2021-05-04 19:11:13 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2021-06-14 20:42:57 +00:00
|
|
|
|
2021-10-29 16:13:20 +00:00
|
|
|
kyverno "github.com/kyverno/kyverno/api/kyverno/v1"
|
2021-05-04 19:11:13 +00:00
|
|
|
)
|
|
|
|
|
2022-03-23 08:59:41 +00:00
|
|
|
func ParsePolicyValidationMode(validationFailureAction kyverno.ValidationFailureAction) (PolicyValidationMode, error) {
|
2021-05-04 19:11:13 +00:00
|
|
|
switch validationFailureAction {
|
2022-03-23 08:59:41 +00:00
|
|
|
case kyverno.Enforce:
|
2021-05-04 19:11:13 +00:00
|
|
|
return Enforce, nil
|
2022-03-23 08:59:41 +00:00
|
|
|
case kyverno.Audit:
|
2021-05-04 19:11:13 +00:00
|
|
|
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
|
|
|
|
}
|