mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
More OPA conformant semantics (#62)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
8a73b4bef9
commit
73ee18f002
@@ -15,32 +15,33 @@ Regorus is available as a library that can be easily integrated into your Rust p
|
||||
|
||||
## Getting Started
|
||||
|
||||
[regorus](examples/regorus.rs) is an example program that shows how to integrate Regorus into your project and evaluate Rego policies.
|
||||
[examples/regorus](examples/regorus.rs) is an example program that shows how to integrate Regorus into your project and evaluate Rego policies.
|
||||
|
||||
To build it, do
|
||||
To build and install it, do
|
||||
|
||||
cargo build -r --example regorus
|
||||
cargo install --example regorus --path .
|
||||
|
||||
|
||||
Check that the regorus example program is working
|
||||
|
||||
$ target/release/examples/regorus
|
||||
$ regorus
|
||||
Usage: regorus <COMMAND>
|
||||
|
||||
Commands:
|
||||
eval Evaluate a Rego Query
|
||||
lex Tokenize a Rego policy
|
||||
parse Parse q Rego policy
|
||||
parse Parse a Rego policy
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
|
||||
Options:
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
-V, --version Print versionUsage: regorus <COMMAND>
|
||||
|
||||
|
||||
|
||||
First, let's evaluate a simple Rego expression `1*2+3`
|
||||
|
||||
target/release/examples/regorus eval "1*2+3"
|
||||
regorus eval "1*2+3"
|
||||
|
||||
This produces the following output
|
||||
|
||||
@@ -63,16 +64,11 @@ This produces the following output
|
||||
|
||||
Next, evaluate a sample [policy](examples/example.rego) and [input](examples/input.json) (borrowed from [Rego tutorial](https://www.openpolicyagent.org/docs/latest/#2-try-opa-eval)):
|
||||
|
||||
target/release/examples/regorus eval -d examples/example.rego -i examples/input.json data.example
|
||||
regorus eval -d examples/example.rego -i examples/input.json data.example
|
||||
|
||||
Finally, evaluate real-world [policies](tests/aci/) used in Azure Container Instances (ACI)
|
||||
|
||||
target/release/examples/regorus eval -d tests/aci/framework.rego \
|
||||
-d tests/aci/policy.rego \
|
||||
-d tests/aci/api.rego \
|
||||
-d tests/aci/data.json \
|
||||
-i tests/aci/input.json \
|
||||
data.policy.mount_overlay=x
|
||||
regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.policy.mount_overlay=x
|
||||
|
||||
|
||||
## ACI Policies
|
||||
@@ -94,26 +90,24 @@ Regorus successfully passes the ACI policy test-suite. It is fast and can run ea
|
||||
|
||||
Run the ACI policies in the `tests/aci` directory, using data `tests/aci/data.json` and input `tests/aci/input.json`:
|
||||
|
||||
target/release/examples/regorus eval \
|
||||
-b tests/aci \
|
||||
-d tests/aci/data.json \
|
||||
-i tests/aci/input.json \
|
||||
data.framework.mount_overlay=x
|
||||
regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.policy.mount_overlay=x
|
||||
|
||||
|
||||
Verify that [OPA](https://github.com/open-policy-agent/opa/releases) produces the same output
|
||||
|
||||
diff <(target/release/examples/regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x) <(opa eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x)
|
||||
diff <(regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x) \
|
||||
<(opa eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x)
|
||||
|
||||
## Performance
|
||||
|
||||
To check how fast Regorus runs on your system, first install a tool like [hyperfine](https://github.com/sharkdp/hyperfine).
|
||||
|
||||
cargo install hyperfine
|
||||
cargo install hyperfine
|
||||
|
||||
Then benchmark evaluation of the ACI policies,
|
||||
|
||||
$ hyperfine "target/release/examples/regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x"
|
||||
Benchmark 1: target/release/examples/regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x
|
||||
$ hyperfine "regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x"
|
||||
Benchmark 1: regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x
|
||||
Time (mean ± σ): 4.6 ms ± 0.2 ms [User: 4.1 ms, System: 0.4 ms]
|
||||
Range (min … max): 4.4 ms … 6.0 ms 422 runs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user