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

Add a --format=raw option for eval #3207

Merged
merged 1 commit into from
Mar 4, 2021

Conversation

jaspervdj-luminal
Copy link
Contributor

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. 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.

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

Copy link
Member

@tsandall tsandall left a 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?

@srenatus
Copy link
Contributor

srenatus commented Mar 3, 2021

I'm all for it! Thanks for coming up with this. 🚀

@jaspervdj-luminal
Copy link
Contributor Author

Thanks for the comments @tsandall and @srenatus! I fixed the issue Stephan spotted and added some tests.

srenatus
srenatus previously approved these changes Mar 3, 2021
Copy link
Contributor

@srenatus srenatus left a 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 😄

tsandall
tsandall previously approved these changes Mar 3, 2021
Copy link
Member

@tsandall tsandall left a 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants