Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/skills/bump-version/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ library and its wrapper packages.
| `wrappers/python/setup.py` | `VERSION = "X.Y.Z"` | `VERSION = "1.3.0"` |
| `wrappers/rust/regorust/Cargo.toml` | `version = "X.Y.Z"` | `version = "1.3.0"` |
| `wrappers/dotnet/Rego/Rego.csproj` | `<Version>X.Y.Z</Version>` | `<Version>1.3.0</Version>` |
| `examples/rust/Cargo.toml` | `regorust = { version = "X.Y.Z" }` | `regorust = { version = "1.3.0" }` |
| `examples/dotnet/example/example.csproj` | `Version="X.Y.Z"` | `Version="1.3.0"` |
| `examples/dotnet/MyPolicy/MyPolicy.csproj` | `Version="X.Y.Z"` | `Version="1.3.0"` |

## Procedure

Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/pr_gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,105 @@ jobs:
working-directory: ${{github.workspace}}/wrappers/python/
run: pytest -vv

linux-example-cpp:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Get dependencies
run: |
sudo apt-get update
sudo apt-get install -y ninja-build libssl-dev

- name: CMake config
working-directory: ${{github.workspace}}/examples/cpp
run: cmake -B ${{github.workspace}}/examples/cpp/build --preset release -G Ninja
env:
REGOCPP_REPO: LOCAL

- name: CMake build
working-directory: ${{github.workspace}}/examples/cpp/build
run: ninja install

- name: CMake test
working-directory: ${{github.workspace}}/examples/cpp/build
run: ctest -V --build-config Release --timeout 120 --output-on-failure -T Test

linux-example-python:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Use Python
uses: actions/setup-python@v6
with:
python-version: "3.12"

- name: Get dependencies
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev
python -m pip install --upgrade pip

- name: Python build
working-directory: ${{github.workspace}}/wrappers/python/
run: pip install -e .[dev]
env:
REGOCPP_REPO: LOCAL

- name: Run example
working-directory: ${{github.workspace}}/examples/python
run: python example.py

linux-example-rust:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Get dependencies
run: |
sudo apt-get update
sudo apt-get install -y cargo rustc libssl-dev

- name: Cargo run
working-directory: ${{github.workspace}}/examples/rust
run: cargo run --config 'patch.crates-io.regorust.path="../../wrappers/rust/regorust"'
env:
REGOCPP_REPO: LOCAL

linux-example-dotnet:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Get dependencies
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev

- name: Use dotnet
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x

- name: Patch project reference
working-directory: ${{github.workspace}}/examples/dotnet/example
run: sed -i 's|<PackageReference Include="Rego" Version="[^"]*" />|<ProjectReference Include="../../../wrappers/dotnet/Rego/Rego.csproj" />|' example.csproj

- name: Run example
working-directory: ${{github.workspace}}/examples/dotnet/example
run: dotnet run
env:
REGOCPP_REPO: LOCAL

linux-cheriot:
runs-on: ubuntu-latest

Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ You can run the test driver from the same directory:

./bin/rego_test tests/regocpp.yaml

### Installing with vcpkg

