diff --git a/pkg/commands/jp/query/command.go b/pkg/commands/jp/query/command.go index 59a3eedb..a955c21b 100644 --- a/pkg/commands/jp/query/command.go +++ b/pkg/commands/jp/query/command.go @@ -156,7 +156,7 @@ func loadInput(cmd *cobra.Command, file string) (any, error) { } func evaluate(input any, query string) (any, error) { - result, err := template.Execute(context.Background(), query, input, nil) + result, err := template.ExecuteJP(context.Background(), query, input, nil) if err != nil { if syntaxError, ok := err.(parsing.SyntaxError); ok { return nil, fmt.Errorf("%s\n%s", syntaxError, syntaxError.HighlightLocation()) diff --git a/pkg/commands/scan/options.go b/pkg/commands/scan/options.go index ecd134e1..0f091504 100644 --- a/pkg/commands/scan/options.go +++ b/pkg/commands/scan/options.go @@ -77,7 +77,7 @@ func (c *options) run(cmd *cobra.Command, _ []string) error { } out.println("Pre processing ...") for _, preprocessor := range c.preprocessors { - result, err := template.Execute(context.Background(), preprocessor, payload, nil) + result, err := template.ExecuteJP(context.Background(), preprocessor, payload, nil) if err != nil { return err } diff --git a/pkg/engine/assert/binding.go b/pkg/engine/assert/binding.go index f4d0d5d8..547a93b0 100644 --- a/pkg/engine/assert/binding.go +++ b/pkg/engine/assert/binding.go @@ -24,7 +24,7 @@ func NewContextBinding(path *field.Path, bindings binding.Bindings, value any, e } switch expr.Engine { case expression.EngineJP: - projected, err := template.Execute(context.TODO(), expr.Statement, value, bindings, opts...) + projected, err := template.ExecuteJP(context.TODO(), expr.Statement, value, bindings, opts...) if err != nil { return nil, field.InternalError(path.Child("variable"), err) } diff --git a/pkg/engine/assert/project.go b/pkg/engine/assert/project.go index 417e6eab..1f530329 100644 --- a/pkg/engine/assert/project.go +++ b/pkg/engine/assert/project.go @@ -22,7 +22,7 @@ type projection struct { func project(ctx context.Context, expression *expression.Expression, key any, value any, bindings binding.Bindings, opts ...template.Option) (*projection, error) { if expression != nil { if expression.Engine != "" { - projected, err := template.Execute(ctx, expression.Statement, value, bindings, opts...) + projected, err := template.ExecuteJP(ctx, expression.Statement, value, bindings, opts...) if err != nil { return nil, err } diff --git a/pkg/engine/template/template.go b/pkg/engine/template/template.go index b3919b36..19a0aa6d 100644 --- a/pkg/engine/template/template.go +++ b/pkg/engine/template/template.go @@ -8,7 +8,7 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/parsing" ) -func Execute(ctx context.Context, statement string, value any, bindings binding.Bindings, opts ...Option) (any, error) { +func ExecuteJP(ctx context.Context, statement string, value any, bindings binding.Bindings, opts ...Option) (any, error) { parser := parsing.NewParser() compiled, err := parser.Parse(statement) if err != nil { diff --git a/pkg/json-engine/engine.go b/pkg/json-engine/engine.go index 9e8d1e2d..07264d42 100644 --- a/pkg/json-engine/engine.go +++ b/pkg/json-engine/engine.go @@ -78,7 +78,7 @@ func New() engine.Engine[Request, Response] { } identifier := "" if r.rule.Identifier != "" { - result, err := template.Execute(context.Background(), r.rule.Identifier, r.resource, bindings) + result, err := template.ExecuteJP(context.Background(), r.rule.Identifier, r.resource, bindings) if err != nil { identifier = fmt.Sprintf("(error: %s)", err) } else { @@ -117,7 +117,7 @@ func New() engine.Engine[Request, Response] { } var feedback map[string]Feedback for _, f := range r.rule.Feedback { - result, err := template.Execute(context.Background(), f.Value, r.resource, bindings) + result, err := template.ExecuteJP(context.Background(), f.Value, r.resource, bindings) if feedback == nil { feedback = map[string]Feedback{} } diff --git a/pkg/server/playground/handler.go b/pkg/server/playground/handler.go index 96adfcdf..86f0b828 100644 --- a/pkg/server/playground/handler.go +++ b/pkg/server/playground/handler.go @@ -34,7 +34,7 @@ func newHandler() (gin.HandlerFunc, error) { } // apply pre processors for _, preprocessor := range in.Preprocessors { - result, err := template.Execute(context.Background(), preprocessor, payload, nil) + result, err := template.ExecuteJP(context.Background(), preprocessor, payload, nil) if err != nil { return nil, fmt.Errorf("failed to execute prepocessor (%s) - %w", preprocessor, err) } diff --git a/pkg/server/scan/handler.go b/pkg/server/scan/handler.go index ef277012..0af2af14 100644 --- a/pkg/server/scan/handler.go +++ b/pkg/server/scan/handler.go @@ -26,7 +26,7 @@ func newHandler(policyProvider PolicyProvider) (gin.HandlerFunc, error) { payload := in.Payload // apply pre processors for _, preprocessor := range in.Preprocessors { - result, err := template.Execute(context.Background(), preprocessor, payload, nil) + result, err := template.ExecuteJP(context.Background(), preprocessor, payload, nil) if err != nil { return nil, fmt.Errorf("failed to execute prepocessor (%s) - %w", preprocessor, err) }