-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add a --format=raw option for eval #3207
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! I've thought about doing something like this for a while. If you can add some tests that would be great. @srenatus any thoughts?
I'm all for it! Thanks for coming up with this. 🚀 |
c85010b
to
f94cc27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
I think this would be most useful for simple results and the table format; I can't see myself use the raw compound values, but that's just me 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @jaspervdj-luminal once you squash the commits, we can merge.
This is a very simple addition but it's proven extremely useful to us since it means you can now use `opa` easily in bash scripts, e.g.: ```bash ACCOUNT_ID="$(opa eval -d accounts.rego --format raw "data.accounts.account")" ``` This means `accounts.rego` can be used by policies as well as e.g. deploy scripts. The naming and functionality is inspired by the `-r` flag from `jq`. In fact, `jq` can be used to replicate this behaviour, but it is a bit nicer to not rely on that system dependency. When multiple queries and expressions are given, they are printed in a simple table format using single newlines and spaces since that is consistent and plays nice with `bash`. Signed-off-by: Jasper Van der Jeugt <jasper@fugue.co>
c87c5c3
72d99e5
to
c87c5c3
Compare
This is a very simple addition but it's proven extremely useful to us since
it means you can now use
opa
easily in bash scripts, e.g.:ACCOUNT_ID="$(opa eval -d accounts.rego --format raw "data.accounts.account")"
This means
accounts.rego
can be used by policies as well as e.g. deployscripts.
The naming and functionality is inspired by the
-r
flag fromjq
. In fact,jq
can be used to replicate this behaviour, but it is a bit nicer to not relyon that system dependency.
I wasn't sure what to do when multiple queries and expressions are given. I
opted to print these in a newline/space separated way since that is consistent
and plays nice with
bash
.If this seems like a good addition I'll add some tests to this PR, I wanted
to test the waters first.
Signed-off-by: Jasper Van der Jeugt jasper@fugue.co