{"id":13787937,"url":"https://github.com/matrix-org/rust-opa-wasm","last_synced_at":"2025-04-04T17:04:50.037Z","repository":{"id":39573265,"uuid":"498392105","full_name":"matrix-org/rust-opa-wasm","owner":"matrix-org","description":"Open Policy Agent WebAssembly Rust SDK","archived":false,"fork":false,"pushed_at":"2025-03-20T15:52:31.000Z","size":507,"stargazers_count":56,"open_issues_count":12,"forks_count":13,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-28T16:10:02.837Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matrix-org.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-31T15:25:59.000Z","updated_at":"2025-03-18T04:32:02.000Z","dependencies_parsed_at":"2023-02-15T17:46:18.585Z","dependency_job_id":"c4d2a1d7-9fdb-456e-8593-91640cc6715b","html_url":"https://github.com/matrix-org/rust-opa-wasm","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrix-org%2Frust-opa-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrix-org%2Frust-opa-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrix-org%2Frust-opa-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrix-org%2Frust-opa-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matrix-org","download_url":"https://codeload.github.com/matrix-org/rust-opa-wasm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217172,"owners_count":20903008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T21:00:33.538Z","updated_at":"2025-04-04T17:04:50.020Z","avatar_url":"https://github.com/matrix-org.png","language":"Rust","funding_links":[],"categories":["WebAssembly (Wasm)"],"sub_categories":["Typescript"],"readme":"# Rust Open Policy Agent SDK\n\nA crate to use OPA policies compiled to WASM.\n\n## Try it out\n\nThis includes a CLI tool to try out the SDK implementation.\n\n```text\ncargo run --features=cli --      \\\n    --module ./policy.wasm       \\\n    --data-path ./data.json      \\\n    --input '{\"hello\": \"world\"}' \\\n    --entrypoint 'hello/world'\n```\n\nSet the `RUST_LOG` environment variable to `info` to show timings informations about the execution.\n\n```text\nopa-wasm\nEvaluates OPA policies compiled as WASM modules\n\nUSAGE:\n    opa-eval [OPTIONS] --entrypoint \u003cENTRYPOINT\u003e \u003c--module \u003cMODULE\u003e|--bundle \u003cBUNDLE\u003e\u003e\n\nOPTIONS:\n    -m, --module \u003cMODULE\u003e            Path to the WASM module\n    -b, --bundle \u003cBUNDLE\u003e            Path to the OPA bundle\n    -e, --entrypoint \u003cENTRYPOINT\u003e    Entrypoint to use\n    -d, --data \u003cJSON\u003e                JSON literal to use as data\n    -D, --data-path \u003cPATH\u003e           Path to a JSON file to load as data\n    -i, --input \u003cJSON\u003e               JSON literal to use as input\n    -I, --input-path \u003cPATH\u003e          Path to a JSON file to load as data\n    -h, --help                       Print help information\n```\n\n## As a library\n\n```rust,no_run\nuse std::collections::HashMap;\n\nuse anyhow::Result;\n\nuse opa_wasm::{wasmtime, Runtime};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c()\u003e {\n    // Configure the WASM runtime\n    let mut config = wasmtime::Config::new();\n    config.async_support(true);\n\n    let engine = wasmtime::Engine::new(\u0026config)?;\n\n    // Load the policy WASM module\n    let module = tokio::fs::read(\"./policy.wasm\").await?;\n    let module = wasmtime::Module::new(\u0026engine, module)?;\n\n    // Create a store which will hold the module instance\n    let mut store = wasmtime::Store::new(\u0026engine, ());\n\n    let data = HashMap::from([(\"hello\", \"world\")]);\n    let input = HashMap::from([(\"message\", \"world\")]);\n\n    // Instantiate the module\n    let runtime = Runtime::new(\u0026mut store, \u0026module).await?;\n\n    let policy = runtime.with_data(\u0026mut store, \u0026data).await?;\n\n    // Evaluate the policy\n    let res: serde_json::Value = policy.evaluate(\u0026mut store, \"hello/world\", \u0026input).await?;\n\n    println!(\"{}\", res);\n\n    Ok(())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrix-org%2Frust-opa-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatrix-org%2Frust-opa-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrix-org%2Frust-opa-wasm/lists"}