2023-02-07 16:51:25 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-logr/logr"
|
2023-03-31 06:41:48 +00:00
|
|
|
enginecontext "github.com/kyverno/kyverno/pkg/engine/context"
|
2023-02-07 16:51:25 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/engine/utils"
|
|
|
|
"github.com/kyverno/kyverno/pkg/engine/variables"
|
|
|
|
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
|
|
|
)
|
|
|
|
|
2023-05-08 07:34:23 +00:00
|
|
|
func CheckPreconditions(logger logr.Logger, jsonContext enginecontext.Interface, anyAllConditions apiextensions.JSON) (bool, string, error) {
|
2023-05-20 21:06:54 +00:00
|
|
|
typeConditions, err := utils.TransformConditions(anyAllConditions)
|
2023-02-07 16:51:25 +00:00
|
|
|
if err != nil {
|
2023-05-08 07:34:23 +00:00
|
|
|
return false, "", fmt.Errorf("failed to parse preconditions: %w", err)
|
2023-02-07 16:51:25 +00:00
|
|
|
}
|
2023-05-08 07:34:23 +00:00
|
|
|
|
2023-05-20 21:06:54 +00:00
|
|
|
return variables.EvaluateConditions(logger, jsonContext, typeConditions)
|
2023-02-07 16:51:25 +00:00
|
|
|
}
|
|
|
|
|
2023-05-08 07:34:23 +00:00
|
|
|
func CheckDenyPreconditions(logger logr.Logger, jsonContext enginecontext.Interface, anyAllConditions apiextensions.JSON) (bool, string, error) {
|
2023-05-20 21:06:54 +00:00
|
|
|
typeConditions, err := utils.TransformConditions(anyAllConditions)
|
2023-02-07 16:51:25 +00:00
|
|
|
if err != nil {
|
2023-05-08 07:34:23 +00:00
|
|
|
return false, "", fmt.Errorf("failed to parse deny conditions: %w", err)
|
2023-02-07 16:51:25 +00:00
|
|
|
}
|
2023-05-08 07:34:23 +00:00
|
|
|
|
2023-05-20 21:06:54 +00:00
|
|
|
return variables.EvaluateConditions(logger, jsonContext, typeConditions)
|
2023-02-07 16:51:25 +00:00
|
|
|
}
|