Open Policy Agent WebAssembly Rust SDK
  • Rust 99.9%
  • Makefile 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Quentin Gliech e12f7ea03e
chore: release v0.3.4 (#278)
## 🤖 New release

* `opa-wasm`: 0.3.3 -> 0.3.4 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.3.4](https://github.com/matrix-org/rust-opa-wasm/compare/v0.3.3...v0.3.4)
- 2026-10-27

### Other

- upgrade Clippy to 1.99.1
- *(deps)* update wasmtime requirement from >=42, <50 to >=42, <51
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
2026-10-27 13:30:53 +01:00
.github ci: upgrade Clippy to 1.99.1 2026-10-27 13:16:11 +01:00
src Fix formatting in CI according to cargo fmt 2026-10-06 12:40:44 +01:00
tests build(deps)!: require wasmtime >=42, <44 2026-04-10 09:57:23 +02:00
.gitignore chore: adapt the tests to rego v1 syntax 2025-02-21 14:35:19 +01:00
.rustfmt.toml Adjust rustfmt configuration 2022-06-28 16:05:36 +02:00
Cargo.toml chore: release v0.3.4 2026-10-27 13:22:54 +01:00
CHANGELOG.md chore: release v0.3.4 2026-10-27 13:22:54 +01:00
clippy.toml Disallow most panics 2024-07-01 11:48:06 +02:00
CONTRIBUTING.md Add contributing guidelines 2022-08-02 10:35:50 +02:00
features.txt Simplify time builtins parameters 2022-12-06 10:43:34 +01:00
LICENSE initial commit 2022-05-31 17:24:09 +02:00
Makefile chore: adapt the tests to rego v1 syntax 2025-02-21 14:35:19 +01:00
README.md Update the README to use the reexported wasmtime 2024-07-01 09:06:11 +02:00

Rust Open Policy Agent SDK

A crate to use OPA policies compiled to WASM.

Try it out

This includes a CLI tool to try out the SDK implementation.

cargo run --features=cli --      \
    --module ./policy.wasm       \
    --data-path ./data.json      \
    --input '{"hello": "world"}' \
    --entrypoint 'hello/world'

Set the RUST_LOG environment variable to info to show timings informations about the execution.

opa-wasm
Evaluates OPA policies compiled as WASM modules

USAGE:
    opa-eval [OPTIONS] --entrypoint <ENTRYPOINT> <--module <MODULE>|--bundle <BUNDLE>>

OPTIONS:
    -m, --module <MODULE>            Path to the WASM module
    -b, --bundle <BUNDLE>            Path to the OPA bundle
    -e, --entrypoint <ENTRYPOINT>    Entrypoint to use
    -d, --data <JSON>                JSON literal to use as data
    -D, --data-path <PATH>           Path to a JSON file to load as data
    -i, --input <JSON>               JSON literal to use as input
    -I, --input-path <PATH>          Path to a JSON file to load as data
    -h, --help                       Print help information

As a library

use std::collections::HashMap;

use anyhow::Result;

use opa_wasm::{wasmtime, Runtime};

#[tokio::main]
async fn main() -> Result<()> {
    // Configure the WASM runtime
    let mut config = wasmtime::Config::new();
    config.async_support(true);

    let engine = wasmtime::Engine::new(&config)?;

    // Load the policy WASM module
    let module = tokio::fs::read("./policy.wasm").await?;
    let module = wasmtime::Module::new(&engine, module)?;

    // Create a store which will hold the module instance
    let mut store = wasmtime::Store::new(&engine, ());

    let data = HashMap::from([("hello", "world")]);
    let input = HashMap::from([("message", "world")]);

    // Instantiate the module
    let runtime = Runtime::new(&mut store, &module).await?;

    let policy = runtime.with_data(&mut store, &data).await?;

    // Evaluate the policy
    let res: serde_json::Value = policy.evaluate(&mut store, "hello/world", &input).await?;

    println!("{}", res);

    Ok(())
}