Skip to content

Commit

Permalink
changes for Jitpack and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Aug 8, 2024
1 parent 4ca2ab9 commit 802bd92
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
37 changes: 34 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
# Open Policy Agent WebAssemby Java Module
[![CI](https://github.com/andreaTP/opa-chicory/workflows/CI/badge.svg)](https://github.com/andreaTP/opa-chicory)
[![](https://jitpack.io/v/andreaTP/opa-chicory.svg)](https://jitpack.io/#andreaTP/opa-chicory)

TODO: take inspiration by this: https://github.com/me-viper/OpaDotNet the docs are pretty cool!
# Open Policy Agent WebAssemby Java SDK (experimental)

This is SDK for using WebAssembly (wasm) compiled [Open Policy Agent](https://www.openpolicyagent.org/) policies
with [Chicory](https://github.com/dylibso/chicory), a pure Java Wasm interpreter.

Initial implementation was based
on [Open Policy Agent WebAssemby NPM Module](https://github.com/open-policy-agent/npm-opa-wasm)
and [Open Policy Agent Ebassembly dotnet core SDK](https://github.com/me-viper/OpaDotNet)

## Why

We want fast in-process OPA policies evaluations, and avoid network bottlenecks when using [opa-java](https://github.com/StyraInc/opa-java).

# Getting Started

## Install the module

TODO: Jitpack release
With Maven:

```
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```

and:

```
<dependency>
<groupId>com.github.andreaTP.opa-chicory</groupId>
<artifactId>opa-chicory</artifactId>
<version>main-SNAPSHOT</version>
</dependency>
```

## Usage

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/github/andreaTP/opa/chicory/Opa.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public OpaPolicy entrypoint(String entrypoint) {
return this;
}

public int loadJson(String data) {
private int loadJson(String data) {
var dataStrAddr = wasm.opaMalloc(data.length());
wasm.memory().writeCString(dataStrAddr, data);
var dstAddr = wasm.opaJsonParse(dataStrAddr, data.length());
wasm.opaFree(dataStrAddr);
return dstAddr;
}

public String dumpJson(int addr) {
private String dumpJson(int addr) {
int resultStrAddr = wasm.opaJsonDump(addr);
var result = wasm.memory().readCString(resultStrAddr);
wasm.opaFree(resultStrAddr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public void opaEval(
Value.i32(format));
}

// helper functions
// helper functions - can be written by the end user
public String readString(int addr) {
int resultAddr = opaJsonDump(addr);
var resultStr = memory().readCString(resultAddr);
Expand Down
17 changes: 0 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,6 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<doclint>none</doclint>
<source>1.8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down

0 comments on commit 802bd92

Please sign in to comment.