open-policy-agent / contrib

Integrations, examples, and proof-of-concepts that are not part of OPA proper.

Home Page:http://www.openpolicyagent.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix docs in data_filter_example

xevix opened this issue · comments

The below examples won't work because the method verb isn't capitalized, but it is in the rego. Should be a simple fix to change get to GET. Will submit PR if time later.

>>> result = opa.compile(q='data.example.allow==true', input={'method':'get', 'path': ['posts'], 'user': 'bob'}, unknowns=['posts'])
The result will contain the SQL clauses to apply to your query.
>>> result.sql.clauses[0].sql()
u'WHERE (("bob" = posts.author))'
On the other hand if the query is NEVER defined, the `defined` attribute will
be False.
>>> result = opa.compile(q='data.example.allow==true', input={'method':'get', 'path': ['deadbeef'], 'user': 'bob'}, unknowns=['posts'])
>>> result.defined
False
The last part of the policy says that super users can access the API
unconditionally. In this case, the `defined` attribute will be True but the
`sql` attribute will be None.
>>> result = opa.compile(q='data.example.allow==true', input={'method':'get', 'path': ['deadbeef'], 'user': 'bob'}, unknowns=['posts'])

@xevix nice catch. If you have a fix you can submit, that would be great. I'm going to mark this as help-wanted since I think this is an easy for anyone to contribute.