Files
regorus/bindings/java
Anand Krishnamoorthi de56cce7cb Fix anyhow dependency issues (#208)
- Do not require backtrace feature
- Starting version 1.0.77, anyhow gathers backtrace is std feature (enabled by default)
  is specified even if backtrace feature is not enabled.
  Therefore specify default features as false.
- Specify version 1.0.45 since that is the minimul version required to successfully
  compile regorus

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2024-04-20 09:57:52 -07:00
..
2024-02-22 15:00:07 -08:00
2024-02-22 15:00:07 -08:00
2024-02-18 08:21:58 -08:00
2024-04-20 09:57:52 -07:00
2024-02-22 21:18:49 -08:00
2024-02-22 15:00:07 -08:00
2024-02-22 15:00:07 -08:00

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.

Usage

Regorus Java is published to Maven Central with native libraries for the following:

  • 64-bit Linux (kernel 3.2+, glibc 2.17+)
  • ARM64 Linux (kernel 4.1, glibc 2.17+)
  • 64-bit macOS (10.12+, Sierra+)
  • ARM64 macOS (11.0+, Big Sur+)
  • 64-bit MSVC (Windows 7+)

If you need to run it in a different OS or an architecture you need to manually build it.

If you're on one of the supported platforms, you can just pull prebuilt JAR from Maven Central by declaring a dependency on com.microsoft.regorus:regorus-java.

With Maven:

<dependencies>
    <dependency>
        <groupId>com.microsoft.regorus</groupId>
        <artifactId>regorus-java</artifactId>
        <version>0.0.1</version>
    </dependency>
</dependencies>

With Gradle:

// build.gradle.kts
implementation("com.microsoft.regorus:regorus-java:0.0.1")

Afterwards you can use it as follows:

import com.microsoft.regorus.Engine;

public class Test {
    public static void main(String[] args) {
        try (Engine engine = new Engine()) {
            engine.addPolicy(
                "hello.rego",
                "package test\nmessage = concat(\", \", [input.message, data.message])"
            );
            engine.addDataJson("{\"message\":\"World!\"}");
            engine.setInputJson("{\"message\":\"Hello\"}");
            String resJson = engine.evalQuery("data.test.message");

            System.out.println(resJson);
        }
    }
}

And you can see the following output once you run it:

{"result":[{"expressions":[{"value":"Hello, World!","text":"data.test.message","location":{"row":1,"col":1}}]}]}

Building

In order to build Regorus Java for a target platform, you need to install Rust target for that target platform first:

$ rustup target add aarch64-apple-darwin

Afterwards, you can build native library for that target using:

$ cargo build --release --target aarch64-apple-darwin

You will then have a native library at ../../target/aarch64-apple-darwin/release/libregorus_java.dylib depending on your target.

You can then build a JAR from source using:

$ mvn package

And you will have a JAR at ./target/regorus-java-0.0.1.jar.

You need to make sure both of the artifacts in Java's classpath. For example with java CLI:

$ java -Djava.library.path=../../target/aarch64-apple-darwin/release/ -cp target/regorus-java-0.0.1.jar Test.java