mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
1.6 KiB
1.6 KiB
Regorus Java
Regorus is
- Rego-Rus(t) - A fast, light-weight Rego interpreter written in Rust.
- Rigorous - A rigorous enforcer of well-defined Rego semantics.
See main Regorus page for more details about the project.
Regorus can be used in Java via com.microsoft.regorus package. (It is not yet available in Maven Central, but can be manually built.)
Building
You can build this binding using Maven:
$ mvn package
$ file target/regorus-java-0.0.1*
target/regorus-java-0.0.1-osx-aarch_64.jar: Zip archive data, at least v1.0 to extract, compression method=deflate
target/regorus-java-0.0.1.jar: Zip archive data, at least v1.0 to extract, compression method=deflate
Usage
import com.microsoft.regorus.Engine;
public class Test {
public static void main(String[] args) {
try (Engine engine = new Engine()) {
engine.pubAddPolicy(
"hello.rego",
"package test\nmessage = concat(\", \", [input.message, data.message])"
);
engine.pubAddDataJson("{\"message\":\"World!\"}");
engine.pubSetInputJson("{\"message\":\"Hello\"}");
String resJson = engine.pubEvalQuery("data.test.message");
System.out.println(resJson);
}
}
}
and run it with:
$ java -cp target/regorus-java-0.0.1.jar:target/regorus-java-0.0.1-osx-aarch_64.jar Test.java
{"result":[{"expressions":[{"value":"Hello, World!","text":"data.test.message","location":{"row":1,"col":1}}]}]}