Skip to content

Commit

Permalink
make path optional (#45)
Browse files Browse the repository at this point in the history
This makes the `path` parameter optional by supporting OPA's "default decision". 

---------

Co-authored-by: Stephan Renatus <stephan@styra.com>
  • Loading branch information
charlesdaniels and srenatus authored May 23, 2024
1 parent ad63a5f commit 0ef5d04
Show file tree
Hide file tree
Showing 24 changed files with 1,431 additions and 174 deletions.
29 changes: 17 additions & 12 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
lockVersion: 2.0.0
id: 47e8e950-a454-4ebb-9f78-86fda7dfa0c2
management:
docChecksum: 2422daf10293e923232daf08349ae0ae
docChecksum: 11b8c1e1d3f9d5dab18c36b33f81200d
docVersion: 0.2.0
speakeasyVersion: 1.285.1
generationVersion: 2.326.3
releaseVersion: 0.7.0
configChecksum: fce52343a81a573dd9118e4fd849279d
speakeasyVersion: 1.292.0
generationVersion: 2.332.4
releaseVersion: 0.7.11
configChecksum: afb2823abec96aebcd7561ecf8e1ffc1
repoURL: https://github.com/StyraInc/opa-java.git
published: true
features:
java:
additionalDependencies: 0.1.0
constsAndDefaults: 0.1.1
core: 3.19.5
core: 3.19.7
examples: 2.81.3
flattening: 2.81.1
globalSecurityCallbacks: 0.1.0
Expand All @@ -24,6 +24,7 @@ generatedFiles:
- src/main/java/com/styra/opa/openapi/SecuritySource.java
- src/main/java/com/styra/opa/openapi/models/shared/Security.java
- src/main/java/com/styra/opa/openapi/SDKConfiguration.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequestBuilder.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequestBuilder.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBuilder.java
- src/main/java/com/styra/opa/openapi/models/operations/HealthRequestBuilder.java
Expand Down Expand Up @@ -69,20 +70,22 @@ generatedFiles:
- src/main/java/com/styra/opa/openapi/utils/Types.java
- src/main/java/com/styra/opa/openapi/utils/Utils.java
- src/main/java/com/styra/opa/openapi/models/errors/SDKError.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequest.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputResponse.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequest.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyResponse.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBody.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequest.java
- src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputResponse.java
- src/main/java/com/styra/opa/openapi/models/operations/HealthRequest.java
- src/main/java/com/styra/opa/openapi/models/operations/HealthResponse.java
- src/main/java/com/styra/opa/openapi/models/shared/Result.java
- src/main/java/com/styra/opa/openapi/models/shared/Input.java
- src/main/java/com/styra/opa/openapi/models/shared/GzipAcceptEncoding.java
- src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyEvaluation.java
- src/main/java/com/styra/opa/openapi/models/shared/Revision.java
- src/main/java/com/styra/opa/openapi/models/shared/Provenance.java
- src/main/java/com/styra/opa/openapi/models/shared/Result.java
- src/main/java/com/styra/opa/openapi/models/shared/Explain.java
- src/main/java/com/styra/opa/openapi/models/shared/GzipAcceptEncoding.java
- src/main/java/com/styra/opa/openapi/models/shared/Input.java
- src/main/java/com/styra/opa/openapi/models/shared/GzipContentEncoding.java
- src/main/java/com/styra/opa/openapi/models/shared/HealthyServer.java
- src/main/java/com/styra/opa/openapi/models/errors/Location.java
Expand All @@ -92,20 +95,22 @@ generatedFiles:
- src/main/java/com/styra/opa/openapi/models/errors/ServerErrorErrors.java
- src/main/java/com/styra/opa/openapi/models/errors/ServerError.java
- src/main/java/com/styra/opa/openapi/models/errors/UnhealthyServer.java
- docs/models/operations/ExecuteDefaultPolicyWithInputRequest.md
- docs/models/operations/ExecuteDefaultPolicyWithInputResponse.md
- docs/models/operations/ExecutePolicyRequest.md
- docs/models/operations/ExecutePolicyResponse.md
- docs/models/operations/ExecutePolicyWithInputRequestBody.md
- docs/models/operations/ExecutePolicyWithInputRequest.md
- docs/models/operations/ExecutePolicyWithInputResponse.md
- docs/models/operations/HealthRequest.md
- docs/models/operations/HealthResponse.md
- docs/models/shared/Result.md
- docs/models/shared/Input.md
- docs/models/shared/GzipAcceptEncoding.md
- docs/models/shared/SuccessfulPolicyEvaluation.md
- docs/models/shared/Revision.md
- docs/models/shared/Provenance.md
- docs/models/shared/Result.md
- docs/models/shared/Explain.md
- docs/models/shared/GzipAcceptEncoding.md
- docs/models/shared/Input.md
- docs/models/shared/GzipContentEncoding.md
- docs/models/shared/HealthyServer.md
- docs/models/errors/Location.md
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
java:
version: 0.7.0
version: 0.7.11
additionalDependencies: []
artifactID: openapi
clientServerStatusCodesAsErrors: true
Expand Down
13 changes: 6 additions & 7 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
speakeasyVersion: 1.285.1
speakeasyVersion: 1.292.0
sources:
openapi:
sourceNamespace: openapi
sourceRevisionDigest: sha256:1fe5f3fb1c57f2d35c00da97557e640e137ea14101c331751e6623ca3995933b
sourceBlobDigest: sha256:7ed70a976b193a4bfa6810f76003acbae70adbe5b0c65fb87838bf8afa031caf
sourceRevisionDigest: sha256:d7ce2b47fb37c8a57ff572bdf2f673093c4b6226ba8af77e38e8ad7f1b5cd113
sourceBlobDigest: sha256:153fe8e766cf694a916b1f96bf93d9d337eb2d5ff636ca6427fa24077b2b64a6
tags:
- latest
- main
targets:
opa:
source: openapi
sourceNamespace: openapi
sourceRevisionDigest: sha256:1fe5f3fb1c57f2d35c00da97557e640e137ea14101c331751e6623ca3995933b
sourceBlobDigest: sha256:7ed70a976b193a4bfa6810f76003acbae70adbe5b0c65fb87838bf8afa031caf
outLocation: /github/workspace/repo
sourceRevisionDigest: sha256:d7ce2b47fb37c8a57ff572bdf2f673093c4b6226ba8af77e38e8ad7f1b5cd113
sourceBlobDigest: sha256:153fe8e766cf694a916b1f96bf93d9d337eb2d5ff636ca6427fa24077b2b64a6
outLocation: /home/cad-styra/f/src/opa-java
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ speakeasyVersion: latest
sources:
openapi:
inputs:
- location: https://raw.githubusercontent.com/StyraInc/enterprise-opa/main/openapi/openapi.yaml
- location: https://raw.githubusercontent.com/StyraInc/enterprise-opa/main/openapi/openapi.yaml
registry:
location: registry.speakeasyapi.dev/styra/styra/openapi
targets:
Expand Down
92 changes: 68 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Maven Central Version](https://img.shields.io/maven-central/v/com.styra/opa?label=Maven%20Central&logo=apache-maven&color=%2324b6e0)](https://central.sonatype.com/artifact/com.styra/opa)

> [!IMPORTANT]
> The documentation for this SDK lives at https://docs.styra.com/sdk, with reference documentation available at https://styrainc.github.io/opa-java
> The documentation for this SDK lives at https://docs.styra.com/sdk, with reference documentation available at https://styrainc.github.io/opa-java/javadoc
You can use the Styra OPA SDK to connect to [Open Policy Agent](https://www.openpolicyagent.org/) and [Enterprise OPA](https://www.styra.com/enterprise-opa/) deployments.

Expand Down Expand Up @@ -87,7 +87,56 @@ public class App {
<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage

### Example
### Example 1

```java
package hello.world;

import com.styra.opa.openapi.OpaApiClient;
import com.styra.opa.openapi.models.operations.*;
import com.styra.opa.openapi.models.shared.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

public static void main(String[] args) throws Exception {
try {
OpaApiClient sdk = OpaApiClient.builder()
.build();

ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput()
.pretty(false)
.acceptEncoding(GzipAcceptEncoding.GZIP)
.input(Input.of(8203.11d))
.call();

if (res.result().isPresent()) {
// handle response
}
} catch (com.styra.opa.openapi.models.errors.ClientError e) {
// handle exception
throw e;
} catch (com.styra.opa.openapi.models.errors.ServerError e) {
// handle exception
throw e;
} catch (com.styra.opa.openapi.models.errors.SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
```

### Example 2

```java
package hello.world;
Expand Down Expand Up @@ -147,6 +196,7 @@ public class Application {

### [OpaApiClient SDK](docs/sdks/opaapiclient/README.md)

* [executeDefaultPolicyWithInput](docs/sdks/opaapiclient/README.md#executedefaultpolicywithinput) - Execute the default decision given an input
* [executePolicy](docs/sdks/opaapiclient/README.md#executepolicy) - Execute a policy
* [executePolicyWithInput](docs/sdks/opaapiclient/README.md#executepolicywithinput) - Execute a policy given an input
* [health](docs/sdks/opaapiclient/README.md#health) - Verify the server is operational
Expand Down Expand Up @@ -187,15 +237,13 @@ public class Application {
.serverIndex(0)
.build();

ExecutePolicyRequest req = ExecutePolicyRequest.builder()
.path("app/rbac")
.build();

ExecutePolicyResponse res = sdk.executePolicy()
.request(req)
ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput()
.pretty(false)
.acceptEncoding(GzipAcceptEncoding.GZIP)
.input(Input.of(8203.11d))
.call();

if (res.successfulPolicyEvaluation().isPresent()) {
if (res.result().isPresent()) {
// handle response
}
} catch (com.styra.opa.openapi.models.errors.ClientError e) {
Expand Down Expand Up @@ -241,15 +289,13 @@ public class Application {
.serverURL("http://localhost:8181")
.build();

ExecutePolicyRequest req = ExecutePolicyRequest.builder()
.path("app/rbac")
.build();

ExecutePolicyResponse res = sdk.executePolicy()
.request(req)
ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput()
.pretty(false)
.acceptEncoding(GzipAcceptEncoding.GZIP)
.input(Input.of(8203.11d))
.call();

if (res.successfulPolicyEvaluation().isPresent()) {
if (res.result().isPresent()) {
// handle response
}
} catch (com.styra.opa.openapi.models.errors.ClientError e) {
Expand Down Expand Up @@ -277,7 +323,7 @@ Handling errors in this SDK should largely match your expectations. All operati

| Error Object | Status Code | Content Type |
| ------------------------- | ------------------------- | ------------------------- |
| models/errors/ClientError | 400 | application/json |
| models/errors/ClientError | 400,404 | application/json |
| models/errors/ServerError | 500 | application/json |
| models/errors/SDKError | 4xx-5xx | */* |

Expand All @@ -304,15 +350,13 @@ public class Application {
OpaApiClient sdk = OpaApiClient.builder()
.build();

ExecutePolicyRequest req = ExecutePolicyRequest.builder()
.path("app/rbac")
.build();

ExecutePolicyResponse res = sdk.executePolicy()
.request(req)
ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput()
.pretty(false)
.acceptEncoding(GzipAcceptEncoding.GZIP)
.input(Input.of(8203.11d))
.call();

if (res.successfulPolicyEvaluation().isPresent()) {
if (res.result().isPresent()) {
// handle response
}
} catch (com.styra.opa.openapi.models.errors.ClientError e) {
Expand Down
47 changes: 47 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,53 @@ import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

public static void main(String[] args) throws Exception {
try {
OpaApiClient sdk = OpaApiClient.builder()
.build();

ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput()
.pretty(false)
.acceptEncoding(GzipAcceptEncoding.GZIP)
.input(Input.of(8203.11d))
.call();

if (res.result().isPresent()) {
// handle response
}
} catch (com.styra.opa.openapi.models.errors.ClientError e) {
// handle exception
throw e;
} catch (com.styra.opa.openapi.models.errors.ServerError e) {
// handle exception
throw e;
} catch (com.styra.opa.openapi.models.errors.SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
```

```java
package hello.world;

import com.styra.opa.openapi.OpaApiClient;
import com.styra.opa.openapi.models.operations.*;
import com.styra.opa.openapi.models.shared.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

public static void main(String[] args) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ publishing {
maven(MavenPublication) {
groupId = 'com.styra'
artifactId = 'opa'
version = '0.7.0'
version = '0.7.11'

from components.java

Expand Down
4 changes: 2 additions & 2 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ and used under MIT license:
<module name="ModifiedControlVariable" />
<module name="MultipleVariableDeclarations" />
<module name="NestedForDepth" />
<module name="NestedIfDepth" />
<module name="NestedTryDepth" />
<module name="NestedIfDepth"><property name="max" value="2"/></module>
<module name="NestedTryDepth"/>
<module name="NoClone" />
<module name="NoFinalizer" />
<module name="OneStatementPerLine" />
Expand Down
10 changes: 10 additions & 0 deletions docs/models/operations/ExecuteDefaultPolicyWithInputRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ExecuteDefaultPolicyWithInputRequest


## Fields

| Field | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pretty` | *Optional<? extends Boolean>* | :heavy_minus_sign: | If parameter is `true`, response will formatted for humans. |
| `acceptEncoding` | [Optional<? extends com.styra.opa.openapi.models.shared.GzipAcceptEncoding>](../../models/shared/GzipAcceptEncoding.md) | :heavy_minus_sign: | Indicates the server should respond with a gzip encoded body. The server will send the compressed response only if its length is above `server.encoding.gzip.min_length` value. See the configuration section |
| `input` | [com.styra.opa.openapi.models.shared.Input](../../models/shared/Input.md) | :heavy_check_mark: | The input document |
Loading

0 comments on commit 0ef5d04

Please sign in to comment.