### Install OpaDotNet.Compilation.Cli NuGet Package Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Add the OpaDotNet.Compilation.Cli package to your project for using the CLI compiler. ```bash dotnet add package OpaDotNet.Compilation.Cli ``` -------------------------------- ### Install OpaDotNet.Compilation.Interop NuGet Package Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Add the OpaDotNet.Compilation.Interop package to your project for using the interop compiler. ```bash dotnet add package OpaDotNet.Compilation.Interop ``` -------------------------------- ### Install OpaDotNet.Wasm NuGet Package Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Use the dotnet CLI to add the OpaDotNet.Wasm package to your project. ```bash dotnet add package OpaDotNet.Wasm ``` -------------------------------- ### Add OpaDotNet.Compilation.Cli Package Source: https://me-viper.github.io/OpaDotNet/articles/migration.html Install the new compilation package to replace the functionality previously in OpaDotNet.Wasm. ```bash dotnet add package OpaDotNet.Compilation.Cli ``` -------------------------------- ### NewGuid Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.DefaultOpaImportsAbi.html Allows overriding the default GUID generation logic. Returns a Guid. ```csharp protected virtual Guid NewGuid() ``` -------------------------------- ### CustomBuiltins Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmBuiltinsOptions.html Gets the list of custom OPA built-ins configured for the Wasm environment. ```csharp public IList CustomBuiltins { get; } ``` -------------------------------- ### RegoCliCompilerOptions.OpaToolPath Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Cli.RegoCliCompilerOptions.html Gets or sets the full path to the opa CLI tool. ```APIDOC ## RegoCliCompilerOptions.OpaToolPath ### Description Full path to opa cli tool. ### Property Value string ``` -------------------------------- ### DefaultBuiltins Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmBuiltinsOptions.html Gets or sets the default OPA built-ins configuration for the Wasm environment. ```csharp public IOpaImportsAbi DefaultBuiltins { get; set; } ``` -------------------------------- ### Compile Policy Bundle with Custom Built-ins (C#) Source: https://me-viper.github.io/OpaDotNet/articles/evaluation/bultins.html Compile a Rego policy bundle, specifying custom built-in capabilities and entrypoints. This example configures the engine to use custom built-ins. ```csharp var compilationParameters = new CompilationParameters { // Custom built-ins will be merged with capabilities v0.53.1. CapabilitiesVersion = "v0.53.1", // Provide built-ins capabilities for the compiler. CapabilitiesFilePath = Path.Combine("builtins", "capabilities.json"), Entrypoints = [ "custom_builtins/zero_arg", "custom_builtins/one_arg", "custom_builtins/two_arg", "custom_builtins/three_arg", "custom_builtins/four_arg", ], }; var compiler = new RegoInteropCompiler(); var policy = await compiler.CompileBundleAsync( "builtins", compilationParameters ); var opts = new WasmPolicyEngineOptions(); opts.ConfigureBuiltins(p => p.CustomBuiltins.Add(new OpaCustomBuiltins())); using var factory = new OpaBundleEvaluatorFactory(policy, opts); var engine = factory.Create(); ``` -------------------------------- ### DefaultBuiltins Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmBuiltinsOptions.html Gets or sets the default OPA built-ins for Wasm execution. ```APIDOC ## DefaultBuiltins Property ### Description Gets or sets the default OPA built-ins. This property allows you to configure the standard set of built-in functions available to OPA policies executed via Wasm. ### Property Type IOpaImportsAbi ``` -------------------------------- ### OpaCustomBuiltinAttribute.Name Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.Builtins.OpaCustomBuiltinAttribute.html Gets the built-in name. ```APIDOC ## Name ### Description Built-in name. ### Property Value string ``` -------------------------------- ### NewGuid() Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.DefaultOpaImportsAbi.html When overridden allows replacing GUID generator. ```APIDOC ## NewGuid() ### Description When overriden allows replacing GUID generator. ### Method `protected virtual Guid NewGuid()` ### Returns - **Guid** - The generated GUID. ``` -------------------------------- ### RegoCompilerVersion GoVersion Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerVersion.html Gets or sets the version of the Go compiler used to build OPA. ```csharp public string? GoVersion { get; set; } ``` -------------------------------- ### CustomBuiltins Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmBuiltinsOptions.html Gets the custom OPA built-ins configured for Wasm execution. ```APIDOC ## CustomBuiltins Property ### Description Gets the custom OPA built-ins. This property allows you to provide a list of custom built-in functions that can be used within OPA policies executed via Wasm. ### Property Type IList ``` -------------------------------- ### RegoCompilerVersion Version Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerVersion.html Gets or sets the main version string of the OPA compiler. ```csharp public string? Version { get; set; } ``` -------------------------------- ### RegoCompilerVersion Platform Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerVersion.html Gets or sets the target platform for which the OPA compiler was built. ```csharp public string? Platform { get; set; } ``` -------------------------------- ### Entrypoint Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.WasmMetadata.html Gets or sets the string path defining the query path the Wasm module is built to evaluate. Usage of this path in a query will utilize the Wasm module. ```csharp [JsonPropertyName("entrypoint")] public string Entrypoint { get; init; } ``` -------------------------------- ### RegoCliCompilerOptions.ExtraArguments Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Cli.RegoCliCompilerOptions.html Gets or sets extra arguments to pass to the `opa build` CLI tool. ```APIDOC ## RegoCliCompilerOptions.ExtraArguments ### Description Extra arguments to pass to `opa build` cli tool. ### Property Value string ``` -------------------------------- ### Module Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.WasmMetadata.html Gets or sets the string path to the Wasm module relative to the root of the bundle. This specifies the location of the WebAssembly file. ```csharp [JsonPropertyName("module")] public string Module { get; init; } ``` -------------------------------- ### Get Compiler Version Information Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.IRegoCompiler.html Retrieves the version information for the OPA compiler. Supports cancellation via a CancellationToken. ```csharp Task Version(CancellationToken cancellationToken = default) ``` -------------------------------- ### OPA Build Command for Custom Capabilities File Source: https://me-viper.github.io/OpaDotNet/articles/reference/capabilities.html Equivalent command-line instruction for building a policy bundle with a custom capabilities file. ```bash opa build -t wasm ./policy-bundle -e example --capabilities mycaps.json ``` -------------------------------- ### IOpaEvaluator.AbiVersion Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.IOpaEvaluator.html Gets the ABI version used for policy evaluation. ```APIDOC ## IOpaEvaluator.AbiVersion ### Description ABI version used for evaluation. ### Property Value Version ``` -------------------------------- ### Create BundleWriter From Directory Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Illustrates creating a BundleWriter and populating it with files from a specified directory. Exclusions can be provided to skip certain files. ```csharp public static BundleWriter FromDirectory(Stream stream, string path, IReadOnlySet? exclusions) ``` -------------------------------- ### GetHashCode Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.CompilationParameters.html Gets the hash code for the CompilationParameters object. ```APIDOC ## GetHashCode() ### Description Returns a hash code for the current CompilationParameters object. ### Method `public override int GetHashCode()` ### Returns int - A hash code for the current object. ``` -------------------------------- ### OPA Build Command for Capabilities Version Source: https://me-viper.github.io/OpaDotNet/articles/reference/capabilities.html Equivalent command-line instruction for building OPA with a specified capabilities version. ```bash opa build -t wasm ./ --capabilities v0.22.0 ``` -------------------------------- ### WasmPolicyEngineOptions.SerializationOptions Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Gets or sets the JSON serialization options for the engine. ```APIDOC ## SerializationOptions Property ### Description JSON serialization options. ### Property Value JsonSerializerOptions ### Exceptions ArgumentNullException Value is `null`. ``` -------------------------------- ### Create BundleWriter Instance Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Shows how to create a new instance of BundleWriter, optionally providing a BundleManifest. The stream provided will be used to write the bundle content. ```csharp public BundleWriter(Stream stream, BundleManifest? manifest = null) ``` -------------------------------- ### WasmPolicyEngineOptions.SignatureValidation Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Gets or sets the options for OPA bundle signature validation. ```APIDOC ## SignatureValidation Property ### Description OPA bundle signature validation options. ### Property Value SignatureValidationOptions ``` -------------------------------- ### Define IOpaCustomBuiltins Interface Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.Builtins.IOpaCustomBuiltins.html This snippet shows the basic definition of the IOpaCustomBuiltins interface. Implement this interface to provide custom built-in functions to OPA. ```csharp public interface IOpaCustomBuiltins ``` -------------------------------- ### Implement Custom Built-in Functions with IOpaCustomBuiltins Source: https://me-viper.github.io/OpaDotNet/articles/evaluation/bultins.html Implement custom built-in functions by extending `IOpaCustomBuiltins`. Each function is registered using the `OpaCustomBuiltin` attribute. Supports functions with zero to four arguments. ```csharp public class OpaCustomBuiltins : IOpaCustomBuiltins { public void Reset() { } // Built-in with zero arguments. [OpaCustomBuiltin("custom.zeroArgBuiltin")] public static string ZeroArgBuiltin() => "hello"; // Built-in with one argument. [OpaCustomBuiltin("custom.oneArgBuiltin")] public static string OneArgBuiltin(string arg1) => $"hello {arg1}"; // Built-in with two arguments. [OpaCustomBuiltin("custom.twoArgBuiltin")] public static string TwoArgBuiltin(string arg1, string arg2) => $"hello {arg1} {arg2}"; // Built-in with three arguments. [OpaCustomBuiltin("custom.threeArgBuiltin")] public static string ThreeArgBuiltin(string arg1, string arg2, string arg3) => $"hello {arg1} {arg2} {arg3}"; // Built-in with four arguments. [OpaCustomBuiltin("custom.fourArgBuiltin")] public static string FourArgBuiltin(string arg1, string arg2, string arg3, string arg4) => $"hello {arg1} {arg2} {arg3} {arg4}"; } ``` -------------------------------- ### Result Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.PolicyEvaluationResult-1.html Gets or sets the policy result data of type T. ```csharp [JsonPropertyName("result")] public T Result { get; set; } ``` -------------------------------- ### BuiltinContext JsonSerializerOptions Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.BuiltinContext.html Gets the JSON serialization options used for this context. ```csharp public JsonSerializerOptions JsonSerializerOptions { get; } ``` -------------------------------- ### BundleWriter.FromDirectory() Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Creates a new BundleWriter instance and populates it with files from the specified directory. Exclusions can be provided to skip certain files. ```APIDOC ## FromDirectory(Stream, string, IReadOnlySet?) ### Description Creates new instance of BundleWriter and populates it with files in `path`. ### Parameters #### stream Stream to write bundle to. #### path Path containing bundle source files. #### exclusions File name patterns for files the BundleWriter should exclude from the results. ### Returns BundleWriter ``` -------------------------------- ### Compile Rego Bundle from Directory Source: https://me-viper.github.io/OpaDotNet/articles/compilation/interop.html Compile an entire bundle of Rego policies from a specified directory using RegoInteropCompiler. This method is useful for organizing multiple policy files. ```csharp var compiler = new RegoInteropCompiler(); var policy = await compiler.CompileBundleAsync( // Directory with bundle sources. "quickstart/", new() { // Entrypoints (same you would pass for -e parameter for opa build). Entrypoints = ["example/hello"], } ); // RegoCliCompiler will always produce bundle. using var engine = OpaBundleEvaluatorFactory.Create(policy); ``` -------------------------------- ### BuiltinContext FunctionName Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.BuiltinContext.html Gets the name of the built-in function associated with this context. ```csharp public string FunctionName { get; } ``` -------------------------------- ### RegoCompilerVersion Commit Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerVersion.html Gets or sets the commit hash of the OPA compiler. ```csharp public string? Commit { get; set; } ``` -------------------------------- ### Write Manifest to Bundle Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Shows how to write a BundleManifest object into the bundle. ```csharp public void WriteManifest(BundleManifest manifest) ``` -------------------------------- ### Write Policy Entry to Bundle Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Demonstrates writing a policy entry to a MemoryStream using BundleWriter. Ensure the BundleWriter instance is disposed to finalize the bundle. ```csharp using var ms = new MemoryStream(); using (var writer = new BundleWriter(ms)) { writer.WriteEntry("package test", "policy.rego"); } // Now bundle have been constructed. ms.Seek(0, SeekOrigin.Begin); ... ``` -------------------------------- ### Write Entry from Stream Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Demonstrates writing the content of a Stream into a bundle entry with a specified relative path. ```csharp public void WriteEntry(Stream stream, string path) ``` -------------------------------- ### Compile from Path Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Compiles an OPA bundle from a specified file path. This method requires the source path, compilation parameters, and a cancellation token. ```APIDOC ## Compile(string path, CompilationParameters parameters, CancellationToken cancellationToken) ### Description Compiles OPA bundle from path. ### Parameters #### Parameters - **path** (string) - Source path. - **parameters** (CompilationParameters) - Compilation parameters. - **cancellationToken** (CancellationToken) - Cancellation token. ### Returns Task - Compiled OPA bundle stream. ``` -------------------------------- ### Compile OPA Bundle from Path Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Compiles an OPA bundle from a specified file path. Use this method when the OPA policy is stored in a file. ```csharp public Task Compile(string path, CompilationParameters parameters, CancellationToken cancellationToken) ``` -------------------------------- ### CompileFileAsync Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a Rego file. ```APIDOC ## CompileFileAsync(IRegoCompiler, string, CompilationParameters) ### Description Compiles OPA bundle from rego bundle stream. ### Method `public static Task CompileFileAsync(this IRegoCompiler compiler, string sourceFilePath, CompilationParameters parameters)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **sourceFilePath** (string) - Required - Source file path. - **parameters** (CompilationParameters) - Required - Compiler parameters. ### Returns Task - Compiled OPA bundle stream. ``` ```APIDOC ## CompileFileAsync(IRegoCompiler, string, CompilationParameters, CancellationToken) ### Description Compiles OPA bundle from rego bundle stream. ### Method `public static Task CompileFileAsync(this IRegoCompiler compiler, string sourceFilePath, CompilationParameters parameters, CancellationToken cancellationToken)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **sourceFilePath** (string) - Required - Source file path. - **parameters** (CompilationParameters) - Required - Compiler parameters. - **cancellationToken** (CancellationToken) - Required - Cancellation token. ### Returns Task - Compiled OPA bundle stream. ``` -------------------------------- ### Compile(string, CompilationParameters, CancellationToken) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.IRegoCompiler.html Compiles an OPA bundle from a file path. ```APIDOC ## Compile(string, CompilationParameters, CancellationToken) ### Description Compiles OPA bundle from path. ### Method Task Compile(string path, CompilationParameters parameters, CancellationToken cancellationToken) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Task - Compiled OPA bundle stream. #### Response Example None ``` -------------------------------- ### RegoCompilerVersion EqualityContract Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerVersion.html Gets the type that represents the equality contract for the RegoCompilerVersion record. ```csharp protected virtual Type EqualityContract { get; } ``` -------------------------------- ### Get AbiVersion Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.IOpaEvaluator.html Retrieves the ABI version used for policy evaluation. This property is read-only. ```csharp Version AbiVersion { get; } ``` -------------------------------- ### Write Bundle from Stream Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Shows how to merge the contents of a source bundle (provided as a Stream) into the current BundleWriter instance. ```csharp public void WriteBundle(Stream bundle) ``` -------------------------------- ### RegoCliCompilerOptions.PreserveBuildArtifacts Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Cli.RegoCliCompilerOptions.html Gets or sets a value indicating whether to preserve intermediate compilation artifacts. ```APIDOC ## RegoCliCompilerOptions.PreserveBuildArtifacts ### Description If `true` compiler will preserve intermediate compilation artifacts; otherwise they will be deleted. ### Property Value bool ``` -------------------------------- ### DefaultOpaImportsAbi Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.DefaultOpaImportsAbi.html Initializes a new instance of the DefaultOpaImportsAbi class. ```csharp public DefaultOpaImportsAbi() ``` -------------------------------- ### DefaultOpaImportsAbi() Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.DefaultOpaImportsAbi.html Initializes a new instance of the DefaultOpaImportsAbi class. ```APIDOC ## DefaultOpaImportsAbi() ### Description Initializes a new instance of the DefaultOpaImportsAbi class. ### Method Constructor ### Parameters None ``` -------------------------------- ### Compile Policy Bundle with Custom Built-ins (C# - Alternative) Source: https://me-viper.github.io/OpaDotNet/articles/evaluation/bultins.html Compile a Rego policy bundle and configure the engine to use custom built-ins via a factory. This approach uses a custom built-ins factory. ```csharp var compilationParameters = new CompilationParameters { // Custom built-ins will be merged with capabilities v0.53.1. CapabilitiesVersion = "v0.53.1", // Provide built-ins capabilities for the compiler. CapabilitiesFilePath = Path.Combine("builtins", "capabilities.json"), Entrypoints = [ "custom_builtins/zero_arg", "custom_builtins/one_arg", "custom_builtins/two_arg", "custom_builtins/three_arg", "custom_builtins/four_arg", ], }; var compiler = new RegoInteropCompiler(); await using var policy = await compiler.CompileBundleAsync( "builtins", compilationParameters ); using var factory = new OpaBundleEvaluatorFactory( policy, null, new DefaultBuiltinsFactory(() => new CustomBuiltinsSample()) ); using var engine = factory.Create(); ``` -------------------------------- ### RegoInteropCompiler Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Initializes a new instance of the RegoInteropCompiler class. An optional logger can be provided for diagnostic purposes. ```csharp public RegoInteropCompiler(ILogger? logger = null) ``` -------------------------------- ### OpaCustomBuiltinAttribute Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.Builtins.OpaCustomBuiltinAttribute.html Initializes a new instance of the OpaCustomBuiltinAttribute class with a specified built-in name. ```APIDOC ## OpaCustomBuiltinAttribute(string name) ### Description Marks custom built-in implementation. ### Parameters #### Parameters - **name** (string) - Built-in name. ``` -------------------------------- ### Add Usings for OpaDotNet Compilation Source: https://me-viper.github.io/OpaDotNet/articles/compilation/cli.html Include necessary namespaces for using the OpaDotNet Wasm and Cli compilation features. ```csharp using OpaDotNet.Wasm; using OpaDotNet.Compilation.Cli; ``` -------------------------------- ### WasmPolicyEngineOptions.MinMemoryPages Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Gets or sets the minimum number of 64k memory pages available for the WASM engine. ```APIDOC ## MinMemoryPages Property ### Description Minimal number of 64k pages available for WASM engine. ### Property Value long ``` -------------------------------- ### Compile Policy using RegoInteropCompiler Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Use the RegoInteropCompiler from OpaDotNet.Compilation.Interop to compile a Rego file and create a WASM bundle. ```csharp 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); ``` -------------------------------- ### WasmPolicyEngineOptions.MaxMemoryPages Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Gets or sets the maximum number of 64k memory pages available for the WASM engine. ```APIDOC ## MaxMemoryPages Property ### Description Maximum number of 64k pages available for WASM engine. ### Property Value long? ``` -------------------------------- ### Add Usings for OpaDotNet Interop Source: https://me-viper.github.io/OpaDotNet/articles/compilation/interop.html Include these using statements to access the necessary OpaDotNet interop compiler functionalities. ```csharp using OpaDotNet.Wasm; using OpaDotNet.Compilation.Interop; ``` -------------------------------- ### WasmPolicyEngineOptions.MaxAbiVersion Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Gets or sets the maximum ABI version to use. Useful for compatibility with older policies. ```APIDOC ## MaxAbiVersion Property ### Description Max ABI versions to use. Can be useful for cases when you want evaluator to use lower ABI version than policy supports. ### Property Value Version ``` -------------------------------- ### Write Entry from Byte Span Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Shows how to write a Span of bytes into a bundle entry with a specified relative path. ```csharp public void WriteEntry(ReadOnlySpan bytes, string path) ``` -------------------------------- ### Compile Policy using RegoCliCompiler Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Use the RegoCliCompiler from OpaDotNet.Compilation.Cli to compile a Rego file and create a WASM bundle. ```csharp 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); ``` -------------------------------- ### WasmPolicyEngineOptions.StrictBuiltinErrors Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Gets or sets a value indicating whether errors in built-in functions should halt policy evaluation. ```APIDOC ## StrictBuiltinErrors Property ### Description If `true` errors in built-in functions will be threaded as exceptions that halt policy evaluation. ### Property Value bool ``` -------------------------------- ### WasmPolicyEngineOptions.CachePath Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Gets or sets the directory used to store unpacked policies. If null, policies are kept in memory. ```APIDOC ## CachePath Property ### Description Directory used to keep unpacked policies. If `null` policies will be kept in memory. ### Property Value string ### Remarks Directory must exist and requires write permissions. ``` -------------------------------- ### Create Default Engine Options with Custom JSON Serialization Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Creates default engine options with custom JSON serialization settings. An Action delegate is used to configure JsonSerializerOptions. ```csharp public static WasmPolicyEngineOptions DefaultWithJsonOptions(Action options) ``` -------------------------------- ### ExportResolutionException Constructors Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.ExportResolutionException.html Initializes a new instance of the ExportResolutionException. ```APIDOC ## ExportResolutionException(Version, string) ### Description Initializes a new instance of the ExportResolutionException. ### Parameters #### Parameters - **abiVersion** (Version) - OPA WASM module ABI version. - **externalName** (string) - External that caused the exception. ``` -------------------------------- ### Compile OPA Bundle from Stream Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.IRegoCompiler.html Compiles an OPA bundle from a provided stream. Requires compilation parameters and a cancellation token. ```csharp Task Compile(Stream stream, CompilationParameters parameters, CancellationToken cancellationToken) ``` -------------------------------- ### BuiltinArg.RawJson Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.BuiltinArg.html Gets the raw JSON representation of the built-in function argument, with REGO sets serialized as arrays. ```csharp public JsonNode? RawJson { get; } ``` -------------------------------- ### Compile Rego Policy Bundle Source: https://me-viper.github.io/OpaDotNet/articles/compilation/cli.html Compile a directory containing Rego policy files as a bundle using RegoCliCompiler. Requires the 'opa' CLI in PATH. This method compiles a bundle and creates a bundle. ```csharp var compiler = new RegoCliCompiler(); var policy = await compiler.CompileBundleAsync( // Directory with bundle sources. "quickstart", new() { // Entrypoints (same you would pass for -e parameter for opa build). Entrypoints = ["example/hello"], } ); // RegoCliCompiler will always produce bundle. using var engine = OpaBundleEvaluatorFactory.Create(policy); ``` -------------------------------- ### Get Compiler Version Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Retrieves the version information for the OPA compiler. This method accepts an optional cancellation token. ```APIDOC ## Version(CancellationToken cancellationToken) ### Description Compiler version information. ### Parameters #### Parameters - **cancellationToken** (CancellationToken) - ### Returns Task - ``` -------------------------------- ### WasmMetadata Constructor with Entrypoint and Module Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.WasmMetadata.html Constructs a WasmMetadata object with the specified entrypoint and module path. The entrypoint defines the query path, and the module is the relative path to the Wasm file. ```csharp public WasmMetadata(string Entrypoint, string Module) ``` -------------------------------- ### Get Compiler Version Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Retrieves the version information for the OPA compiler. A cancellation token can be provided to abort the operation. ```csharp public Task Version(CancellationToken cancellationToken = default) ``` -------------------------------- ### Compile Single Rego Policy File Source: https://me-viper.github.io/OpaDotNet/articles/compilation/interop.html Compile a single Rego policy file using RegoInteropCompiler. Ensure the policy source file exists and specify entrypoints for the compilation. ```csharp var compiler = new RegoInteropCompiler(); var policy = await compiler.CompileFileAsync( // Policy source file. "quickstart/example.rego", new() { // Entrypoints (same you would pass for -e parameter for opa build). Entrypoints = ["example/hello"], } ); // RegoCliCompiler will always produce bundle. using var engine = OpaBundleEvaluatorFactory.Create(policy); ``` -------------------------------- ### OpaCustomBuiltinAttribute.Memorize Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.Builtins.OpaCustomBuiltinAttribute.html Gets or sets a value indicating whether to enable value memoization across multiple calls in the same query. ```APIDOC ## Memorize ### Description If `true` enables value memoization across multiple calls in the same query. ### Property Value bool ``` -------------------------------- ### BuiltinArg.Raw Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.BuiltinArg.html Gets the raw JSON representation of the built-in function argument, including REGO sets specific patches. ```csharp public JsonNode? Raw { get; } ``` -------------------------------- ### CompileFile (Obsolete) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a Rego policy source file. This method is obsolete and CompileFileAsync should be used instead. ```APIDOC ## CompileFile ### Description Compiles OPA bundle from rego policy source file. ### Method `public static Task CompileFile(this IRegoCompiler compiler, string sourceFilePath, IEnumerable? entrypoints = null, CancellationToken cancellationToken = default)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **sourceFilePath** (string) - Required - Source file path. - **entrypoints** (IEnumerable?) - Optional - Which documents (entrypoints) will be queried when asking for policy decisions. - **cancellationToken** (CancellationToken) - Optional - Cancellation token. #### Returns Task - Compiled OPA bundle stream. ``` -------------------------------- ### TryGetFeature Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.IOpaEvaluator.html Attempts to retrieve an ABI version specific extension feature. Returns true if the feature is supported and populated. ```csharp bool TryGetFeature(out TFeature feature) where TFeature : class, IOpaEvaluatorFeature ``` -------------------------------- ### RegoCompilationException SourceFile Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilationException.html Gets the source file that caused the current exception. This property provides information about the file where the OPA policy compilation failed. ```csharp public string? SourceFile { get; } ``` -------------------------------- ### Compile OPA Bundle with Custom Capabilities File Source: https://me-viper.github.io/OpaDotNet/articles/reference/capabilities.html Compile a policy bundle using a custom capabilities file. This file defines the capabilities used for policy validation. This method is applicable only to policy bundles. ```csharp var compiler = new RegoCliCompiler(); await using var policy = await compiler.CompileBundle( "./policy-bundle", "example", "mycaps.json" ); ``` -------------------------------- ### Compile Raw Rego Policy Source Source: https://me-viper.github.io/OpaDotNet/articles/compilation/cli.html Compile Rego policy source code directly using RegoCliCompiler. Ensure the 'opa' CLI is in your PATH. This method compiles source code and creates a bundle. ```csharp IRegoCompiler compiler = new RegoCliCompiler(); var policySource = """ package example default hello = false hello { x := input.message x == data.world } """; var policy = await compiler.CompileSourceAsync( // Policy source code. policySource, new() { // Entrypoints (same you would pass for -e parameter for opa build). Entrypoints = ["example/hello"], } ); // RegoCliCompiler will always produce bundle. using var engine = OpaBundleEvaluatorFactory.Create(policy); ``` -------------------------------- ### Equals Method (BundleManifest) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleManifest.html Compares this BundleManifest instance to another BundleManifest for equality. ```csharp public virtual bool Equals(BundleManifest? other) ``` -------------------------------- ### Add Usings for OpaDotNet Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Include the necessary using directive for OpaDotNet.Wasm in your C# code. ```csharp using OpaDotNet.Wasm; ``` -------------------------------- ### Compile Single Rego Policy File Source: https://me-viper.github.io/OpaDotNet/articles/compilation/cli.html Compile a single Rego policy file using RegoCliCompiler. Ensure the 'opa' CLI is in your PATH. This method compiles a file and creates a bundle. ```csharp var compiler = new RegoCliCompiler(); var policy = await compiler.CompileFileAsync( // Policy source file. "quickstart/example.rego", new() { // Entrypoints (same you would pass for -e parameter for opa build). Entrypoints = ["example/hello"], } ); // RegoCliCompiler will always produce bundle. using var engine = OpaBundleEvaluatorFactory.Create(policy); ``` -------------------------------- ### RegoInteropCompiler Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Creates a new instance of the RegoInteropCompiler class. An optional logger can be provided. ```APIDOC ## RegoInteropCompiler(ILogger? logger) ### Description Creates new instance of RegoInteropCompiler class. ### Parameters #### Parameters - **logger** (ILogger?) - Logger instance ``` -------------------------------- ### Write File to Bundle Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Demonstrates writing the contents of a file into the bundle. An optional overridePath can be provided to specify the bundle's internal path. ```csharp public void WriteFile(string path, string? overridePath = null) ``` -------------------------------- ### CompileSourceAsync Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles OPA bundle from rego policy source code. ```APIDOC ## CompileSourceAsync(IRegoCompiler, string, CompilationParameters) ### Description Compiles OPA bundle from rego policy source code. This method always compiles contents as bundle. ### Method `public static Task CompileSourceAsync(this IRegoCompiler compiler, string source, CompilationParameters parameters)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **source** (string) - Required - Source file path. - **parameters** (CompilationParameters) - Required - Compiler parameters. ### Returns Task - Compiled OPA bundle stream. ### Remarks This method always compiles contents as bundle. ``` ```APIDOC ## CompileSourceAsync(IRegoCompiler, string, CompilationParameters, CancellationToken) ### Description Compiles OPA bundle from rego policy source code. This method always compiles contents as bundle. ### Method `public static Task CompileSourceAsync(this IRegoCompiler compiler, string source, CompilationParameters parameters, CancellationToken cancellationToken)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **source** (string) - Required - Source file path. - **parameters** (CompilationParameters) - Required - Compiler parameters. - **cancellationToken** (CancellationToken) - Required - Cancellation token. ### Returns Task - Compiled OPA bundle stream. ### Remarks This method always compiles contents as bundle. ``` -------------------------------- ### WasmPolicyEngineOptions.ConfigureBuiltins Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Configures the built-in functions for the OPA engine. ```APIDOC ## ConfigureBuiltins(Action) Method ### Description Configure OPA built-ins. ### Parameters `configure` Action ``` -------------------------------- ### OpaToolPath Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Cli.RegoCliCompilerOptions.html Sets the full path to the `opa` executable. This is required if the `opa` tool is not in the system's PATH environment variable. ```csharp public string? OpaToolPath { get; set; } ``` -------------------------------- ### BundleWriter Class Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.html Implements the logic for writing files into an OPA policy bundle. ```APIDOC ## Class BundleWriter ### Description Implements writing files into OPA policy bundle. ``` -------------------------------- ### SigningAlgorithm Property Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.SignatureValidationOptions.html Sets the name of the signing algorithm used for bundle verification. Defaults to "RS256". ```csharp public string SigningAlgorithm { get; init; } ``` -------------------------------- ### ExportResolutionException Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.ExportResolutionException.html Initializes a new instance of the ExportResolutionException with the specified OPA WASM module ABI version and the name of the external that caused the exception. ```csharp public ExportResolutionException(Version abiVersion, string externalName) ``` -------------------------------- ### Create Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.IOpaEvaluatorFactory.html Creates a new OPA evaluator instance. ```APIDOC ## Create() ### Description Creates new OPA evaluator instance ### Method ```csharp IOpaEvaluator Create() ``` ### Returns - IOpaEvaluator: New OPA evaluator instance ``` -------------------------------- ### Compile(Stream, CompilationParameters, CancellationToken) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.IRegoCompiler.html Compiles an OPA bundle from a stream. ```APIDOC ## Compile(Stream, CompilationParameters, CancellationToken) ### Description Compiles OPA bundle from stream. ### Method Task Compile(Stream stream, CompilationParameters parameters, CancellationToken cancellationToken) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Task - Compiled OPA bundle stream. #### Response Example None ``` -------------------------------- ### PrintLn Method Signature Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.IOpaImportsAbi.html Called to emit a message from the policy evaluation. Accepts a single string message. ```csharp void PrintLn(string message) ``` -------------------------------- ### Compile Rego to WASM Source: https://me-viper.github.io/OpaDotNet/articles/evaluation/wasm.html Compile the Rego policy into a WASM binary using the OPA CLI. Ensure the target is 'wasm' and the entrypoint is specified. ```bash opa build -t wasm -e example/hello quickstart/example.rego ``` -------------------------------- ### CompileBundleAsync (string, CompilationParameters, CancellationToken) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a specified path with a cancellation token. ```APIDOC ## CompileBundleAsync ### Description Compiles OPA bundle from rego bundle stream. ### Method `public static Task CompileBundleAsync(this IRegoCompiler compiler, string path, CompilationParameters parameters, CancellationToken cancellationToken)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **path** (string) - Required - Bundle directory or bundle archive path. - **parameters** (CompilationParameters) - Required - Compiler parameters. - **cancellationToken** (CancellationToken) - Required - Cancellation token. #### Returns Task - Compiled OPA bundle stream. #### Remarks This method always compiles contents as bundle. ``` -------------------------------- ### Write Bundle from Byte Span Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleWriter.html Illustrates merging the contents of a source bundle (provided as a Span of bytes) into the current BundleWriter instance. ```csharp public void WriteBundle(Span bundle) ``` -------------------------------- ### Compile OPA Policy Bundle Source: https://me-viper.github.io/OpaDotNet/articles/evaluation/bundle.html Use the OPA CLI to compile local policy and data files into a WebAssembly (WASM) bundle. The `-t wasm` flag specifies the target format, and `-b` indicates a bundle. ```bash opa build -t wasm -b -e example/hello ./quickstart ``` -------------------------------- ### GetCapabilities() Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.ICapabilitiesProvider.html Retrieves a stream containing the capabilities JSON. ```APIDOC ## GetCapabilities() ### Description Returns a stream containing the capabilities JSON. ### Method ```csharp Stream GetCapabilities() ``` ### Returns - **Stream**: Capabilities JSON. ``` -------------------------------- ### CompileFile (Obsolete) - RegoCompilerExtensions Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a Rego policy source file. This method is obsolete and IRegoCompiler.CompileFileAsync should be used instead. ```csharp [Obsolete("Use IRegoCompiler.CompileFileAsync instead")] public static Task CompileFile(this IRegoCompiler compiler, string sourceFilePath, IEnumerable? entrypoints = null, CancellationToken cancellationToken = default) ``` -------------------------------- ### RegoCliCompilerOptions Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Cli.RegoCliCompilerOptions.html Initializes a new instance of the RegoCliCompilerOptions class. ```APIDOC ## RegoCliCompilerOptions() ### Description Initializes a new instance of the RegoCliCompilerOptions class. ### Method Constructor ### Parameters None ``` -------------------------------- ### CompileBundleAsync (string, CompilationParameters) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a specified path. ```APIDOC ## CompileBundleAsync ### Description Compiles OPA bundle from path. ### Method `public static Task CompileBundleAsync(this IRegoCompiler compiler, string path, CompilationParameters parameters)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **path** (string) - Required - Bundle directory or bundle archive path. - **parameters** (CompilationParameters) - Required - Compiler parameters. #### Returns Task - Compiled OPA bundle stream. #### Remarks This method always compiles contents as bundle. ``` -------------------------------- ### BundleManifest Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleManifest.html Default constructor for the BundleManifest record. ```csharp public BundleManifest() ``` -------------------------------- ### Compile Rego Policy using opa build CLI Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Use the opa build CLI tool to compile a Rego file into a WASM module. ```bash opa build -t wasm -e example/hello example.rego ``` -------------------------------- ### Create WasmPolicyEngineOptions Instance Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Instantiates a new WasmPolicyEngineOptions object. This is the default constructor. ```csharp public WasmPolicyEngineOptions() ``` -------------------------------- ### RegoCliCompilerOptions Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Cli.RegoCliCompilerOptions.html Initializes a new instance of the RegoCliCompilerOptions class. ```csharp public RegoCliCompilerOptions() ``` -------------------------------- ### Evaluate OPA Bundle with .NET Source: https://me-viper.github.io/OpaDotNet/articles/evaluation/bundle.html Create an OpaBundleEvaluator from a compiled bundle file and evaluate policy queries. The evaluator is created using a factory method that reads the bundle from a stream. ```csharp // Create evaluator from compiled policy module. using var engine = OpaBundleEvaluatorFactory.Create(File.OpenRead("data/bundle.tar.gz")); // External data is in the bundle already. // Evaluate. Policy query will return false. var deny = engine.EvaluatePredicate(new { message = "hi" }); if (deny.Result) { // Should not get here. } else { // Wrong password. } // Evaluate. Policy query will return true. var approve = engine.EvaluatePredicate(new { message = "world" }); if (approve.Result) { // Correct password. } else { // Should not get here. } ``` -------------------------------- ### IOpaCustomBuiltins Interface Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.Builtins.html Custom OPA built-ins interface. Implementing this interface allows you to define and provide custom built-in functions that can be called from OPA policies. ```APIDOC ## Interface: IOpaCustomBuiltins ### Description Custom OPA built-ins. ### Usage Implement this interface in your .NET classes to create custom built-in functions that can be exposed to OPA policies. ``` -------------------------------- ### CompileStream Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles OPA bundle from rego bundle stream. This method is obsolete and CompileBundleAsync should be used instead. ```APIDOC ## CompileStream(IRegoCompiler, Stream, IEnumerable?, Stream?, CancellationToken) ### Description Compiles OPA bundle from rego bundle stream. ### Method `[Obsolete("Use IRegoCompiler.CompileBundleAsync instead")] public static Task CompileStream(this IRegoCompiler compiler, Stream bundle, IEnumerable? entrypoints = null, Stream? capabilitiesJson = null, CancellationToken cancellationToken = default)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **bundle** (Stream) - Required - Rego bundle stream. - **entrypoints** (IEnumerable) - Optional - Which documents (entrypoints) will be queried when asking for policy decisions. - **capabilitiesJson** (Stream) - Optional - Capabilities json that defines the built-in functions and other language features that policies may depend on. - **cancellationToken** (CancellationToken) - Optional - Cancellation token. ### Returns Task - Compiled OPA bundle stream. ``` -------------------------------- ### WasmPolicyEngineOptions Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Creates a new instance of WasmPolicyEngineOptions with default settings. ```APIDOC ## WasmPolicyEngineOptions() ### Description Creates new WasmPolicyEngineOptions instance. ### Method ```csharp public WasmPolicyEngineOptions() ``` ``` -------------------------------- ### WasmBuiltinsOptions Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmBuiltinsOptions.html Initializes a new instance of the WasmBuiltinsOptions class. ```APIDOC ## WasmBuiltinsOptions() ### Description Initializes a new instance of the WasmBuiltinsOptions class. ### Method Constructor ### Parameters None ``` -------------------------------- ### CompileBundle (Obsolete) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a specified directory. This method is obsolete and CompileBundleAsync should be used instead. ```APIDOC ## CompileBundle ### Description Compiles OPA bundle from bundle directory. ### Method `public static Task CompileBundle(this IRegoCompiler compiler, string bundlePath, IEnumerable? entrypoints = null, string? capabilitiesFilePath = null, CancellationToken cancellationToken = default)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **bundlePath** (string) - Required - Bundle directory or bundle archive path. - **entrypoints** (IEnumerable?) - Optional - Which documents (entrypoints) will be queried when asking for policy decisions. - **capabilitiesFilePath** (string?) - Optional - Capabilities file that defines the built-in functions and other language features that policies may depend on. - **cancellationToken** (CancellationToken) - Optional - Cancellation token. #### Returns Task - Compiled OPA bundle stream. ``` -------------------------------- ### Func Method Signature (3 Arguments) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.IOpaImportsAbi.html Dispatches a built-in function with three arguments. Accepts a BuiltinContext and three BuiltinArg objects. ```csharp object? Func(BuiltinContext context, BuiltinArg arg1, BuiltinArg arg2, BuiltinArg arg3) ``` -------------------------------- ### RegoCompilationException Constructor with Source File and Message Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilationException.html Initializes a new instance of RegoCompilationException with a source file name and an error message. This is useful for pinpointing the exact file that caused the compilation error. ```csharp public RegoCompilationException(string sourceFile, string? message) ``` -------------------------------- ### Now Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.DefaultOpaImportsAbi.html Allows overriding the default logic for retrieving the current UTC date and time. Returns a DateTimeOffset. ```csharp protected virtual DateTimeOffset Now() ``` -------------------------------- ### RegoCompilerVersion ToString Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerVersion.html Returns a string representation of the RegoCompilerVersion object. ```csharp public override string ToString() ``` -------------------------------- ### CompileBundle (Obsolete) - RegoCompilerExtensions Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a specified directory. This method is obsolete and IRegoCompiler.CompileBundleAsync should be used instead. ```csharp [Obsolete("Use IRegoCompiler.CompileBundleAsync instead")] public static Task CompileBundle(this IRegoCompiler compiler, string bundlePath, IEnumerable? entrypoints = null, string? capabilitiesFilePath = null, CancellationToken cancellationToken = default) ``` -------------------------------- ### Compile OPA Bundle from Stream Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Compiles an OPA bundle from a provided stream. This method is suitable when the OPA policy is available in memory. ```csharp public Task Compile(Stream stream, CompilationParameters parameters, CancellationToken cancellationToken) ``` -------------------------------- ### Load Compiled Policy and Set Data Source: https://me-viper.github.io/OpaDotNet/articles/HowToStart.html Instantiate an OPA evaluator from a WASM file and set JSON data for policy evaluation. ```csharp const string data = "{ \"world\": \"world\" }"; using var engine = OpaWasmEvaluatorFactory.Create( File.OpenRead("data/policy.wasm") ); engine.SetDataFromRawJson(data); ``` -------------------------------- ### WasmBuiltinsOptions Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmBuiltinsOptions.html Initializes a new instance of the WasmBuiltinsOptions class. ```csharp public WasmBuiltinsOptions() ``` -------------------------------- ### Compile from Stream Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Interop.RegoInteropCompiler.html Compiles an OPA bundle from a given stream. This method takes the source stream, compilation parameters, and a cancellation token. ```APIDOC ## Compile(Stream stream, CompilationParameters parameters, CancellationToken cancellationToken) ### Description Compiles OPA bundle from stream. ### Parameters #### Parameters - **stream** (Stream) - Source stream. - **parameters** (CompilationParameters) - Compilation parameters. - **cancellationToken** (CancellationToken) - Cancellation token. ### Returns Task - Compiled OPA bundle stream. ``` -------------------------------- ### Print Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.Builtins.IOpaCustomPrinter.html Called to emit messages from the policy evaluation. ```APIDOC ## Print(IEnumerable args) ### Description Called to emit messages from the policy evaluation. ### Method void Print(IEnumerable args) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### WasmPolicyEngineOptions.DefaultWithJsonOptions Method Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.WasmPolicyEngineOptions.html Creates default engine options with custom JSON serialization settings. ```APIDOC ## DefaultWithJsonOptions(Action) Method ### Description Creates default engine options. ### Parameters `options` Action JSON serialization options. ### Returns WasmPolicyEngineOptions Engine options. ``` -------------------------------- ### CompileBundleAsync (Stream, CompilationParameters, CancellationToken) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a stream of Rego bundle content with a cancellation token. ```APIDOC ## CompileBundleAsync ### Description Compiles OPA bundle from rego bundle stream. ### Method `public static Task CompileBundleAsync(this IRegoCompiler compiler, Stream bundle, CompilationParameters parameters, CancellationToken cancellationToken)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **bundle** (Stream) - Required - Rego bundle stream. - **parameters** (CompilationParameters) - Required - Compiler parameters. - **cancellationToken** (CancellationToken) - Required - Cancellation token. #### Returns Task - Compiled OPA bundle stream. #### Remarks This method always compiles contents as bundle. ``` -------------------------------- ### OpaCustomBuiltinAttribute Constructor Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Wasm.Builtins.OpaCustomBuiltinAttribute.html The constructor for OpaCustomBuiltinAttribute takes a string argument for the built-in name. This allows you to specify the name under which the custom built-in will be available in OPA policies. ```csharp public OpaCustomBuiltinAttribute(string name) ``` -------------------------------- ### CompileBundleAsync (Stream, CompilationParameters) Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.RegoCompilerExtensions.html Compiles an OPA bundle from a stream of Rego bundle content. ```APIDOC ## CompileBundleAsync ### Description Compiles OPA bundle from rego bundle stream. ### Method `public static Task CompileBundleAsync(this IRegoCompiler compiler, Stream bundle, CompilationParameters parameters)` ### Parameters #### Path Parameters - **compiler** (IRegoCompiler) - Required - Compiler instance. - **bundle** (Stream) - Required - Rego bundle stream. - **parameters** (CompilationParameters) - Required - Compiler parameters. #### Returns Task - Compiled OPA bundle stream. #### Remarks This method always compiles contents as bundle. ``` -------------------------------- ### BundleManifest Constructors Source: https://me-viper.github.io/OpaDotNet/api/OpaDotNet.Compilation.Abstractions.BundleManifest.html Provides constructors for creating BundleManifest objects. ```APIDOC ## BundleManifest() ### Description Initializes a new instance of the BundleManifest class. ### Method public BundleManifest() ``` ```APIDOC ## BundleManifest(BundleManifest) ### Description Initializes a new instance of the BundleManifest class with a copy of an existing instance. ### Method protected BundleManifest(BundleManifest original) ### Parameters - **original** (BundleManifest) - The BundleManifest instance to copy. ```