1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-01-20 18:52:16 +00:00
kyverno/ext/wildcard/utils.go
Charles-Edouard Brétéché c96199dee1
chore: move utils/wildcard in ext (#8772)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-10-29 23:59:53 +00:00

36 lines
827 B
Go

package wildcard
import "strings"
func ContainsWildcard(v string) bool {
return strings.Contains(v, "*") || strings.Contains(v, "?")
}
// MatchPatterns check if any text satisfies any pattern
func MatchPatterns(patterns []string, names ...string) (string, string, bool) {
for _, name := range names {
for _, pattern := range patterns {
if Match(pattern, name) {
return pattern, name, true
}
}
}
return "", "", false
}
// CheckPatterns check if any text satisfies any pattern
func CheckPatterns(patterns []string, names ...string) bool {
_, _, match := MatchPatterns(patterns, names...)
return match
}
func SeperateWildcards(l []string) (lw []string, rl []string) {
for _, val := range l {
if ContainsWildcard(val) {
lw = append(lw, val)
} else {
rl = append(rl, val)
}
}
return lw, rl
}