Skip to content

Commit

Permalink
rego: don't parse inputs for wasm target (open-policy-agent#3624)
Browse files Browse the repository at this point in the history
opa.Eval() expects an input of type *interface{}; and for evaluations targetting
the wasm engine, we had been parsing the rawInput (*interface{}) into *ast.Value,
only to run ast.JSON() on it (going back to *interface{}) before passing it off
to the Wasm SDK.

Signed-off-by: Stephan Renatus <[email protected]>
  • Loading branch information
srenatus authored Jul 8, 2021
1 parent 8f48998 commit 94c4ad6
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions rego/rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,11 @@ func (pq preparedQuery) newEvalContext(ctx context.Context, options []EvalOption
// Note that it could still be nil
ectx.rawInput = pq.r.rawInput
}
ectx.parsedInput, err = pq.r.parseRawInput(ectx.rawInput, ectx.metrics)
if err != nil {
return nil, finishFunc, err
if pq.r.target != targetWasm {
ectx.parsedInput, err = pq.r.parseRawInput(ectx.rawInput, ectx.metrics)
if err != nil {
return nil, finishFunc, err
}
}
}

Expand Down Expand Up @@ -1931,18 +1933,9 @@ func (r *Rego) eval(ctx context.Context, ectx *EvalContext) (ResultSet, error) {

func (r *Rego) evalWasm(ctx context.Context, ectx *EvalContext) (ResultSet, error) {

var input *interface{}
if ectx.parsedInput != nil {
i, err := ast.JSON(ectx.parsedInput)
if err != nil {
return nil, err
}
input = &i
}

result, err := r.opa.Eval(ctx, opa.EvalOpts{
Metrics: r.metrics,
Input: input,
Input: ectx.rawInput,
Time: ectx.time,
Seed: ectx.seed,
})
Expand Down

0 comments on commit 94c4ad6

Please sign in to comment.