Home

Awesome

CI Coverage Status Static Badge

Open Policy Agent (OPA) Compilation Tools

Backend for packaging OPA policy and data files into bundles for OpaDotNet project.

NuGet Packages

Package
OpaDotNet.Compilation.AbstractionsNuGet
OpaDotNet.Compilation.CliNuGet
OpaDotNet.Compilation.InteropNuGet

Getting Started

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.

Cli

Install OpaDotNet.Compilation.Cli nuget package

dotnet add package OpaDotNet.Compilation.Cli

Usage

[!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.
...

Interop

Install OpaDotNet.Compilation.Interop nuget package

dotnet add package OpaDotNet.Compilation.Interop

Usage

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.
...

Building

Prerequisites

Linux (WSL)

Windows

[!NOTE] WSL 2.0 is required to compile Opa.Interop.so on windows.

Build and Test

3rd Party Libraries and Contributions