github.com/argoproj/argo-cd/v3@v3.2.1/util/glob/list.go (about) 1 package glob 2 3 import ( 4 "strings" 5 6 "github.com/argoproj/argo-cd/v3/util/regex" 7 ) 8 9 const ( 10 EXACT = "exact" 11 GLOB = "glob" 12 REGEXP = "regexp" 13 ) 14 15 // MatchStringInList will return true if item is contained in list. 16 // patternMatch; can be set to exact, glob, regexp. 17 // If patternMatch; is set to exact, the item must be an exact match. 18 // If patternMatch; is set to glob, the item must match a glob pattern. 19 // If patternMatch; is set to regexp, the item must match a regular expression or glob. 20 func MatchStringInList(list []string, item string, patternMatch string) bool { 21 for _, ll := range list { 22 // If string is wrapped in "/", assume it is a regular expression. 23 switch { 24 case patternMatch == REGEXP && strings.HasPrefix(ll, "/") && strings.HasSuffix(ll, "/") && regex.Match(ll[1:len(ll)-1], item): 25 return true 26 case (patternMatch == REGEXP || patternMatch == GLOB) && Match(ll, item): 27 return true 28 case patternMatch == EXACT && item == ll: 29 return true 30 } 31 } 32 return false 33 }