2019-05-14 01:17:28 +00:00
|
|
|
package engine
|
2019-05-13 18:27:47 +00:00
|
|
|
|
|
|
|
import (
|
2023-02-08 05:55:03 +00:00
|
|
|
"context"
|
2021-02-03 21:09:42 +00:00
|
|
|
|
2023-02-09 15:15:51 +00:00
|
|
|
"github.com/go-logr/logr"
|
2022-03-28 14:01:27 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/autogen"
|
2023-01-30 11:41:09 +00:00
|
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
2023-02-09 15:15:51 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/engine/internal"
|
2019-05-13 18:27:47 +00:00
|
|
|
)
|
|
|
|
|
2022-03-29 13:04:33 +00:00
|
|
|
// GenerateResponse checks for validity of generate rule on the resource
|
2023-02-06 12:49:04 +00:00
|
|
|
func (e *engine) generateResponse(
|
2023-02-08 05:55:03 +00:00
|
|
|
ctx context.Context,
|
2023-02-09 15:15:51 +00:00
|
|
|
logger logr.Logger,
|
2023-01-31 15:28:48 +00:00
|
|
|
policyContext engineapi.PolicyContext,
|
2023-03-30 11:59:32 +00:00
|
|
|
) engineapi.PolicyResponse {
|
|
|
|
resp := engineapi.NewPolicyResponse()
|
2023-01-31 15:28:48 +00:00
|
|
|
for _, rule := range autogen.ComputeRules(policyContext.Policy()) {
|
2023-02-09 15:15:51 +00:00
|
|
|
logger := internal.LoggerWithRule(logger, rule)
|
|
|
|
if ruleResp := e.filterRule(rule, logger, policyContext); ruleResp != nil {
|
2023-03-30 11:59:32 +00:00
|
|
|
resp.Rules = append(resp.Rules, *ruleResp)
|
2022-03-29 13:04:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-23 12:58:52 +00:00
|
|
|
return resp
|
2022-03-29 13:04:33 +00:00
|
|
|
}
|