// Matches returns true if the resource ID matches the glob from cfg. func (res *Resource) Matches(cfg *pb.ResourceTemplate) bool { // NOTE(ryszard): The only possible error from Match is for a // malformed pattern, so it is safe to quench it (especially // that the config validation should have found any malformed // patterns). glob := cfg.GetIdentifierGlob() matches, _ := filepath.Match(glob, res.ID) return glob == res.ID || matches }
// LoadConfig loads cfg into the resource. LoadConfig takes care of // locking the resource. func (res *Resource) LoadConfig(cfg *pb.ResourceTemplate, expiryTime *time.Time) { res.mu.Lock() defer res.mu.Unlock() res.config = cfg res.expiryTime = expiryTime algo := cfg.GetAlgorithm() res.algorithm = GetAlgorithm(algo) res.learner = Learn(algo) }