rego-cpp 0.4.5
A C++ implementation of the Rego language and runtime
|
rego-cpp
This project is an effort to create a C++ interpreter for the OPA policy language, Rego. Our goal is to build both a standalone executable and a library such that programmers who are working in C++ can interpret Rego programs natively. To achieve this we are building our interpreter on top of the experimental term rewriter Trieste.
Warning While this project has progressed to the point that we support full Rego language (see Language Support below) we do not support all built-ins. That said, we have verified compliance with the OPA Rego test suite. Even so, it should still be considered experimental software and used with discretion.
Start by installing CMake in the way appropriate for your environment.
Create a build directory and initialize the cmake project:
mkdir build cd build cmake .. --preset release-clang
You can then build and run the tests using:
ninja install ctest
Create a build directory and initialize the cmake project:
mkdir build cd build cmake .. --preset release
You can then build and run the tests using:
cmake --build . --config Release --target INSTALL ctest -C Release
rego
CLIThe interpreter tool will be located at build/dist/bin/rego
. Here are some example commands using the provided example files and run from the suggested dist
install directory:
./bin/rego -d examples/scalars.rego -q data.scalars.greeting {"expressions":["Hello"]} ./bin/rego -d examples/objects.rego -q data.objects.sites[1].name {"expressions":["smoke1"]} ./bin/rego -d examples/data0.json examples/data1.json examples/objects.rego -i examples/input0.json -q "[data.one, input.b, data.objects.sites[1]]" {"expressions":[[{"bar":"Foo", "baz":5, "be":true, "bop":23.4}, "20", {"name":"smoke1"}]]} ./bin/rego -q "5 + (2 - 4 * 0.25) * -3 + 7.4" {"bindings":{"x":5, "y":9.4}} ./bin/rego -d examples/bodies.rego -i examples/input1.json -q data.bodies.e {"expressions":[{"one":15, "two":15}]}
You can run the test driver from the same directory:
./bin/rego_test tests/regocpp.yaml
rego
LibrarySee the examples directory for examples of how to use the library from different langauages.
We support v0.68.0 of Rego as defined by OPA, with the following grammar:
rego.v1
enabled (See OPA v1.0 for more info).Definitions:
At the moment support the following builtins are available:
aggregates
arrays
bits
casts
encoding
graphs
numbers
objects
regex
semver
sets
strings
time
types
units
uuid
opa.runtime
print
Our goal is to achieve and maintain full compatibility with the reference Go implementation. We have developed a test driver which runs the same tests and validates that we produce the same outputs. At this stage we pass all the non-builtin specific test suites, which we clone from the OPA repository. To build with the OPA tests available for testing, use one of the following presets:
release-clang-opa
release-opa
At present, we are NOT passing the following test suites in full:
crypto*
glob*
graphql
invalidkeyerror
json*
(except jsonbuiltins
)jwt*
net*
planner-ir
providers-aws
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.