func shouldBeAnUUID(actual interface{}, expected ...interface{}) string { input := actual.(string) input = strings.TrimSpace(input) if err := anonuuid.IsUUID(input); err != nil { return fmt.Sprintf("%q should be an UUID", actual) } return "" }
// LookUpImages attempts to return identifiers matching a pattern func (c *ScalewayCache) LookUpImages(needle string, acceptUUID bool) ScalewayResolverResults { c.Lock.Lock() defer c.Lock.Unlock() var res ScalewayResolverResults var exactMatches ScalewayResolverResults if acceptUUID && anonuuid.IsUUID(needle) == nil { entry := ScalewayResolverResult{ Identifier: needle, Name: needle, Type: IdentifierImage, } entry.ComputeRankMatch(needle) res = append(res, entry) } needle = regexp.MustCompile(`^user/`).ReplaceAllString(needle, "") // FIXME: if 'user/' is in needle, only watch for a user image nameRegex := regexp.MustCompile(`(?i)` + regexp.MustCompile(`[_-]`).ReplaceAllString(needle, ".*")) for identifier, name := range c.Images { if name == needle { entry := ScalewayResolverResult{ Identifier: identifier, Name: name, Type: IdentifierImage, } entry.ComputeRankMatch(needle) exactMatches = append(exactMatches, entry) } if strings.HasPrefix(identifier, needle) || nameRegex.MatchString(name) { entry := ScalewayResolverResult{ Identifier: identifier, Name: name, Type: IdentifierImage, } entry.ComputeRankMatch(needle) res = append(res, entry) } } if len(exactMatches) == 1 { return exactMatches } return removeDuplicatesResults(res) }