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

OPA eval --disable-inlining can not parse parameters with double quotes #2196

Closed
xin-styra opened this issue Mar 17, 2020 · 7 comments · Fixed by #2421
Closed

OPA eval --disable-inlining can not parse parameters with double quotes #2196

xin-styra opened this issue Mar 17, 2020 · 7 comments · Fixed by #2421

Comments

@xin-styra
Copy link
Contributor

Expected Behavior

OPA command line should be able to parse parameters with double-quotes. E.g., --disable-inlining=query should take the query even if there are double quotes " in the query, e.g., data.policy["com.styra.envoy"].resolver.main

Actual Behavior

It seems when partial eval is executed, the above parameter query is not respected. There seems to be some problem with argument parsing for those with quotes.

Steps to Reproduce the Problem

  1. Given any policy bundle
  2. Run opa eval -p -b . 'x = [actual query]' -f source --disable-inlining=query
  3. This works if I use Golang to execute the partial eval with the same parameters.

Additional Info

@patrick-east
Copy link
Contributor

Easy repro:

opa eval --disable-inlining='data["p"]' data

Gives:

Error: invalid argument "data[\"p\"]" for "--disable-inlining" flag: parse error on line 1, column 5: bare " in non-quoted-field
Usage:
  opa eval <query> [flags]

Flags:
  -b, --bundle string                                 set bundle file(s) or directory path(s)
      --coverage                                      report coverage
  -d, --data string                                   set data file(s) or directory path(s)
      --disable-indexing                              disable indexing optimizations
      --disable-inlining strings                      set paths of documents to exclude from inlining
      --explain {off,full,notes,fails}                enable query explanations (default off)
      --fail                                          exits with non-zero exit code on undefined/empty result and errors
      --fail-defined                                  exits with non-zero exit code on defined/non-empty result and errors
  -f, --format {json,values,bindings,pretty,source}   set output format (default json)
  -h, --help                                          help for eval
      --ignore strings                                set file and directory names to ignore during loading (e.g., '.*' excludes hidden files)
      --import string                                 set query import(s)
  -i, --input string                                  set input file path
      --instrument                                    enable query instrumentation metrics (implies --metrics)
      --metrics                                       report query performance metrics
      --package string                                set query package
  -p, --partial                                       perform partial evaluation
      --pretty-limit int                              set limit after which pretty output gets truncated (default 80)
      --profile                                       perform expression profiling
      --profile-limit int                             set number of profiling results to show (default 10)
      --profile-sort string                           set sort order of expression profiler results
      --stdin                                         read query from stdin
  -I, --stdin-input                                   read input document from stdin
  -u, --unknowns strings                              set paths to treat as unknown during partial evaluation (default [input])

invalid argument "data[\"p\"]" for "--disable-inlining" flag: parse error on line 1, column 5: bare " in non-quoted-field

@patrick-east patrick-east changed the title OPA command line can not parse parameters with double quotes OPA eval --disable-inlining can not parse parameters with double quotes Mar 17, 2020
@sresthas
Copy link
Contributor

Can I take this up? Some pointers would be helpful

@patrick-east
Copy link
Contributor

@sresthas Sounds good. This one will require digging into some of the documentation and code for https://github.com/spf13/cobra

I think the first thing to confirm is where the error is happening and why.

Based on the error message I think the problem is with the CLI argument string for

opa/cmd/eval.go

Line 221 in 9d1b42d

evalCommand.Flags().StringSliceVarP(&params.disableInlining, "disable-inlining", "", []string{}, "set paths of documents to exclude from inlining")
and passing in a flag value like --disable-inlining='data["p"]'

But it is not clear why this is a problem.

@Syn3rman
Copy link
Contributor

Syn3rman commented May 7, 2020

Hey @patrick-east,

Since there has been no update on this for a while, could I have a look at it later? (after closing the open pr)

@sresthas
Copy link
Contributor

sresthas commented May 7, 2020

@Syn3rman I am looking into this, can you please select any other issue.
Thanks!

@Syn3rman
Copy link
Contributor

Using StringArrayVarP instead of StringSliceVarP seems to do the trick here. Should I make the changes and open a pr @patrick-east?

@patrick-east
Copy link
Contributor

Go for it

tsandall pushed a commit that referenced this issue May 27, 2020
This commit fixes the parse error encountered while using double quotes
in the parameters.

Fixes #2196
Signed-off-by: Aditya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants