2023-03-24 17:24:00 +01:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/go-logr/logr"
|
|
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
|
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
2023-03-27 10:09:46 +02:00
|
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
2023-03-24 17:24:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Handler interface {
|
|
|
|
Process(
|
|
|
|
context.Context,
|
|
|
|
logr.Logger,
|
|
|
|
engineapi.PolicyContext,
|
2023-03-27 10:09:46 +02:00
|
|
|
unstructured.Unstructured,
|
2023-03-24 17:24:00 +01:00
|
|
|
kyvernov1.Rule,
|
2023-03-27 10:09:46 +02:00
|
|
|
func(logr.Logger, engineapi.PolicyContext, kyvernov1.Rule) *engineapi.RuleResponse,
|
|
|
|
) (unstructured.Unstructured, []engineapi.RuleResponse)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RuleResponses(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
|
2023-03-24 17:24:00 +01:00
|
|
|
}
|