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

Support values requiring evaluation in with modifiers #701

Closed
tsandall opened this issue Apr 11, 2018 · 0 comments
Closed

Support values requiring evaluation in with modifiers #701

tsandall opened this issue Apr 11, 2018 · 0 comments

Comments

@tsandall
Copy link
Member

Today you must assign values requiring evaluation to local variables before using them in with modifiers. For example, the following is not allowed:

foo = {"bar": 1}; data.foo with input as foo.bar

The easiest way to handle this would be to rewrite the with modifiers early in compilation the same way we do for rule heads, comprehension terms, etc.

So, for example, the query above would become:

foo = {"bar": 1}; __local0__ = foo.bar; data.foo with input as __local0__
tsandall added a commit to tsandall/opa that referenced this issue Apr 30, 2018
These changes update the compiler to rewrite with modifiers to allow
refs or other terms that require evaluation as values. For example,
before this change, the following would not be allowed:

allow with input as data.test.some_test_input

Because the with value (data.test.some_test_input) requires evaluation.

After this change, the expression will be rewritten so that the with
value is bound to a variable earlier in the query and then substituted
with a variable.

This change will make tests cleaner as users will not have to bind
inputs to variables explicitly inside their test cases.

Fixes open-policy-agent#701

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Apr 30, 2018
These changes update the compiler to rewrite with modifiers to allow
refs or other terms that require evaluation as values. For example,
before this change, the following would not be allowed:

allow with input as data.test.some_test_input

Because the with value (data.test.some_test_input) requires evaluation.

After this change, the expression will be rewritten so that the with
value is bound to a variable earlier in the query and then substituted
with a variable.

This change will make tests cleaner as users will not have to bind
inputs to variables explicitly inside their test cases.

Fixes #701

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
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

No branches or pull requests

1 participant