From b6935d1addd759d38d19535d2018360dc408ff56 Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi <35780660+anakrish@users.noreply.github.com> Date: Tue, 10 Sep 2024 11:47:46 -0700 Subject: [PATCH] fix: Update readme with correct path to example policy (#312) Also add test to lock down example policy path. Also Fix clippy warning by using unwrap_or_default Signed-off-by: Anand Krishnamoorthi --- .github/workflows/pr.yml | 2 ++ README.md | 6 +++--- src/utils.rs | 5 +---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 90ad5724..cfcb22d4 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -30,6 +30,8 @@ jobs: run: cargo test -r --doc - name: Run tests run: cargo test -r + - name: Run example + run: cargo run --example regorus -- eval -d examples/server/allowed_server.rego -i examples/server/input.json data.example - name: Run tests (ACI) run: cargo test -r --test aci - name: Run tests (KATA) diff --git a/README.md b/README.md index 505bd404..c908fe70 100644 --- a/README.md +++ b/README.md @@ -184,11 +184,11 @@ This produces the following output } ``` -Next, evaluate a sample [policy](https://github.com/microsoft/regorus/blob/main/examples/example.rego) and [input](https://github.com/microsoft/regorus/blob/main/examples/input.json) +Next, evaluate a sample [policy](https://github.com/microsoft/regorus/blob/main/examples/server/allowed_server.rego) and [input](https://github.com/microsoft/regorus/blob/main/examples/server/input.json) (borrowed from [Rego tutorial](https://www.openpolicyagent.org/docs/latest/#2-try-opa-eval)): ```bash -$ regorus eval -d examples/example.rego -i examples/input.json data.example +$ regorus eval -d examples/server/allowed_server.rego -i examples/server/input.json data.example ``` Finally, evaluate real-world [policies](tests/aci/) used in Azure Container Instances (ACI) @@ -204,7 +204,7 @@ Regorus allows determining which lines of a policy have been executed using the We can try it out using the `regorus` example program by passing in the `--coverage` flag. ```shell -$ regorus eval -d examples/example.rego -i examples/input.json data.example --coverage +$ regorus eval -d examples/server/allowed_server.rego -i examples/server/input.json data.example --coverage ``` It produces the following coverage report which shows that all lines are executed except the line that sets `allow` to true. diff --git a/src/utils.rs b/src/utils.rs index cdb0b65e..afdf8f08 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -78,10 +78,7 @@ pub fn get_extra_arg( module: Option<&str>, functions: &FunctionTable, ) -> Option> { - match get_extra_arg_impl(expr, module, functions) { - Ok(a) => a, - _ => None, - } + get_extra_arg_impl(expr, module, functions).unwrap_or_default() } pub fn gather_functions(modules: &[Ref]) -> Result {