OpaDotNet.Wasm
3.0.0-preview-0001
See the version list below for details.
dotnet add package OpaDotNet.Wasm --version 3.0.0-preview-0001
NuGet\Install-Package OpaDotNet.Wasm -Version 3.0.0-preview-0001
<PackageReference Include="OpaDotNet.Wasm" Version="3.0.0-preview-0001" />
paket add OpaDotNet.Wasm --version 3.0.0-preview-0001
#r "nuget: OpaDotNet.Wasm, 3.0.0-preview-0001"
// Install OpaDotNet.Wasm as a Cake Addin #addin nuget:?package=OpaDotNet.Wasm&version=3.0.0-preview-0001&prerelease // Install OpaDotNet.Wasm as a Cake Tool #tool nuget:?package=OpaDotNet.Wasm&version=3.0.0-preview-0001&prerelease
Open Policy Agent (OPA) WebAssembly dotnet core SDK
This is SDK for using WebAssembly (wasm) compiled Open Policy Agent policies with dotnet core.
Initial implementation was based on Open Policy Agent WebAssemby NPM Module
For more information check out the guide.
Key Features
- Fast in-process OPA policies evaluation.
- Full ABI support.
- Additional OPA built-ins.
- Compilation.
- AspDotNet Core integration.
Getting Started
Install nuget package
dotnet add package OpaDotNet.Wasm
Usage
To evaluate OPA policy you need to:
Load compiled policy
using using OpaDotNet.Wasm;
const string data = "{ \"world\": \"world\" }";
using var engine = OpaEvaluatorFactory.CreateFromWasm(
File.OpenRead("policy.wasm")
);
engine.SetDataFromRawJson(data);
Evaluate policy
IOpaEvaluator
has several APIs for policy evaluation:
EvaluatePredicate
- Evaluates named policy with specified input. Response interpreted as simpletrue
/false
result.Evaluate
- Evaluates named policy with specified input.EvaluateRaw
- Evaluates named policy with specified raw JSON input.
var policyResult = engine.EvaluatePredicate(inp);
Check result
if (policyResult.Result)
{
// We've been authorized.
}
else
{
// Can't do that.
}
Writing policy
See writing policy
Compiling policy
You have several options to compile rego policy into wasm module:
package example
default hello = false
hello if {
x := input.message
x == data.world
}
Manually
Either use the Compile REST API or opa build CLI tool.
For example, with OPA v0.20.5+:
opa build -t wasm -e example/hello example.rego
Which is compiling the example.rego
policy file.
The result will be an OPA bundle with the policy.wasm
binary included. See ./samples for a more
comprehensive example.
See opa build --help
for more details.
With OpaDotNet.Compilation
You can use SDK to do compilation for you. For more information see OpaDotNet.Compilation.
OpaDotNet.Compilation.Cli
dotnet add package OpaDotNet.Compilation.Cli
using OpaDotNet.Wasm;
using OpaDotNet.Compilation.Cli;
var compiler = new RegoCliCompiler();
var policyStream = await compiler.CompileFile("example.rego", new[] { "example/hello" });
// Use compiled policy.
using var engine = OpaEvaluatorFactory.CreateFromBundle(policyStream);
OpaDotNet.Compilation.Interop
dotnet add package OpaDotNet.Compilation.Interop
using OpaDotNet.Wasm;
using OpaDotNet.Compilation.Interop;
var compiler = new RegoInteropCompiler();
var policyStream = await compiler.CompileFile("example.rego", new[] { "example/hello" });
// Use compiled policy.
using var engine = OpaEvaluatorFactory.CreateFromBundle(policyStream);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- IPNetwork2 (>= 3.0.667)
- JetBrains.Annotations (>= 2024.2.0)
- JsonPatch.Net (>= 3.1.1)
- JsonSchema.Net (>= 7.2.3)
- Microsoft.Extensions.Primitives (>= 8.0.0)
- Semver (>= 2.3.0)
- System.IdentityModel.Tokens.Jwt (>= 8.1.0)
- Wasmtime (>= 22.0.0)
- Yaml2JsonNode (>= 2.1.1)
- YamlDotNet (>= 16.1.3)
-
net8.0
- IPNetwork2 (>= 3.0.667)
- JetBrains.Annotations (>= 2024.2.0)
- JsonPatch.Net (>= 3.1.1)
- JsonSchema.Net (>= 7.2.3)
- Microsoft.Extensions.Primitives (>= 8.0.0)
- Semver (>= 2.3.0)
- System.IdentityModel.Tokens.Jwt (>= 8.1.0)
- Wasmtime (>= 22.0.0)
- Yaml2JsonNode (>= 2.1.1)
- YamlDotNet (>= 16.1.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OpaDotNet.Wasm:
Package | Downloads |
---|---|
OpaDotNet.Extensions.AspNetCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.0-preview-0004 | 70 | 11/10/2024 |
3.0.0-preview-0001 | 73 | 10/25/2024 |
3.0.0-preview-0000 | 63 | 10/25/2024 |
2.5.1 | 81 | 11/8/2024 |
2.5.0 | 498 | 2/12/2024 |
2.4.1 | 145 | 1/26/2024 |
2.4.1-pre0004 | 96 | 1/23/2024 |
2.4.0 | 176 | 1/10/2024 |
2.3.0 | 231 | 11/21/2023 |
2.2.0 | 193 | 10/11/2023 |
2.2.0-preview0010 | 147 | 10/9/2023 |
2.2.0-preview0008 | 146 | 10/3/2023 |
2.1.1 | 157 | 9/29/2023 |
2.1.0 | 167 | 9/28/2023 |
2.0.0 | 287 | 8/18/2023 |
2.0.0-preview0012 | 124 | 8/18/2023 |
2.0.0-preview | 122 | 8/17/2023 |
1.4.0 | 215 | 8/15/2023 |
1.3.0 | 157 | 8/9/2023 |
1.3.0-preview0010 | 137 | 8/7/2023 |
1.2.1 | 193 | 7/27/2023 |
1.2.0 | 197 | 7/26/2023 |
1.2.0-preview0033 | 142 | 7/25/2023 |
1.2.0-preview0028 | 130 | 7/24/2023 |
1.2.0-preview0012 | 151 | 7/20/2023 |
1.2.0-preview0009 | 131 | 7/19/2023 |
1.2.0-preview0007 | 134 | 7/19/2023 |
1.1.0 | 175 | 7/13/2023 |
1.1.0-preview0078 | 151 | 7/13/2023 |
1.1.0-preview0076 | 113 | 7/13/2023 |
1.1.0-preview0073 | 120 | 7/13/2023 |
1.1.0-preview0068 | 140 | 7/12/2023 |
1.1.0-preview0067 | 160 | 7/12/2023 |
1.1.0-preview0065 | 156 | 7/12/2023 |
1.1.0-preview0063 | 142 | 7/12/2023 |
1.1.0-preview0061 | 160 | 7/11/2023 |
1.1.0-preview0057 | 127 | 7/11/2023 |
1.1.0-preview0053 | 126 | 7/11/2023 |
1.1.0-preview0049 | 106 | 7/10/2023 |
1.1.0-preview0047 | 118 | 7/10/2023 |
1.1.0-preview0018 | 145 | 7/6/2023 |
1.1.0-preview0015 | 127 | 7/6/2023 |
1.1.0-preview0012 | 133 | 7/6/2023 |
1.1.0-preview0011 | 135 | 7/5/2023 |
1.1.0-preview0010 | 139 | 7/5/2023 |
1.1.0-preview0009 | 123 | 7/5/2023 |
1.1.0-preview0007 | 123 | 7/3/2023 |
1.0.0 | 160 | 6/27/2023 |
1.0.0-preview0059 | 143 | 6/27/2023 |
1.0.0-preview0058 | 128 | 6/27/2023 |
1.0.0-preview0056 | 125 | 6/27/2023 |
1.0.0-preview0049 | 120 | 6/23/2023 |
1.0.0-preview0048 | 125 | 6/23/2023 |
1.0.0-preview0047 | 110 | 6/23/2023 |
1.0.0-preview0045 | 135 | 6/23/2023 |
1.0.0-preview0043 | 119 | 6/23/2023 |
1.0.0-preview0041 | 88 | 6/22/2023 |
1.0.0-preview0040 | 133 | 6/22/2023 |
1.0.0-preview0037 | 107 | 6/22/2023 |
1.0.0-preview0036 | 125 | 6/22/2023 |
1.0.0-preview0032 | 131 | 6/22/2023 |
1.0.0-preview0031 | 130 | 6/22/2023 |
1.0.0-preview0029 | 115 | 6/21/2023 |
1.0.0-preview0027 | 130 | 6/21/2023 |
1.0.0-preview0025 | 125 | 6/21/2023 |
1.0.0-preview0023 | 139 | 6/21/2023 |
1.0.0-preview0021 | 104 | 6/20/2023 |
1.0.0-preview0012 | 110 | 6/20/2023 |
1.0.0-preview0011 | 136 | 6/20/2023 |