Backend for packaging OPA policy and data files into bundles for OpaDotNet project.
Package | |
---|---|
OpaDotNet.Compilation.Abstractions | |
OpaDotNet.Compilation.Cli | |
OpaDotNet.Compilation.Interop |
Which one you should be using?
Use OpaDotNet.Compilation.Cli
if you have opa
CLI tool installed or you need functionality besides compilation (running tests, syntax checking etc.). Suitable for web applications and/or applications running in Docker containers. See README for more details.
Use OpaDotNet.Compilation.Interop
if you need compilation only and want to avoid having external dependencies. Suitable for libraries, console application etc. See README for more details.
For more information you can check the guide.
dotnet add package OpaDotNet.Compilation.Cli
Important
You will need opa
cli tool v0.20.0+ to be in your PATH or provide full path in RegoCliCompilerOptions
.
using OpaDotNet.Compilation.Abstractions;
using OpaDotNet.Compilation.Cli;
IRegoCompiler compiler = new RegoCliCompiler();
var bundleStream = await compiler.CompileFile("example.rego", new[] { "example/hello" });
// Use compiled policy bundle.
...
dotnet add package OpaDotNet.Compilation.Interop
using OpaDotNet.Compilation.Abstractions;
using OpaDotNet.Compilation.Interop;
IRegoCompiler compiler = new RegoInteropCompiler();
var bundleStream = await compiler.CompileFile("example.rego", new[] { "example/hello" });
// Use compiled policy bundle.
...
- go lang v1.20
- dotnet SDK 7.0
- opa cli
gcc
to compileOpa.Interop.so
gcc-mingw-w64
to compileOpa.Interop.dll
Note
WSL 2.0 is required to compile Opa.Interop.so
on windows.
- Powershell Core 7.0+
- WSL 2.0
- Run
build.ps1
Compile Opa.Interop libraries - Run
dotnet build
to build the project or use Visual Studio to buildOpaDotNet.Compilation.sln
- Run
dotnet test
to test the project or use Visual Studio test explorer.
- OPA SDK - High-level API for embedding OPA inside of Go programs.