mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
2230842270
Signed-off-by: Abdul Jabbar <abduljabbar5225@gmail.com>
53 lines
974 B
Go
53 lines
974 B
Go
package validate
|
|
|
|
import (
|
|
"github.com/kyverno/go-wildcard"
|
|
|
|
"github.com/kyverno/policy-reporter/pkg/helper"
|
|
)
|
|
|
|
func Namespace(namespace string, namespaces RuleSets) bool {
|
|
if namespace == "" {
|
|
return true
|
|
}
|
|
|
|
return MatchRuleSet(namespace, namespaces)
|
|
}
|
|
|
|
func Kind(kind string, kinds RuleSets) bool {
|
|
if kind == "" {
|
|
return true
|
|
}
|
|
|
|
return MatchRuleSet(kind, kinds)
|
|
}
|
|
|
|
func MatchRuleSet(value string, rules RuleSets) bool {
|
|
if len(rules.Include) > 0 {
|
|
for _, ns := range rules.Include {
|
|
if wildcard.Match(ns, value) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
} else if len(rules.Exclude) > 0 {
|
|
for _, ns := range rules.Exclude {
|
|
if wildcard.Match(ns, value) {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func ContainsRuleSet(value string, rules RuleSets) bool {
|
|
if len(rules.Include) > 0 {
|
|
return helper.Contains(value, rules.Include)
|
|
} else if len(rules.Exclude) > 0 && helper.Contains(value, rules.Exclude) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|