1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-14 11:57:32 +00:00
policy-reporter/pkg/validate/validate.go
abdul-jabbar01 2230842270
Feat: Add kind attribute in the Metrics filter (#442)
Signed-off-by: Abdul Jabbar <abduljabbar5225@gmail.com>
2024-05-28 23:09:17 +02:00

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
}