Skip to content

chore: Migrate CI to sonatype central portal #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/fossa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
run: ./gradlew build

- name: Run FOSSA scan and upload build data
uses: fossas/fossa-action@3ebcea1862c6ffbd5cf1b4d0bd6b3fe7bd6f2cac # v1.7.0
uses: fossas/fossa-action@c0a7d013f84c8ee5e910593186598625513cc1e4 # v1.6.0
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
branch: ${{ github.ref_name }}

- name: Run FOSSA tests
uses: fossas/fossa-action@3ebcea1862c6ffbd5cf1b4d0bd6b3fe7bd6f2cac # v1.7.0
uses: fossas/fossa-action@c0a7d013f84c8ee5e910593186598625513cc1e4 # v1.6.0
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
run-tests: true
12 changes: 6 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
cache: gradle

- name: Set up Gradle
uses: gradle/actions/setup-gradle@8379f6a1328ee0e06e2bb424dadb7b159856a326 # v4.4.0
uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1

- name: Test and Build with Gradle
run: |
./gradlew build test-integration

- if: matrix.java == 11
name: Upload coverage to Codecov
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -59,10 +59,10 @@ jobs:
distribution: "temurin"

- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@8379f6a1328ee0e06e2bb424dadb7b159856a326 # v4.4.0
uses: gradle/actions/wrapper-validation@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1

- name: Setup Gradle
uses: gradle/actions/setup-gradle@8379f6a1328ee0e06e2bb424dadb7b159856a326 # v4.4.0
uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1

# Tasks created by https://github.com/gradle-nexus/publish-plugin
- name: Publish package
Expand Down Expand Up @@ -92,10 +92,10 @@ jobs:
distribution: "temurin"

- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@8379f6a1328ee0e06e2bb424dadb7b159856a326 # v4.4.0
uses: gradle/actions/wrapper-validation@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1

- name: Setup Gradle
uses: gradle/actions/setup-gradle@8379f6a1328ee0e06e2bb424dadb7b159856a326 # v4.4.0
uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1

