2021-05-04 19:11:13 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2021-06-14 20:42:57 +00:00
|
|
|
|
|
|
|
kyverno "github.com/kyverno/kyverno/pkg/api/kyverno/v1"
|
2021-05-04 19:11:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ParsePolicyValidationMode(validationFailureAction string) (PolicyValidationMode, error) {
|
|
|
|
switch validationFailureAction {
|
|
|
|
case "enforce":
|
|
|
|
return Enforce, nil
|
|
|
|
case "audit":
|
|
|
|
return Audit, nil
|
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("wrong validation failure action found %s. Allowed: '%s', '%s'", validationFailureAction, "enforce", "audit")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 20:42:57 +00:00
|
|
|
func ParsePolicyBackgroundMode(backgroundMode *bool) PolicyBackgroundMode {
|
|
|
|
if backgroundMode == nil || *backgroundMode {
|
2021-05-04 19:11:13 +00:00
|
|
|
return BackgroundTrue
|
|
|
|
}
|
2021-06-14 20:42:57 +00:00
|
|
|
|
2021-05-04 19:11:13 +00:00
|
|
|
return BackgroundFalse
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseRuleType(rule kyverno.Rule) RuleType {
|
|
|
|
if !reflect.DeepEqual(rule.Validation, kyverno.Validation{}) {
|
|
|
|
return Validate
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(rule.Mutation, kyverno.Mutation{}) {
|
|
|
|
return Mutate
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(rule.Generation, kyverno.Generation{}) {
|
|
|
|
return Generate
|
|
|
|
}
|
|
|
|
return EmptyRuleType
|
|
|
|
}
|