(patterns []string, match func(string) (bool, error))
| 45 | } |
| 46 | |
| 47 | func matchAny(patterns []string, match func(string) (bool, error)) bool { |
| 48 | if len(patterns) == 0 { |
| 49 | return true |
| 50 | } |
| 51 | |
| 52 | var hasPositive, matchedPositive bool |
| 53 | |
| 54 | for _, p := range patterns { |
| 55 | negated := strings.HasPrefix(p, "!") |
| 56 | if negated { |
| 57 | p = p[1:] |
| 58 | } else { |
| 59 | hasPositive = true |
| 60 | } |
| 61 | |
| 62 | ok, err := match(p) |
| 63 | if err != nil { |
| 64 | klog.V(1).Infof("%s is an invalid pattern: %v", p, err) |
| 65 | continue |
| 66 | } |
| 67 | if negated && ok { |
| 68 | // if a netagive expression is matched we return immediately |
| 69 | return false |
| 70 | } |
| 71 | if !negated && ok { |
| 72 | // if a positive expression is matched, |
| 73 | // we take note of it but continue the loop, in case there are any netagive expressions that would match |
| 74 | matchedPositive = true |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // if there are only negatives, allow by default unless a negative matched earlier |
| 79 | // if there are positives, require at least one positive match |
| 80 | return !hasPositive || matchedPositive |
| 81 | } |
| 82 | |
| 83 | func matchGroups(patterns []string, g string) bool { |
| 84 | return matchAny(patterns, func(pattern string) (bool, error) { |
no outgoing calls
no test coverage detected