{"id":16118947,"url":"https://github.com/cch0/opa-wasm-examples","last_synced_at":"2026-01-21T10:01:42.064Z","repository":{"id":233487662,"uuid":"657815152","full_name":"cch0/opa-wasm-examples","owner":"cch0","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-24T16:45:34.000Z","size":196,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T09:51:50.554Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Open Policy Agent","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cch0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-23T23:29:31.000Z","updated_at":"2023-06-23T23:42:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"36336aef-d969-4a3f-84ef-54387e657fc2","html_url":"https://github.com/cch0/opa-wasm-examples","commit_stats":null,"previous_names":["cch0/opa-wasm-examples"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cch0/opa-wasm-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch0%2Fopa-wasm-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch0%2Fopa-wasm-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch0%2Fopa-wasm-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch0%2Fopa-wasm-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cch0","download_url":"https://codeload.github.com/cch0/opa-wasm-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch0%2Fopa-wasm-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28631936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-10-09T20:51:43.500Z","updated_at":"2026-01-21T10:01:42.034Z","avatar_url":"https://github.com/cch0.png","language":"Open Policy Agent","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OPA WebAssembly Examples For OPA Policy Evaluation\n\nA collection of examples which demonstrates how to evaluate against the same policy [policy.wasm](./config/policy.wasm) using different programming languages. The policy is expected to be written in Rego and compiled by WebAssembly.\n\nThe OPA policy file included here is an example of Rego policy for evaluating PDU packets.\n\n[opa_input.json](./config/opa_input.json) contains an example of PDU packet and [data.json](./config/data.json) contains the rules configuration parameters.\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n## Java Example\n\nExecute the `com.kdf.Main` class inside the java directory. The `pom.xml` file specifies the version of `wasmtime-java` dependency which only exists in a private Maven repository.\n\n```\n2023-06-23 14:13:26 INFO - main - Main:33 - evaluation result: [{\"result\":{\"rule\":\"C\",\"label\":\"UNRESTRICTED\"}}]\n2023-06-23 14:13:26 INFO - main - Main:36 - rule: \"C\", label: \"UNRESTRICTED\"\n```\n\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n## Python Example\n\n- Following the instruction on [wasmer-python](https://github.com/wasmerio/wasmer-python) to install `wasmer`. The reason for this step is that python package might not be available for you OS and architecture.\n- `pip install opa-wasm[cranelift]` or `pip install \"opa-wasm[cranelift]\"` if you are a `zsh` user, \n\n\n\n\n\nExecute the command\n\n```\ncd python\n\npython3 example.py\n```\n\n\u003c/br\u003e\nOutput:\n\n```\n[{'result': {'rule': 'C', 'label': 'UNRESTRICTED'}}]\n```\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n## Nodejs Example\n\n\n\n```\ncd nodejs\n\nnpm install\n\nnode example.js\n```\n\n\u003c/br\u003e\nOutput:\n\n```\nresultSet is  [ { result: { rule: 'C', label: 'UNRESTRICTED' } } ]\nlabel =  UNRESTRICTED\nrule =  C\n```\n\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n## OPA Eval Command Line Example\n\n```\nopa eval -d config/data.json -d config/example.rego  -i config/opa_input.json -e example/label_to_use  -f pretty  data.example.label_to_use\n```\n\nOutput:\n\n```\n{\n  \"label\": \"UNRESTRICTED\",\n  \"rule\": \"C\"\n}\n```\n\n\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n## OPA Server Docker Example\n\nCompared to [opa_input.json](./config/opa_input.json) file, [input.json](./config/input.json) file add the content of `opa_input.json` file as the value field with key `input` in the `input.json` file, i.e.\n\n```\n{\n    \"input\": { ... content from opa_input.json }\n}\n```\n\n\u003c/br\u003e\n\nExecute the command to start up OPA Server\n\n```\ndocker run -it -v $PWD/config/data.json:/config/data.json -v $PWD/config/example.rego:/config/example.rego  -p 8181:8181  openpolicyagent/opa:0.54.0-dev-static-debug run --server --addr :8181 /config\n```\n\n\u003c/br\u003e\n\n\nExecute the `curl` command\n\n```\ncurl -d @./config/input.json http://localhost:8181/v1/data/example/label_to_use\n```\n\n\u003c/br\u003e\n\nOutput:\n```\n{\"result\":{\"label\":\"UNRESTRICTED\",\"rule\":\"C\"}}\n```\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n## OPA Server Local Example\n\nExecute the command to start up OPA Server\n\n```\nopa run config/data.json config/example.rego -s --addr localhost:8181\n```\n\n\u003c/br\u003e\n\nExecute the `curl` command\n\n```\ncurl -d @./config/input.json http://localhost:8181/v1/data/example/label_to_use\n```\n\n\u003c/br\u003e\n\nOutput:\n```\n{\"result\":{\"label\":\"UNRESTRICTED\",\"rule\":\"C\"}}\n```\n\n\n\u003c/br\u003e\n\u003c/br\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcch0%2Fopa-wasm-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcch0%2Fopa-wasm-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcch0%2Fopa-wasm-examples/lists"}