A dotnet OPA client designed for applications to take advantage of its first-class WebAssembly support.
DOPA is built with Wasmtime, the same runtime used by OPA for WebAssembly.
To start, you will need to compile your OPA policy for WebAssembly to get a .wasm
. See OPA's documentation on compiling policies for more details. This document refers to example.rego.
Currently, the compiled wasm needs to be extracted from the output bundle. This can be accomplished with tar
.
$ opa build -t wasm -e example/hello example.rego
$ tar -xzf ./bundle.tar.gz /policy.wasm
With your compiled wasm available to your application, and named whatever you want, instantiate an IOpaModule
from the file.
using DOPA;
using IOpaModule module = WasmModule.FromFile("./example.wasm");
The module links the WebAssembly runtime to your application, and incurs an extra compilation cost that you don't want to repeat very often. It is also where you can configure things that don't change between your policy instances, such as a serializer.
Create an instance of IOpaPolicy
to set any data, evaluate your policy, and start getting results.
using IOpaPolicy policy = module.CreatePolicy();
policy.SetData(new { world = "hello" });
var allowed = policy.Evaluate<bool>(new { message = "hello" });
Pull requests and issues are appreciated and encouraged.
DOPA is licensed under the MIT License.