2023-02-02 10:58:34 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-02-03 05:01:11 +00:00
|
|
|
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
2023-02-02 10:58:34 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
|
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
|
|
|
"github.com/kyverno/kyverno/pkg/registryclient"
|
|
|
|
)
|
|
|
|
|
2023-02-03 05:01:11 +00:00
|
|
|
type engine struct {
|
2023-02-06 05:49:47 +00:00
|
|
|
configuration config.Configuration
|
|
|
|
contextLoader engineapi.ContextLoaderFactory
|
|
|
|
exceptionSelector engineapi.PolicyExceptionSelector
|
2023-02-03 05:01:11 +00:00
|
|
|
}
|
2023-02-02 10:58:34 +00:00
|
|
|
|
2023-02-03 05:01:11 +00:00
|
|
|
func NewEngine(
|
|
|
|
configuration config.Configuration,
|
|
|
|
contextLoader engineapi.ContextLoaderFactory,
|
2023-02-06 05:49:47 +00:00
|
|
|
exceptionSelector engineapi.PolicyExceptionSelector,
|
2023-02-03 05:01:11 +00:00
|
|
|
) engineapi.Engine {
|
|
|
|
return &engine{
|
2023-02-06 05:49:47 +00:00
|
|
|
configuration: configuration,
|
|
|
|
contextLoader: contextLoader,
|
|
|
|
exceptionSelector: exceptionSelector,
|
2023-02-03 05:01:11 +00:00
|
|
|
}
|
2023-02-02 10:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *engine) Validate(
|
|
|
|
ctx context.Context,
|
|
|
|
policyContext engineapi.PolicyContext,
|
|
|
|
) *engineapi.EngineResponse {
|
2023-02-06 12:49:04 +00:00
|
|
|
return e.validate(ctx, policyContext)
|
2023-02-02 10:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *engine) Mutate(
|
|
|
|
ctx context.Context,
|
|
|
|
policyContext engineapi.PolicyContext,
|
|
|
|
) *engineapi.EngineResponse {
|
2023-02-06 12:49:04 +00:00
|
|
|
return e.mutate(ctx, policyContext)
|
2023-02-02 10:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *engine) VerifyAndPatchImages(
|
|
|
|
ctx context.Context,
|
|
|
|
rclient registryclient.Client,
|
|
|
|
policyContext engineapi.PolicyContext,
|
|
|
|
) (*engineapi.EngineResponse, *engineapi.ImageVerificationMetadata) {
|
2023-02-06 12:49:04 +00:00
|
|
|
return e.verifyAndPatchImages(ctx, rclient, policyContext)
|
2023-02-03 05:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *engine) ApplyBackgroundChecks(
|
|
|
|
policyContext engineapi.PolicyContext,
|
|
|
|
) *engineapi.EngineResponse {
|
2023-02-06 12:49:04 +00:00
|
|
|
return e.applyBackgroundChecks(policyContext)
|
2023-02-03 05:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *engine) GenerateResponse(
|
|
|
|
policyContext engineapi.PolicyContext,
|
|
|
|
gr kyvernov1beta1.UpdateRequest,
|
|
|
|
) *engineapi.EngineResponse {
|
2023-02-06 12:49:04 +00:00
|
|
|
return e.generateResponse(policyContext, gr)
|
2023-02-03 05:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *engine) ContextLoader(
|
|
|
|
policyContext engineapi.PolicyContext,
|
|
|
|
ruleName string,
|
|
|
|
) engineapi.ContextLoader {
|
|
|
|
return e.contextLoader(policyContext, ruleName)
|
2023-02-02 10:58:34 +00:00
|
|
|
}
|