






$opa --help
An open source project to policy-enable your service.
Usage:
opa [command]
Available Commands:
bench Benchmark a Rego query
build Build an OPA bundle
check Check Rego source files
completion generate the autocompletion script for the specified shell
deps Analyze Rego query dependencies
eval Evaluate a Rego query
fmt Format Rego source files
help Help about any command
parse Parse Rego source file
run Start OPA in interactive or server mode
sign Generate an OPA bundle signature
test Execute Rego test cases
version Print the version of OPA
Flags:
-h, --help help for opa
Use "opa [command] --help" for more information about a command.

package acmecorp.api
import data.acmecorp.roles
default allow = false
allow {
input.method = “GET”
input.path = [“accounts”, user]
input.user = user
}
allow {
input.method = “GET”
input.path = [“accounts”, “report”]
roles[input.user][_] = “admin”
}
allow {
input.method = “POST”
input.path = [“accounts”]
roles[input.user][_] = “admin”
}

$ opa test . -v
data.authz.test_post_allowed: PASS (1.417µs)
data.authz.test_get_anonymous_denied: PASS (426ns)
data.authz.test_get_user_allowed: PASS (367ns)
data.authz.test_get_another_user_denied: PASS (320ns)
--------------------------------------------------------------------------------
PASS: 4/4
opa test -v --bench example.rego example_test.rego
data.authz.test_post_allowed 98425 11773 ns/op 9298 timer_rego_query_eval_ns/op 8437 B/op 160 allocs/op
data.authz.test_get_anonymous_denied 131479 9106 ns/op 6841 timer_rego_query_eval_ns/op 6596 B/op 133 allocs/op
data.authz.test_get_user_allowed 96920 12395 ns/op 9920 timer_rego_query_eval_ns/op 8966 B/op 166 allocs/op
data.authz.test_get_another_user_denied 103340 11834 ns/op 9301 timer_rego_query_eval_ns/op 8341 B/op 157 allocs/op
--------------------------------------------------------------------------------
PASS: 4/4
opa test --coverage --format=json example.rego example_test.rego
{
"files": {
"example.rego": {
"covered": [
{
"start": {
"row": 3
},
"end": {
"row": 5
}
},
...
],
"coverage": 100
},
"example_test.rego": {
"covered": [
....
],
"coverage": 100
}
},
"coverage": 100
}










