From ec120542bd8beaa8262baae7a133474ad598404e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Thu, 19 Sep 2024 10:34:27 +0200 Subject: [PATCH] refactor: move jp extensions in a top level package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/commands/jp/function/command.go | 4 ++-- pkg/engine/assert/binding.go | 3 ++- pkg/engine/template/options.go | 3 ++- pkg/{engine/template => jp}/binding.go | 2 +- pkg/{engine/template => jp}/functions.go | 6 +++--- pkg/{engine/template => jp}/functions/at.go | 0 pkg/{engine/template => jp}/functions/concat.go | 0 pkg/{engine/template => jp}/functions/functions.go | 0 pkg/{engine/template => jp}/functions/json_parse.go | 0 pkg/{engine/template => jp}/functions/wildcard.go | 0 pkg/{engine/template => jp}/kyverno/arithmetic.go | 0 pkg/{engine/template => jp}/kyverno/arithmetic_test.go | 0 pkg/{engine/template => jp}/kyverno/error.go | 0 pkg/{engine/template => jp}/kyverno/functionentry.go | 0 pkg/{engine/template => jp}/kyverno/functionentry_test.go | 0 pkg/{engine/template => jp}/kyverno/functions.go | 0 pkg/{engine/template => jp}/kyverno/functions_test.go | 0 pkg/{engine/template => jp}/kyverno/time.go | 0 pkg/{engine/template => jp}/kyverno/time_test.go | 0 pkg/{engine/template => jp}/kyverno/utils.go | 0 pkg/{engine/template => jp}/kyverno/utils_test.go | 0 website/jp/main.go | 4 ++-- 22 files changed, 12 insertions(+), 10 deletions(-) rename pkg/{engine/template => jp}/binding.go (92%) rename pkg/{engine/template => jp}/functions.go (70%) rename pkg/{engine/template => jp}/functions/at.go (100%) rename pkg/{engine/template => jp}/functions/concat.go (100%) rename pkg/{engine/template => jp}/functions/functions.go (100%) rename pkg/{engine/template => jp}/functions/json_parse.go (100%) rename pkg/{engine/template => jp}/functions/wildcard.go (100%) rename pkg/{engine/template => jp}/kyverno/arithmetic.go (100%) rename pkg/{engine/template => jp}/kyverno/arithmetic_test.go (100%) rename pkg/{engine/template => jp}/kyverno/error.go (100%) rename pkg/{engine/template => jp}/kyverno/functionentry.go (100%) rename pkg/{engine/template => jp}/kyverno/functionentry_test.go (100%) rename pkg/{engine/template => jp}/kyverno/functions.go (100%) rename pkg/{engine/template => jp}/kyverno/functions_test.go (100%) rename pkg/{engine/template => jp}/kyverno/time.go (100%) rename pkg/{engine/template => jp}/kyverno/time_test.go (100%) rename pkg/{engine/template => jp}/kyverno/utils.go (100%) rename pkg/{engine/template => jp}/kyverno/utils_test.go (100%) diff --git a/pkg/commands/jp/function/command.go b/pkg/commands/jp/function/command.go index 3bb7377c..88c856a0 100644 --- a/pkg/commands/jp/function/command.go +++ b/pkg/commands/jp/function/command.go @@ -10,7 +10,7 @@ import ( jpfunctions "github.com/jmespath-community/go-jmespath/pkg/functions" "github.com/kyverno/kyverno-json/pkg/command" - "github.com/kyverno/kyverno-json/pkg/engine/template" + "github.com/kyverno/kyverno-json/pkg/jp" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/util/sets" ) @@ -59,7 +59,7 @@ func functionString(f jpfunctions.FunctionEntry) string { } func printFunctions(out io.Writer, names ...string) { - funcs := template.GetFunctions(context.Background()) + funcs := jp.GetFunctions(context.Background()) slices.SortFunc(funcs, func(a, b jpfunctions.FunctionEntry) int { return cmp.Compare(functionString(a), functionString(b)) }) diff --git a/pkg/engine/assert/binding.go b/pkg/engine/assert/binding.go index 54034a75..dbf55185 100644 --- a/pkg/engine/assert/binding.go +++ b/pkg/engine/assert/binding.go @@ -5,11 +5,12 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/binding" "github.com/kyverno/kyverno-json/pkg/engine/template" + "github.com/kyverno/kyverno-json/pkg/jp" "k8s.io/apimachinery/pkg/util/validation/field" ) func NewContextBinding(path *field.Path, bindings binding.Bindings, value any, entry any, opts ...template.Option) binding.Binding { - return template.NewLazyBinding( + return jp.NewLazyBinding( func() (any, error) { expression := parseExpression(context.TODO(), entry) if expression != nil && expression.engine != "" { diff --git a/pkg/engine/template/options.go b/pkg/engine/template/options.go index 8062622e..52cf408a 100644 --- a/pkg/engine/template/options.go +++ b/pkg/engine/template/options.go @@ -4,10 +4,11 @@ import ( "context" "github.com/jmespath-community/go-jmespath/pkg/interpreter" + "github.com/kyverno/kyverno-json/pkg/jp" ) var ( - funcs = GetFunctions(context.Background()) + funcs = jp.GetFunctions(context.Background()) defaultCaller = interpreter.NewFunctionCaller(funcs...) ) diff --git a/pkg/engine/template/binding.go b/pkg/jp/binding.go similarity index 92% rename from pkg/engine/template/binding.go rename to pkg/jp/binding.go index 9a6e4d38..9e41ab56 100644 --- a/pkg/engine/template/binding.go +++ b/pkg/jp/binding.go @@ -1,4 +1,4 @@ -package template +package jp import ( "sync" diff --git a/pkg/engine/template/functions.go b/pkg/jp/functions.go similarity index 70% rename from pkg/engine/template/functions.go rename to pkg/jp/functions.go index 3db539b1..7495d633 100644 --- a/pkg/engine/template/functions.go +++ b/pkg/jp/functions.go @@ -1,11 +1,11 @@ -package template +package jp import ( "context" jpfunctions "github.com/jmespath-community/go-jmespath/pkg/functions" - "github.com/kyverno/kyverno-json/pkg/engine/template/functions" - kyvernofunctions "github.com/kyverno/kyverno-json/pkg/engine/template/kyverno" + "github.com/kyverno/kyverno-json/pkg/jp/functions" + kyvernofunctions "github.com/kyverno/kyverno-json/pkg/jp/kyverno" ) func GetFunctions(ctx context.Context) []jpfunctions.FunctionEntry { diff --git a/pkg/engine/template/functions/at.go b/pkg/jp/functions/at.go similarity index 100% rename from pkg/engine/template/functions/at.go rename to pkg/jp/functions/at.go diff --git a/pkg/engine/template/functions/concat.go b/pkg/jp/functions/concat.go similarity index 100% rename from pkg/engine/template/functions/concat.go rename to pkg/jp/functions/concat.go diff --git a/pkg/engine/template/functions/functions.go b/pkg/jp/functions/functions.go similarity index 100% rename from pkg/engine/template/functions/functions.go rename to pkg/jp/functions/functions.go diff --git a/pkg/engine/template/functions/json_parse.go b/pkg/jp/functions/json_parse.go similarity index 100% rename from pkg/engine/template/functions/json_parse.go rename to pkg/jp/functions/json_parse.go diff --git a/pkg/engine/template/functions/wildcard.go b/pkg/jp/functions/wildcard.go similarity index 100% rename from pkg/engine/template/functions/wildcard.go rename to pkg/jp/functions/wildcard.go diff --git a/pkg/engine/template/kyverno/arithmetic.go b/pkg/jp/kyverno/arithmetic.go similarity index 100% rename from pkg/engine/template/kyverno/arithmetic.go rename to pkg/jp/kyverno/arithmetic.go diff --git a/pkg/engine/template/kyverno/arithmetic_test.go b/pkg/jp/kyverno/arithmetic_test.go similarity index 100% rename from pkg/engine/template/kyverno/arithmetic_test.go rename to pkg/jp/kyverno/arithmetic_test.go diff --git a/pkg/engine/template/kyverno/error.go b/pkg/jp/kyverno/error.go similarity index 100% rename from pkg/engine/template/kyverno/error.go rename to pkg/jp/kyverno/error.go diff --git a/pkg/engine/template/kyverno/functionentry.go b/pkg/jp/kyverno/functionentry.go similarity index 100% rename from pkg/engine/template/kyverno/functionentry.go rename to pkg/jp/kyverno/functionentry.go diff --git a/pkg/engine/template/kyverno/functionentry_test.go b/pkg/jp/kyverno/functionentry_test.go similarity index 100% rename from pkg/engine/template/kyverno/functionentry_test.go rename to pkg/jp/kyverno/functionentry_test.go diff --git a/pkg/engine/template/kyverno/functions.go b/pkg/jp/kyverno/functions.go similarity index 100% rename from pkg/engine/template/kyverno/functions.go rename to pkg/jp/kyverno/functions.go diff --git a/pkg/engine/template/kyverno/functions_test.go b/pkg/jp/kyverno/functions_test.go similarity index 100% rename from pkg/engine/template/kyverno/functions_test.go rename to pkg/jp/kyverno/functions_test.go diff --git a/pkg/engine/template/kyverno/time.go b/pkg/jp/kyverno/time.go similarity index 100% rename from pkg/engine/template/kyverno/time.go rename to pkg/jp/kyverno/time.go diff --git a/pkg/engine/template/kyverno/time_test.go b/pkg/jp/kyverno/time_test.go similarity index 100% rename from pkg/engine/template/kyverno/time_test.go rename to pkg/jp/kyverno/time_test.go diff --git a/pkg/engine/template/kyverno/utils.go b/pkg/jp/kyverno/utils.go similarity index 100% rename from pkg/engine/template/kyverno/utils.go rename to pkg/jp/kyverno/utils.go diff --git a/pkg/engine/template/kyverno/utils_test.go b/pkg/jp/kyverno/utils_test.go similarity index 100% rename from pkg/engine/template/kyverno/utils_test.go rename to pkg/jp/kyverno/utils_test.go diff --git a/website/jp/main.go b/website/jp/main.go index 02bbcf2c..2c45cfd3 100644 --- a/website/jp/main.go +++ b/website/jp/main.go @@ -5,8 +5,8 @@ import ( "strings" jpfunctions "github.com/jmespath-community/go-jmespath/pkg/functions" - "github.com/kyverno/kyverno-json/pkg/engine/template/functions" - kyvernofunctions "github.com/kyverno/kyverno-json/pkg/engine/template/kyverno" + "github.com/kyverno/kyverno-json/pkg/jp/functions" + kyvernofunctions "github.com/kyverno/kyverno-json/pkg/jp/kyverno" ) func main() {