You can install rego-cpp using [vcpkg](https://vcpkg.io/):

```bash
vcpkg install rego-cpp
```

To enable crypto/JWT built-ins (requires OpenSSL 3):

```bash
vcpkg install rego-cpp[openssl3]
```

To also install the `rego` CLI tool:

```bash
vcpkg install rego-cpp[openssl3,tools]
```

Then in your CMake project:

```cmake
find_package(regocpp CONFIG REQUIRED)
target_link_libraries(<your-target> PRIVATE regocpp::rego)
```

For overlay port usage, see [`ports/rego-cpp/`](ports/rego-cpp/).

### Using the `rego` Library

See the [examples](examples/README.md) directory for examples of how to use the
Expand Down
61 changes: 29 additions & 32 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,51 +50,48 @@ a@host:dist$ ./bin/regoc -d examples/scalars.rego -q data.scalars.greeting
```

## Python
The Python example is a [simple command line tool](python/rego.py) that takes zero or more
Rego data, module, and input files and evaluates a query against them.

Examples:
The [Python example](python/example.py) is a demonstration program that shows
how to use all the features of the wrapper, including queries, input/data,
and bundles.

```bash
a@host:python$ pip install regopy
a@host:python$ python rego.py eval -d examples/scalars.rego data.scalars.greeting
{"expressions":["Hello"]}

a@host:python$ python rego.py eval -d examples/objects.rego data.objects.sites[1].name
{"expressions":["smoke1"]}

a@host:python$ python rego.py eval -d examples/data0.json -d examples/data1.json -d examples/objects.rego -i examples/input0.json "[data.one, input.b, data.objects.sites[1]]"
{"expressions":[[{"bar":"Foo", "baz":5, "be":true, "bop":23.4},"20",{"name":"smoke1"}]]}

a@host:python$ python rego.py eval "x=5; y=x + (2 - 4 * 0.25) * -3 + 7.4;2 * 5"
a@host:python$ python example.py
Query Only
{"expressions":[true, true, 10], "bindings":{"x":5, "y":9.4}}
x = 5
10

a@host:python$ python rego.py eval -d examples/bodies.rego -i examples/input1.json data.bodies.e
{"expressions":[{"one":15, "two":15}]}
```
Input and Data
{"expressions":[true], "bindings":{"x":[{"bar":"Foo", "baz":5, "be":true, "bop":23.4},"20",{"name":"smoke1"}]}}

Bundles
query: {"expressions":[true], "bindings":{"x":4460}}
example/foo: {"expressions":[2275]}
```

## Rust
The Rust example is another [simple command line tool](rust/src/main.rs) that takes zero or more
There is also a [command line tool](python/rego.py) that takes zero or more
Rego data, module, and input files and evaluates a query against them.

Examples:

```bash
a@host:rust$ cargo run -- eval -d examples/scalars.rego data.scalars.greeting
{"expressions":["Hello"]}

a@host:rust$ cargo run -- eval -d examples/objects.rego data.objects.sites[1].name
{"expressions":["smoke1"]}

a@host:rust$ cargo run -- eval -d examples/data0.json -d examples/data1.json -d examples/objects.rego -i examples/input0.json "[data.one, input.b, data.objects.sites[1]]"
{"expressions":[[{"bar":"Foo", "baz":5, "be":true, "bop":23.4},"20",{"name":"smoke1"}]]}
## Rust
The [Rust example](rust/src/main.rs) is a demonstration program that shows
how to use all the features of the wrapper, including queries, input/data,
and bundles.

a@host:rust$ cargo run -- eval "x=5; y=x + (2 - 4 * 0.25) * -3 + 7.4;5 * 2"
```bash
a@host:rust$ cargo run
Query Only
{"expressions":[true, true, 10], "bindings":{"x":5, "y":9.4}}
x = 5
10

Input and Data
{"expressions":[true], "bindings":{"x":[{"bar":"Foo", "baz":5, "be":true, "bop":23.4},"20",{"name":"smoke1"}]}}

a@host:rust$ cargo run -- eval -d examples/bodies.rego -i examples/input1.json data.bodies.e
{"expressions":[{"one":15, "two":15}]}
Bundles
query: {"expressions":[true], "bindings":{"x":4460}}
example/foo: {"expressions":[2275]}
```

## dotnet
Expand Down
7 changes: 6 additions & 1 deletion examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ add_test(
COMMAND bin/regoc -d examples/data0.json -d examples/data1.json -i examples/input0.json -d examples/objects.rego -q data.objects.sites[1]
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist
)
set_tests_properties(regoc PROPERTIES PASS_REGULAR_EXPRESSION "{\"name\":\"smoke1\"}")
set_tests_properties(regoc PROPERTIES PASS_REGULAR_EXPRESSION "{\"name\":\"smoke1\"}")
add_test(
NAME example
COMMAND bin/example
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist
)
7 changes: 6 additions & 1 deletion examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ add_test(
COMMAND bin/custom_builtin
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist
)
set_tests_properties(custom_builtin PROPERTIES PASS_REGULAR_EXPRESSION "5")
set_tests_properties(custom_builtin PROPERTIES PASS_REGULAR_EXPRESSION "5")
add_test(
NAME example
COMMAND bin/example
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist
)
2 changes: 0 additions & 2 deletions examples/cpp/example.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "trieste/logging.h"

#include <rego/rego.hh>

int main()
Expand Down
Loading
Loading