Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename Execute to ExecuteJP #492

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/commands/jp/query/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
}

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)

Check warning on line 159 in pkg/commands/jp/query/command.go

View check run for this annotation

Codecov / codecov/patch

pkg/commands/jp/query/command.go#L159

Added line #L159 was not covered by tests
if err != nil {
if syntaxError, ok := err.(parsing.SyntaxError); ok {
return nil, fmt.Errorf("%s\n%s", syntaxError, syntaxError.HighlightLocation())
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/scan/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/assert/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
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...)

Check warning on line 27 in pkg/engine/assert/binding.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/binding.go#L27

Added line #L27 was not covered by tests
if err != nil {
return nil, field.InternalError(path.Child("variable"), err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/assert/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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...)

Check warning on line 25 in pkg/engine/assert/project.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/project.go#L25

Added line #L25 was not covered by tests
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/json-engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
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 {
Expand Down Expand Up @@ -117,7 +117,7 @@
}
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)

Check warning on line 120 in pkg/json-engine/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/json-engine/engine.go#L120

Added line #L120 was not covered by tests
if feedback == nil {
feedback = map[string]Feedback{}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/playground/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
// 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)

Check warning on line 37 in pkg/server/playground/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/playground/handler.go#L37

Added line #L37 was not covered by tests
if err != nil {
return nil, fmt.Errorf("failed to execute prepocessor (%s) - %w", preprocessor, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/scan/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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)

Check warning on line 29 in pkg/server/scan/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/scan/handler.go#L29

Added line #L29 was not covered by tests
if err != nil {
return nil, fmt.Errorf("failed to execute prepocessor (%s) - %w", preprocessor, err)
}
Expand Down