OPA SDKs
You can quickly connect an application to Enterprise OPA or Open Policy Agent (OPA) using the following SDKs.
These are developed and supported by Styra:
Language | Repo | Docs | Package |
---|---|---|---|
Java | StyraInc/opa-java | styrainc.github.io/opa-java | |
TypeScript | StyraInc/opa-typescript | styrainc.github.io/opa-typescript | @styra/opa |
C# | StyraInc/opa-csharp | styrainc.github.io/opa-csharp | Styra |
Getting Started
- TypeScript
- Java
- C#
npm:
npm add @styra/opa
Yarn:
yarn add @styra/opa
Gradle:
implementation 'com.styra.opa:api:0.4.2'
Maven:
<dependency>
<groupId>com.styra.opa</groupId>
<artifactId>api</artifactId>
<version>0.4.2</version>
</dependency>
Nuget:
dotnet add package Styra
Code Examples
- TypeScript
- Java
- C#
import { OPAClient } from "@styra/opa";
const serverURL = "http://opa-host:8181";
const opa = new OPAClient(serverURL);
const path = "authz/allow";
const input = {
subject: "alice",
action: "read",
resource: "/finance/reports/fy2038_budget.csv"
};
const result = await opa.evaluate(path, input);
console.log(result ? "allowed" : "denied");
String opaURL = "http://opa-host:8181";
OPA opa = new OPA(opaURL);
java.util.Map<String,Object> input = java.util.Map.ofEntries(
entry("subject", "alice"),
entry("action", "read"),
entry("resource", "/finance/reports/fy2038_budget.csv")
);
allowed = opa.check(input, "authz/allow");
System.out.println("allowed: " + allowed);
// TODO
Support
Got suggestions or need help? We're here! Please reach out to us on the Styra Community Slack.