From ebebef6cb741df608d22d3af4409f95ef4d99d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Tue, 5 Sep 2023 23:58:03 +0200 Subject: [PATCH] refactor: remove depency from validation to cli (#8274) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- cmd/cli/kubectl-kyverno/utils/common/regex.go | 8 -------- pkg/validation/policy/validate.go | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 cmd/cli/kubectl-kyverno/utils/common/regex.go diff --git a/cmd/cli/kubectl-kyverno/utils/common/regex.go b/cmd/cli/kubectl-kyverno/utils/common/regex.go deleted file mode 100644 index 8e74c25494..0000000000 --- a/cmd/cli/kubectl-kyverno/utils/common/regex.go +++ /dev/null @@ -1,8 +0,0 @@ -package common - -import ( - "regexp" -) - -// RegexVariables represents regex for '{{}}' -var RegexVariables = regexp.MustCompile(`\{\{[^{}]*\}\}`) diff --git a/pkg/validation/policy/validate.go b/pkg/validation/policy/validate.go index 2b41157bd6..44cd533a50 100644 --- a/pkg/validation/policy/validate.go +++ b/pkg/validation/policy/validate.go @@ -16,7 +16,6 @@ import ( "github.com/kyverno/go-jmespath" "github.com/kyverno/kyverno/api/kyverno" kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" - "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common" "github.com/kyverno/kyverno/pkg/autogen" "github.com/kyverno/kyverno/pkg/clients/dclient" openapicontroller "github.com/kyverno/kyverno/pkg/controllers/openapi" @@ -43,6 +42,7 @@ var ( allowedVariablesBackground = regexp.MustCompile(`request\.|element|elementIndex|@|images|images\.|image\.|([a-z_0-9]+\()[^{}]`) allowedVariablesInTarget = regexp.MustCompile(`request\.|serviceAccountName|serviceAccountNamespace|element|elementIndex|@|images|images\.|image\.|target\.|([a-z_0-9]+\()[^{}]`) allowedVariablesBackgroundInTarget = regexp.MustCompile(`request\.|element|elementIndex|@|images|images\.|image\.|target\.|([a-z_0-9]+\()[^{}]`) + regexVariables = regexp.MustCompile(`\{\{[^{}]*\}\}`) // wildCardAllowedVariables represents regex for the allowed fields in wildcards wildCardAllowedVariables = regexp.MustCompile(`\{\{\s*(request\.|serviceAccountName|serviceAccountNamespace)[^{}]*\}\}`) errOperationForbidden = errors.New("variables are forbidden in the path of a JSONPatch") @@ -542,7 +542,7 @@ func objectHasVariables(object interface{}) error { return err } - if len(common.RegexVariables.FindAllStringSubmatch(string(objectJSON), -1)) > 0 { + if len(regexVariables.FindAllStringSubmatch(string(objectJSON), -1)) > 0 { return fmt.Errorf("invalid variables") }