mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
95f54a1cb6
* feat: enable custom data in policy reports using properties Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: dont throw error in variable substitution for properties Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> --------- Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-logr/logr"
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
|
kyvernov2 "github.com/kyverno/kyverno/api/kyverno/v2"
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
)
|
|
|
|
type Handler interface {
|
|
Process(
|
|
context.Context,
|
|
logr.Logger,
|
|
engineapi.PolicyContext,
|
|
unstructured.Unstructured,
|
|
kyvernov1.Rule,
|
|
engineapi.EngineContextLoader,
|
|
[]*kyvernov2.PolicyException,
|
|
) (unstructured.Unstructured, []engineapi.RuleResponse)
|
|
}
|
|
|
|
func WithError(rule kyvernov1.Rule, ruleType engineapi.RuleType, msg string, err error) []engineapi.RuleResponse {
|
|
return WithResponses(engineapi.RuleError(rule.Name, ruleType, msg, err, rule.ReportProperties))
|
|
}
|
|
|
|
func WithSkip(rule kyvernov1.Rule, ruleType engineapi.RuleType, msg string) []engineapi.RuleResponse {
|
|
return WithResponses(engineapi.RuleSkip(rule.Name, ruleType, msg, rule.ReportProperties))
|
|
}
|
|
|
|
func WithPass(rule kyvernov1.Rule, ruleType engineapi.RuleType, msg string) []engineapi.RuleResponse {
|
|
return WithResponses(engineapi.RulePass(rule.Name, ruleType, msg, rule.ReportProperties))
|
|
}
|
|
|
|
func WithFail(rule kyvernov1.Rule, ruleType engineapi.RuleType, msg string) []engineapi.RuleResponse {
|
|
return WithResponses(engineapi.RuleFail(rule.Name, ruleType, msg, rule.ReportProperties))
|
|
}
|
|
|
|
func WithResponses(rrs ...*engineapi.RuleResponse) []engineapi.RuleResponse {
|
|
var out []engineapi.RuleResponse
|
|
for _, rr := range rrs {
|
|
if rr != nil {
|
|
out = append(out, *rr)
|
|
}
|
|
}
|
|
if len(out) == 0 {
|
|
return nil
|
|
}
|
|
return out
|
|
}
|