# Tasks created by https://docs.gradle.org/current/userguide/publishing_maven.html
- name: Publish package
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public class Example {
}
```

#### Auth0 Client Credentials
#### Client Credentials

```java
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -605,6 +605,8 @@ Similar to [check](#check), but instead of checking a single user-object relatio

[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/BatchCheck)

> **Note**: The order of `batchCheck` results is not guaranteed to match the order of the checks provided. Use `correlationId` to pair responses with requests.

> Passing `ClientBatchCheckOptions` is optional. All fields of `ClientBatchCheckOptions` are optional.

```java
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
// Quality
id 'jacoco'
id 'jvm-test-suite'
id 'com.diffplug.spotless' version '7.0.4'
id 'com.diffplug.spotless' version '7.0.3'

Comment on lines +7 to 8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Spotless downgrade re-introduces CVE-2024-34329 transitively

Spotless 7.0.4 shaded the vulnerable commons-text range; 7.0.3 did not.
Unless the downgrade is required for the Central-Portal migration, keep 7.0.4 or explicitly override commons-text.

-    id 'com.diffplug.spotless' version '7.0.3'
+    id 'com.diffplug.spotless' version '7.0.4'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
id 'com.diffplug.spotless' version '7.0.3'
id 'com.diffplug.spotless' version '7.0.4'
🤖 Prompt for AI Agents
In build.gradle around lines 7 to 8, the Spotless plugin version is downgraded
to 7.0.3, which reintroduces the CVE-2024-34329 vulnerability due to an unshaded
vulnerable commons-text dependency. To fix this, either revert the Spotless
plugin version back to 7.0.4 or, if the downgrade is necessary, explicitly add a
dependency override for commons-text to a safe version that mitigates the
vulnerability.

// IDE
id 'idea'
Expand Down Expand Up @@ -65,7 +65,7 @@ dependencies {
implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
implementation "org.openapitools:jackson-databind-nullable:0.2.6"
implementation platform("io.opentelemetry:opentelemetry-bom:1.50.0")
implementation platform("io.opentelemetry:opentelemetry-bom:1.49.0")
implementation "io.opentelemetry:opentelemetry-api"
}

Expand All @@ -75,8 +75,8 @@ testing {
useJUnitJupiter()
dependencies {
implementation 'org.assertj:assertj-core:3.27.3'
implementation 'org.mockito:mockito-core:5.18.0'
implementation 'org.junit.jupiter:junit-jupiter:5.13.0'
implementation 'org.mockito:mockito-core:5.17.0'
implementation 'org.junit.jupiter:junit-jupiter:5.12.2'
implementation 'org.wiremock:wiremock:3.13.0'

runtimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down Expand Up @@ -106,8 +106,8 @@ testing {
dependencies {
implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version"
implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
implementation "org.testcontainers:junit-jupiter:1.21.1"
implementation "org.testcontainers:openfga:1.21.1"
implementation "org.testcontainers:junit-jupiter:1.21.0"
implementation "org.testcontainers:openfga:1.21.0"
implementation project()
}

Expand Down
4 changes: 2 additions & 2 deletions example/example1/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'application'
id 'com.diffplug.spotless' version '7.0.4'
id 'org.jetbrains.kotlin.jvm' version '2.1.21'
id 'com.diffplug.spotless' version '7.0.3'
id 'org.jetbrains.kotlin.jvm' version '2.1.20'
}

application {
Expand Down
4 changes: 2 additions & 2 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ signing {
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri('https://s01.oss.sonatype.org/service/local/'))
snapshotRepositoryUrl.set(uri('https://s01.oss.sonatype.org/content/repositories/snapshots/'))
nexusUrl.set(uri('https://ossrh-staging-api.central.sonatype.com/service/local/'))
snapshotRepositoryUrl.set(uri('https://central.sonatype.com/repository/maven-snapshots/'))
username.set(System.getenv('MAVEN_USERNAME'))
Comment on lines +54 to 56
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Verify new Central-Portal endpoints

According to Sonatype’s migration guide the staging API is
https://central.sonatype.com/api/v1/staging and snapshots stay on s01.oss.sonatype.org.
The URLs used here (ossrh-staging-api.central.sonatype.com and /repository/maven-snapshots/) are not documented and may 404.

-            nexusUrl.set(uri('https://ossrh-staging-api.central.sonatype.com/service/local/'))
-            snapshotRepositoryUrl.set(uri('https://central.sonatype.com/repository/maven-snapshots/'))
+            nexusUrl.set(uri('https://central.sonatype.com/api/v1/staging'))
+            snapshotRepositoryUrl.set(uri('https://s01.oss.sonatype.org/content/repositories/snapshots/'))

Also, the workflows still use OSSRH_USERNAME/OSSRH_TOKEN; Central Portal requires a generated ‘token’ credential instead.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
nexusUrl.set(uri('https://ossrh-staging-api.central.sonatype.com/service/local/'))
snapshotRepositoryUrl.set(uri('https://central.sonatype.com/repository/maven-snapshots/'))
username.set(System.getenv('MAVEN_USERNAME'))
nexusUrl.set(uri('https://central.sonatype.com/api/v1/staging'))
snapshotRepositoryUrl.set(uri('https://s01.oss.sonatype.org/content/repositories/snapshots/'))
username.set(System.getenv('MAVEN_USERNAME'))
🤖 Prompt for AI Agents
In publish.gradle around lines 54 to 56, update the nexusUrl to
'https://central.sonatype.com/api/v1/staging' as per Sonatype's migration guide,
and change the snapshotRepositoryUrl to use the 's01.oss.sonatype.org' domain
for snapshots. Also, replace the environment variables for authentication from
'OSSRH_USERNAME' and 'OSSRH_TOKEN' to use the new Central Portal generated token
credentials accordingly.

password.set(System.getenv('MAVEN_PASSWORD'))
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/openfga/sdk/api/OpenFgaApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,11 @@ private Map<Attribute, String> buildTelemetryAttributes(Map<String, Object> attr
if (body instanceof BatchCheckRequest) {
BatchCheckRequest batchCheckRequest = (BatchCheckRequest) body;

if (!isNullOrWhitespace(batchCheckRequest.getAuthorizationModelId())) {
telemetryAttributes.put(
Attributes.FGA_CLIENT_REQUEST_MODEL_ID, batchCheckRequest.getAuthorizationModelId());
}

if (batchCheckRequest.getChecks() != null) {
telemetryAttributes.put(
Attributes.FGA_CLIENT_REQUEST_BATCH_CHECK_SIZE,
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,23 @@ public CompletableFuture<ClientBatchCheckResponse> batchCheck(

var override = new ConfigurationOverride().addHeaders(options);

Consumer<List<BatchCheckItem>> singleBatchCheckRequest = request -> call(() ->
api.batchCheck(configuration.getStoreId(), new BatchCheckRequest().checks(request), override))
Consumer<List<BatchCheckItem>> singleBatchCheckRequest = request -> call(() -> {
BatchCheckRequest body = new BatchCheckRequest().checks(request);
if (options.getConsistency() != null) {
body.consistency(options.getConsistency());
}

// Set authorizationModelId from options if available; otherwise, use the default from configuration
String authorizationModelId = !isNullOrWhitespace(options.getAuthorizationModelId())
? options.getAuthorizationModelId()
: configuration.getAuthorizationModelId();

if (!isNullOrWhitespace(authorizationModelId)) {
body.authorizationModelId(authorizationModelId);
}

return api.batchCheck(configuration.getStoreId(), body, override);
})
.handleAsync((batchCheckResponseApiResponse, throwable) -> {
Map<String, BatchCheckSingleResult> response =
batchCheckResponseApiResponse.getData().getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public int hashCode() {
public Boolean isNullable() {
if (Boolean.TRUE.equals(isNullable)) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
return Boolean.FALSE;
}
}
32 changes: 32 additions & 0 deletions src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,38 @@ public void shouldSplitBatchesSuccessfully(WireMockRuntimeInfo wireMockRuntimeIn
assertEquals("relation not found", response3.getError().getMessage());
}

@Test
public void batchCheck_withOptions() throws Exception {
// Given
String postUrl = String.format("https://api.fga.example/stores/%s/batch-check", DEFAULT_STORE_ID);
String expectedBody = String.format(
"{\"checks\":[{\"tuple_key\":{\"user\":\"%s\",\"relation\":\"%s\",\"object\":\"%s\"},\"contextual_tuples\":null,\"context\":null,\"correlation_id\":\"cor-1\"}],\"authorization_model_id\":\"%s\",\"consistency\":\"%s\"}",
DEFAULT_USER,
DEFAULT_RELATION,
DEFAULT_OBJECT,
DEFAULT_AUTH_MODEL_ID,
ConsistencyPreference.MINIMIZE_LATENCY);
mockHttpClient.onPost(postUrl).withBody(is(expectedBody)).doReturn(200, "{\"result\":{}}");

ClientBatchCheckItem item = new ClientBatchCheckItem()
.user(DEFAULT_USER)
.relation(DEFAULT_RELATION)
._object(DEFAULT_OBJECT)
.correlationId("cor-1");
ClientBatchCheckRequest request = new ClientBatchCheckRequest().checks(List.of(item));
ClientBatchCheckOptions options = new ClientBatchCheckOptions()
.authorizationModelId(DEFAULT_AUTH_MODEL_ID)
.consistency(ConsistencyPreference.MINIMIZE_LATENCY);

// When
ClientBatchCheckResponse response = fga.batchCheck(request, options).join();

// Then
mockHttpClient.verify().post(postUrl).withBody(is(expectedBody)).called(1);
assertNotNull(response);
assertTrue(response.getResult().isEmpty());
}

/**
* Expand all relationships in userset tree format, and following userset rewrite rules. Useful to reason
* about and debug a certain relationship.
Expand Down