Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sangkeon/java-opa-wasm
https://github.com/sangkeon/java-opa-wasm
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sangkeon/java-opa-wasm
- Owner: sangkeon
- License: apache-2.0
- Created: 2021-03-30T16:22:11.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-10T05:00:07.000Z (9 months ago)
- Last Synced: 2024-08-03T21:01:23.031Z (5 months ago)
- Language: Java
- Size: 364 KB
- Stars: 15
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-opa - JVM - Java SDK for calling Wasm-compiled policies. Uses wasmtime. (WebAssembly (Wasm) / Typescript)
README
# OPA(Open Policy Agent) WebAssembly SDK for Java
## About
OPA(www.openpolicyagent.org) ia a awesome policy engine for Cloud Native Application and Micro Services.This project is a very sample-grade sdk to illustrate how to use wasm compiled rego policy for Java application.
This project uses https://github.com/kawamuray/wasmtime-java for WASM runtime.
Inspired by and, borrowed many ideas+codes from following projects.
- golang-opa-wasm(https://github.com/open-policy-agent/golang-opa-wasm)
- npm-opa-wasm(https://github.com/open-policy-agent/npm-opa-wasm)
- dotnet-opa-wasm(https://github.com/christophwille/dotnet-opa-wasm)Tested under OPA version 0.26.0
## Warning
- Very early stage project and almost sdk independent builtin functions not implemented(just place holder).
-If you are using an Apple Silicon Mac, see [FOR_APPLE_SILICON_USERS.md](./FOR_APPLE_SILICON_USERS.md) first./del>## Usage
### Maven dependency ###
```
io.github.sangkeon
java-opa-wasm
0.2.5
```### To load and evaluate for OPA wasm file
```
try (
OPAModule om = new OPAModule("./sample-policy/wasm/policy.wasm");
) {
String input = "{\"user\": \"john\"}";
String data = "{\"role\":{\"john\":\"admin\"}}";om.setData(data);
String result = om.evaluate(input, "opa/wasm/test/allowed");
System.out.println("result=" + result);
}
```### To load and evaluate for OPA bundle
When using bundle, policy.wasm and data.json inside bundle will be loaded.```
try {
Bundle bundle = BundleUtil.extractBundle("./sample-policy/bundle/bundle.tar.gz");try (
OPAModule om = new OPAModule(bundle);
) {
String input = "{\"user\": \"alice\"}";
String result = om.evaluate(input, "opa/wasm/test/allowed");System.out.println("result=" + result);
}
} catch(Exception e) {
}```