From 16637e15c2e10a029a7e5b2eb15b03d36f1b68c0 Mon Sep 17 00:00:00 2001 From: AnurosePrakash Date: Tue, 2 May 2023 15:28:51 +0200 Subject: [PATCH 1/8] feat: reworking lastcommitinfo extension --- extensions/last-commit-info/build.gradle.kts | 3 + .../sovity/edc/extension/LastCommitInfo.java | 28 +++++++++ .../extension/LastCommitInfoController.java | 5 +- .../edc/extension/LastCommitInfoService.java | 17 ++---- .../controller/LastCommitInfoEnvTest.java | 42 ------------- .../controller/LastCommitInfoJarTest.java | 43 ------------- .../controller/LastCommitInfoTest.java | 61 +++++++++++++++++++ .../version/controller/TestUtils.java | 33 +--------- .../test/resources/jar-last-commit-info.txt | 1 + 9 files changed, 105 insertions(+), 128 deletions(-) create mode 100644 extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java delete mode 100644 extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoEnvTest.java delete mode 100644 extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoJarTest.java create mode 100644 extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java create mode 100644 extensions/last-commit-info/src/test/resources/jar-last-commit-info.txt diff --git a/extensions/last-commit-info/build.gradle.kts b/extensions/last-commit-info/build.gradle.kts index d67433fb5..f5babd589 100644 --- a/extensions/last-commit-info/build.gradle.kts +++ b/extensions/last-commit-info/build.gradle.kts @@ -8,6 +8,9 @@ plugins { } dependencies { + annotationProcessor("org.projectlombok:lombok:1.18.26") + compileOnly("org.projectlombok:lombok:1.18.26") + api("${edcGroup}:core-spi:${edcVersion}") api("${edcGroup}:control-plane-spi:${edcVersion}") implementation("${edcGroup}:api-core:${edcVersion}") diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java new file mode 100644 index 000000000..ce237151b --- /dev/null +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.extension; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class LastCommitInfo { + /** + * + */ + private String envLastCommitInfo; + private String jarLastCommitInfo; +} diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java index 1d48f0bce..db44ebc56 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java @@ -23,13 +23,16 @@ @Path("/last-commit-info") public class LastCommitInfoController { private final LastCommitInfoService lastCommitInfoService; + //private final LastCommitInfo lastCommitInfo; public LastCommitInfoController(LastCommitInfoService lastCommitInfoService) { this.lastCommitInfoService = lastCommitInfoService; } @GET - public String getLastCommitInfo() { + @Produces(MediaType.APPLICATION_JSON) + public LastCommitInfo getLastCommitInfo() { + System.out.println("the commit info : "+lastCommitInfoService.getLastCommitInfo()); return lastCommitInfoService.getLastCommitInfo(); } } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java index 461b0a8df..54c12dd55 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java @@ -24,23 +24,18 @@ public class LastCommitInfoService { private final ServiceExtensionContext context; + + public LastCommitInfoService(ServiceExtensionContext context) { this.context = context; } - public String getLastCommitInfo() { - var result = ""; - - if (!getEnvLastCommitInfo().equals("")) { - result += "Env Last Commit Info: \n"; - result += getEnvLastCommitInfo() + "\n"; - } + public LastCommitInfo getLastCommitInfo() { + var result = new LastCommitInfo(); + result.setEnvLastCommitInfo(getEnvLastCommitInfo()); - if (!getEnvLastCommitInfo().equals(getJarLastCommitInfo())) { - result += "Jar Last Commit Info: \n"; - result += getJarLastCommitInfo(); - } + result.setJarLastCommitInfo(getJarLastCommitInfo()); return result; } diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoEnvTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoEnvTest.java deleted file mode 100644 index c3f59a247..000000000 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoEnvTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2023 sovity GmbH - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.extension.version.controller; - -import org.eclipse.edc.junit.annotations.ApiTest; -import org.eclipse.edc.junit.extensions.EdcExtension; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static de.sovity.edc.extension.version.controller.TestUtils.createConfiguration; -import static de.sovity.edc.extension.version.controller.TestUtils.mockRequest; -import static org.hamcrest.Matchers.containsStringIgnoringCase; - -@ApiTest -@ExtendWith(EdcExtension.class) -class LastCommitInfoEnvTest { - - @BeforeEach - void setUp(EdcExtension extension) { - extension.setConfiguration(createConfiguration("env")); - } - - @Test - void testEnvAndJar() { - var request = mockRequest(); - request.assertThat().body(containsStringIgnoringCase("pipeline")); - request.assertThat().body(containsStringIgnoringCase("env")); - } -} diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoJarTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoJarTest.java deleted file mode 100644 index 65f87062e..000000000 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoJarTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 sovity GmbH - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.extension.version.controller; - -import org.eclipse.edc.junit.annotations.ApiTest; -import org.eclipse.edc.junit.extensions.EdcExtension; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static de.sovity.edc.extension.version.controller.TestUtils.createConfiguration; -import static de.sovity.edc.extension.version.controller.TestUtils.mockRequest; -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.not; - -@ApiTest -@ExtendWith(EdcExtension.class) -class LastCommitInfoJarTest { - - @BeforeEach - void setUp(EdcExtension extension) { - extension.setConfiguration(createConfiguration("")); - } - - @Test - void testOnlyJar() { - var request = mockRequest(); - request.assertThat().body(containsStringIgnoringCase("pipeline")); - request.assertThat().body(not(containsStringIgnoringCase("env"))); - } -} diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java new file mode 100644 index 000000000..ab7eb8e54 --- /dev/null +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.extension.version.controller; + +import io.restassured.http.ContentType; +import org.eclipse.edc.junit.annotations.ApiTest; +import org.eclipse.edc.junit.extensions.EdcExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort; +import static org.hamcrest.Matchers.equalTo; + +@ApiTest +@ExtendWith(EdcExtension.class) +class LastCommitInfoTest { + + @BeforeEach + void setUp(EdcExtension extension) { + extension.setConfiguration(Map.of( + "web.http.port", String.valueOf(getFreePort()), + "web.http.path", "/api", + "web.http.management.port", String.valueOf(TestUtils.DATA_PORT), + "web.http.management.path", "/api/v1/data", + "edc.api.auth.key", TestUtils.AUTH_KEY, + "edc.last.commit.info", "test env commit message")); + } + + @Test + void testEnvAndJar() { + var request = given() + .baseUri("http://localhost:" + TestUtils.DATA_PORT) + .basePath("/api/v1/data") + .header("x-api-key", TestUtils.AUTH_KEY) + .when() + .contentType(ContentType.JSON) + .get("/last-commit-info") + .then() + .statusCode(200) + .contentType(ContentType.JSON); + + request.assertThat().body("envLastCommitInfo", equalTo("test env commit message")) + .body("jarLastCommitInfo", equalTo("test jar commit message\n")); + } +} diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java index 8ceecd847..e9f6c6866 100644 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java @@ -14,41 +14,12 @@ package de.sovity.edc.extension.version.controller; -import io.restassured.http.ContentType; -import io.restassured.response.ValidatableResponse; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - import static io.restassured.RestAssured.given; import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort; public class TestUtils { - private static final int DATA_PORT = getFreePort(); - private static final String AUTH_KEY = "123456"; - - @NotNull - static Map createConfiguration(String commitInfo) { - return Map.of( - "web.http.port", String.valueOf(getFreePort()), - "web.http.path", "/api", - "web.http.management.port", String.valueOf(DATA_PORT), - "web.http.management.path", "/api/v1/data", - "edc.api.auth.key", AUTH_KEY, - "edc.last.commit.info", commitInfo); - } + public static final int DATA_PORT = getFreePort(); + public static final String AUTH_KEY = "123456"; - static ValidatableResponse mockRequest() { - return given() - .baseUri("http://localhost:" + DATA_PORT) - .basePath("/api/v1/data") - .header("x-api-key", AUTH_KEY) - .when() - .contentType(ContentType.TEXT) - .get(String.format("/last-commit-info")) - .then() - .statusCode(200) - .contentType(ContentType.JSON); - } } diff --git a/extensions/last-commit-info/src/test/resources/jar-last-commit-info.txt b/extensions/last-commit-info/src/test/resources/jar-last-commit-info.txt new file mode 100644 index 000000000..1516a70eb --- /dev/null +++ b/extensions/last-commit-info/src/test/resources/jar-last-commit-info.txt @@ -0,0 +1 @@ +test jar commit message From b46c71256e8a4a092a05ce92ef55d31744b5aebc Mon Sep 17 00:00:00 2001 From: AnurosePrakash Date: Fri, 5 May 2023 11:35:07 +0200 Subject: [PATCH 2/8] chore: refactor --- .../main/java/de/sovity/edc/extension/LastCommitInfo.java | 6 +++--- .../de/sovity/edc/extension/LastCommitInfoController.java | 2 -- .../extension/version/controller/LastCommitInfoTest.java | 5 ++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java index ce237151b..0a4a97a8d 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java @@ -20,9 +20,9 @@ @Getter @Setter public class LastCommitInfo { - /** - * - */ + private String envLastCommitInfo; + private String envLastBuildDate; private String jarLastCommitInfo; + private String jarLastBuildDate; } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java index db44ebc56..9f7994694 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java @@ -23,7 +23,6 @@ @Path("/last-commit-info") public class LastCommitInfoController { private final LastCommitInfoService lastCommitInfoService; - //private final LastCommitInfo lastCommitInfo; public LastCommitInfoController(LastCommitInfoService lastCommitInfoService) { this.lastCommitInfoService = lastCommitInfoService; @@ -32,7 +31,6 @@ public LastCommitInfoController(LastCommitInfoService lastCommitInfoService) { @GET @Produces(MediaType.APPLICATION_JSON) public LastCommitInfo getLastCommitInfo() { - System.out.println("the commit info : "+lastCommitInfoService.getLastCommitInfo()); return lastCommitInfoService.getLastCommitInfo(); } } diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java index ab7eb8e54..04c26d37e 100644 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java @@ -56,6 +56,9 @@ void testEnvAndJar() { .contentType(ContentType.JSON); request.assertThat().body("envLastCommitInfo", equalTo("test env commit message")) - .body("jarLastCommitInfo", equalTo("test jar commit message\n")); + .body("envLastBuildDate", equalTo("2023-05-05T14:30:00Z")) + .body("jarLastCommitInfo", equalTo("test jar commit message\n")) + .body("jarLastBuildDate", equalTo("2023-05-05T14:30:00Z")); + } } From cefe67b196c77d406b5d36543f680f4e7290fcfa Mon Sep 17 00:00:00 2001 From: AnurosePrakash Date: Mon, 8 May 2023 15:33:07 +0200 Subject: [PATCH 3/8] feat: adding last build date values of edc env and jar to the last commit info --- .../sovity/edc/extension/LastCommitInfo.java | 2 ++ .../extension/LastCommitInfoController.java | 4 ++- .../edc/extension/LastCommitInfoService.java | 31 +++++++++++++++---- .../controller/LastCommitInfoTest.java | 8 ++--- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java index 0a4a97a8d..7ffe5b924 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java @@ -25,4 +25,6 @@ public class LastCommitInfo { private String envLastBuildDate; private String jarLastCommitInfo; private String jarLastBuildDate; + + } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java index 9f7994694..48b622642 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java @@ -19,6 +19,8 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; +import java.io.IOException; + @Produces({MediaType.APPLICATION_JSON}) @Path("/last-commit-info") public class LastCommitInfoController { @@ -30,7 +32,7 @@ public LastCommitInfoController(LastCommitInfoService lastCommitInfoService) { @GET @Produces(MediaType.APPLICATION_JSON) - public LastCommitInfo getLastCommitInfo() { + public LastCommitInfo getLastCommitInfo() throws IOException { return lastCommitInfoService.getLastCommitInfo(); } } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java index 54c12dd55..3307a3ef7 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java @@ -16,37 +16,56 @@ import org.eclipse.edc.spi.system.ServiceExtensionContext; +import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.Scanner; +import java.util.jar.Attributes; +import java.util.jar.Manifest; public class LastCommitInfoService { private final ServiceExtensionContext context; - public LastCommitInfoService(ServiceExtensionContext context) { this.context = context; } - public LastCommitInfo getLastCommitInfo() { + public LastCommitInfo getLastCommitInfo() throws IOException { var result = new LastCommitInfo(); result.setEnvLastCommitInfo(getEnvLastCommitInfo()); + result.setEnvLastBuildDate(getEnvLastCommitDate()); - - result.setJarLastCommitInfo(getJarLastCommitInfo()); + result.setJarLastCommitInfo(getJarInfo().get(0)); + result.setJarLastBuildDate(getJarInfo().get(1)); return result; } - public String getJarLastCommitInfo() { + public List getJarInfo() throws IOException { + + var jarInfo = new ArrayList(); var classLoader = Thread.currentThread().getContextClassLoader(); var is = classLoader.getResourceAsStream("jar-last-commit-info.txt"); var scanner = new Scanner(Objects.requireNonNull(is), StandardCharsets.UTF_8).useDelimiter("\\A"); - return scanner.hasNext() ? scanner.next() : ""; + jarInfo.add(scanner.hasNext() ? scanner.next() : ""); + + Manifest manifest = new Manifest(is); + Attributes attributes = manifest.getMainAttributes(); + jarInfo.add(attributes.getValue("Build-Date")); + + return jarInfo; } public String getEnvLastCommitInfo() { return context.getSetting("edc.last.commit.info", ""); } + + public String getEnvLastCommitDate() { + return context.getSetting("edc.env.last.commit.date", ""); + } + + } diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java index 04c26d37e..5b513cbc8 100644 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java @@ -39,7 +39,8 @@ void setUp(EdcExtension extension) { "web.http.management.port", String.valueOf(TestUtils.DATA_PORT), "web.http.management.path", "/api/v1/data", "edc.api.auth.key", TestUtils.AUTH_KEY, - "edc.last.commit.info", "test env commit message")); + "edc.last.commit.info", "test env commit message", + "edc.env.last.commit.date", "2023-05-08T15:30:00Z")); } @Test @@ -56,9 +57,8 @@ void testEnvAndJar() { .contentType(ContentType.JSON); request.assertThat().body("envLastCommitInfo", equalTo("test env commit message")) - .body("envLastBuildDate", equalTo("2023-05-05T14:30:00Z")) - .body("jarLastCommitInfo", equalTo("test jar commit message\n")) - .body("jarLastBuildDate", equalTo("2023-05-05T14:30:00Z")); + .body("envLastBuildDate", equalTo("2023-05-08T15:30:00Z")) + .body("jarLastCommitInfo", equalTo("test jar commit message\n")); } } From 56c82f08bcd0b9cd9009a80987a60a2b3b415da5 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Fri, 5 May 2023 11:43:19 +0200 Subject: [PATCH 4/8] feat oauth2 client credentials auth flow (Java API Wrapper Client Library) (#309) * feat oauth2 client credentials auth flow (Java API Wrapper Client Library) * fix README.md (Java API Wrapper Client) * refactor remove google oauth dependency, minor code quality improvements * ci add retries due to iais maven repo issue * fix minor code quality issues --- .../build-and-publish-connector-images.yml | 7 +++ .../build-and-publish-ts-api-client.yml | 7 +++ extensions/wrapper/client-example/README.md | 2 +- .../wrapper/client-ts-example/README.md | 2 +- extensions/wrapper/client/README.md | 36 +++++++++++ .../sovity/edc/client/EdcClientBuilder.java | 13 ++++ .../sovity/edc/client/EdcClientFactory.java | 23 +++++++- .../oauth2/OAuth2ClientCredentials.java | 36 +++++++++++ .../OAuth2CredentialsAuthenticator.java | 59 +++++++++++++++++++ .../oauth2/OAuth2CredentialsInterceptor.java | 40 +++++++++++++ .../client/oauth2/OAuth2CredentialsStore.java | 54 +++++++++++++++++ .../edc/client/oauth2/OAuth2TokenFetcher.java | 56 ++++++++++++++++++ .../client/oauth2/OAuth2TokenResponse.java | 35 +++++++++++ .../edc/client/oauth2/OkHttpRequestUtils.java | 38 ++++++++++++ .../edc/client/oauth2/SovityKeycloakUrl.java | 37 ++++++++++++ ...ClientTest.java => UseCaseClientTest.java} | 0 extensions/wrapper/wrapper-ee-api/README.md | 2 +- extensions/wrapper/wrapper/README.md | 2 +- 18 files changed, 443 insertions(+), 6 deletions(-) create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2ClientCredentials.java create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsAuthenticator.java create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsInterceptor.java create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsStore.java create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenFetcher.java create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenResponse.java create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OkHttpRequestUtils.java create mode 100644 extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/SovityKeycloakUrl.java rename extensions/wrapper/client/src/test/java/de/sovity/edc/client/{ExampleClientTest.java => UseCaseClientTest.java} (100%) diff --git a/.github/workflows/build-and-publish-connector-images.yml b/.github/workflows/build-and-publish-connector-images.yml index c654f30c3..cfb9e5a00 100644 --- a/.github/workflows/build-and-publish-connector-images.yml +++ b/.github/workflows/build-and-publish-connector-images.yml @@ -84,6 +84,13 @@ jobs: - name: Build and push EDC image uses: docker/build-push-action@v4 with: + # The Core EDC depends on a dependency in the Fraunhofer IAIS Maven Nexus + # Because that nexus is currently only 40% available, it keeps crashing the pipelines + # The following retries alleviate the issue slightly + retry_on: error + timeout_seconds: 5 + max_attempts: 4 + file: connector/Dockerfile context: . push: true diff --git a/.github/workflows/build-and-publish-ts-api-client.yml b/.github/workflows/build-and-publish-ts-api-client.yml index 62fc20d57..6fe48db9a 100644 --- a/.github/workflows/build-and-publish-ts-api-client.yml +++ b/.github/workflows/build-and-publish-ts-api-client.yml @@ -29,6 +29,13 @@ jobs: registry-url: 'https://registry.npmjs.org' cache-dependency-path: ./extensions/wrapper/client-ts/package-lock.json - name: Generate openapi.yaml & Client Code + with: + # The Core EDC depends on a dependency in the Fraunhofer IAIS Maven Nexus + # Because that nexus is currently only 40% available, it keeps crashing the pipelines + # The following retries alleviate the issue slightly + retry_on: error + timeout_seconds: 5 + max_attempts: 4 run: | ./gradlew :extensions:wrapper:wrapper:clean :extensions:wrapper:wrapper:build -x test --no-daemon - name: NPM Package Dist Tag & Version diff --git a/extensions/wrapper/client-example/README.md b/extensions/wrapper/client-example/README.md index 7221dd264..d0e8ac7d9 100644 --- a/extensions/wrapper/client-example/README.md +++ b/extensions/wrapper/client-example/README.md @@ -43,7 +43,7 @@ docker compose -f docker-compose-dev.yaml down -t 1 ## License -Apache License 2.0 - see [LICENSE](../../LICENSE) +Apache License 2.0 - see [LICENSE](../../../LICENSE) ## Contact diff --git a/extensions/wrapper/client-ts-example/README.md b/extensions/wrapper/client-ts-example/README.md index 6b65d1429..c5f1027cf 100644 --- a/extensions/wrapper/client-ts-example/README.md +++ b/extensions/wrapper/client-ts-example/README.md @@ -51,7 +51,7 @@ docker compose -f docker-compose-dev.yaml down -t 1 ## License -Apache License 2.0 - see [LICENSE](../../LICENSE) +Apache License 2.0 - see [LICENSE](../../../LICENSE) ## Contact diff --git a/extensions/wrapper/client/README.md b/extensions/wrapper/client/README.md index 7449ae824..714248fca 100644 --- a/extensions/wrapper/client/README.md +++ b/extensions/wrapper/client/README.md @@ -31,6 +31,42 @@ An example project using this client can be found [here](../client-example). ``` +## Usage + +### Example Using API Key Auth + +```java +import de.sovity.edc.client.EdcClient; + +// Example using our Community Edition EDC +EdcClient client = EdcClient.builder() + .managementApiUrl("http://localhost:11002/api/v1/management") + .managementApiKey("ApiKeyDefaultValue") + .build(); + +KpiResult kpiResult = client.useCaseApi().kpiEndpoint(); +``` + +### Example Using OAuth2 Client Credentials + +```java +import de.sovity.edc.client.EdcClient; +import de.sovity.edc.client.oauth2.OAuth2ClientCredentials; +import de.sovity.edc.client.oauth2.SovityKeycloakUrl; + +// Example using a productive Connector-as-a-Service (CaaS) EDC Connector +EdcClient client = EdcClient.builder() + .managementApiUrl("https://your-connector.prod-sovity.azure.sovity.io/control/data") + .oauth2ClientCredentials(OAuth2ClientCredentials.builder() + .tokenUrl(SovityKeycloakUrl.PRODUCTION) + .clientId("my-edc-app") + .clientSecret("...") + .build()) + .build(); + +KpiResult kpiResult = client.useCaseApi().kpiEndpoint(); +``` + ## License Apache License 2.0 - see [LICENSE](../../LICENSE) diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientBuilder.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientBuilder.java index d9a18f593..dafc8d53d 100644 --- a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientBuilder.java +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientBuilder.java @@ -14,6 +14,7 @@ package de.sovity.edc.client; +import de.sovity.edc.client.oauth2.OAuth2ClientCredentials; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -22,9 +23,21 @@ @Setter @Accessors(fluent = true, chain = true) public class EdcClientBuilder { + /** + * Management API Base URL, e.g. https://my-connector.com/control/management + */ private String managementApiUrl; + + /** + * Enables EDC Management API Key authentication. + */ private String managementApiKey = "ApiKeyDefaultValue"; + /** + * Enables OAuth2 "Client Credentials Flow" authentication. + */ + private OAuth2ClientCredentials oauth2ClientCredentials; + public EdcClient build() { return EdcClientFactory.newClient(this); } diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientFactory.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientFactory.java index afaee68d2..e03c1e299 100644 --- a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientFactory.java +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/EdcClientFactory.java @@ -18,8 +18,13 @@ import de.sovity.edc.client.gen.api.EnterpriseEditionApi; import de.sovity.edc.client.gen.api.UiApi; import de.sovity.edc.client.gen.api.UseCaseApi; +import de.sovity.edc.client.oauth2.OAuth2CredentialsAuthenticator; +import de.sovity.edc.client.oauth2.OAuth2CredentialsStore; +import de.sovity.edc.client.oauth2.OAuth2CredentialsInterceptor; +import de.sovity.edc.client.oauth2.OAuth2TokenFetcher; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; /** * Builds {@link EdcClient}s. @@ -30,8 +35,22 @@ public class EdcClientFactory { public static EdcClient newClient(EdcClientBuilder builder) { var apiClient = new ApiClient() .setServerIndex(null) - .setBasePath(builder.managementApiUrl()) - .addDefaultHeader("x-api-key", builder.managementApiKey()); + .setBasePath(builder.managementApiUrl()); + + if (StringUtils.isNotBlank(builder.managementApiKey())) { + apiClient.addDefaultHeader("X-Api-Key", builder.managementApiKey()); + } + + if (builder.oauth2ClientCredentials() != null) { + var tokenFetcher = new OAuth2TokenFetcher(builder.oauth2ClientCredentials()); + var handler = new OAuth2CredentialsStore(tokenFetcher); + var httpClient = apiClient.getHttpClient() + .newBuilder() + .addInterceptor(new OAuth2CredentialsInterceptor(handler)) + .authenticator(new OAuth2CredentialsAuthenticator(handler)) + .build(); + apiClient.setHttpClient(httpClient); + } return new EdcClient( new UiApi(apiClient), diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2ClientCredentials.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2ClientCredentials.java new file mode 100644 index 000000000..b202ed6a5 --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2ClientCredentials.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NonNull; + +/** + * Credentials for connecting to the EDC via the OAuth2 "Client Credentials" flow. + */ +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder +public class OAuth2ClientCredentials { + @NonNull + private String tokenUrl; + @NonNull + private String clientId; + @NonNull + private String clientSecret; +} diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsAuthenticator.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsAuthenticator.java new file mode 100644 index 000000000..6a9d3486a --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsAuthenticator.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import lombok.RequiredArgsConstructor; +import okhttp3.Authenticator; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.Route; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * OkHttp Authenticator: Potentially re-tries requests that failed with a 401 / 403 + * with updated access tokens. + */ +@RequiredArgsConstructor +public class OAuth2CredentialsAuthenticator implements Authenticator { + private final OAuth2CredentialsStore credentialsStore; + + @Nullable + @Override + public Request authenticate(@Nullable Route route, @NotNull Response response) { + // Skip if original request had no authentication + if (!OkHttpRequestUtils.hadBearerToken(response)) { + return null; + } + + var token = credentialsStore.getAccessToken(); + synchronized (this) { + // The synchronized Block prevents multiple parallel token refreshes + // So here the token might have changed already + var changedToken = credentialsStore.getAccessToken(); + + // If the token has changed since the request was made, use the new token. + if (!changedToken.equals(token)) { + return OkHttpRequestUtils.withBearerToken(response.request(), changedToken); + } + + // If the token hasn't changed, try to be the code path to refresh the token + var updatedToken = credentialsStore.refreshAccessToken(); + + // Retry the request with the new token. + return OkHttpRequestUtils.withBearerToken(response.request(), updatedToken); + } + } +} diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsInterceptor.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsInterceptor.java new file mode 100644 index 000000000..dd52d2d8d --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsInterceptor.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import lombok.RequiredArgsConstructor; +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; + +/** + * OkHttp Interceptor: Adds Bearer Token to requests + */ +@RequiredArgsConstructor +public class OAuth2CredentialsInterceptor implements Interceptor { + private final OAuth2CredentialsStore credentialsStore; + + @NotNull + @Override + public Response intercept(Chain chain) throws IOException { + String accessToken = credentialsStore.getAccessToken(); + Request request = OkHttpRequestUtils.withBearerToken(chain.request(), accessToken); + return chain.proceed(request); + } + +} diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsStore.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsStore.java new file mode 100644 index 000000000..0b02da89d --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2CredentialsStore.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import lombok.SneakyThrows; + +/** + * Holds the Access Token and coordinates it between the Interceptor and the Authenticator. + */ +public class OAuth2CredentialsStore { + private final OAuth2TokenFetcher tokenFetcher; + private OAuth2TokenResponse tokenResponse = null; + + public OAuth2CredentialsStore(OAuth2TokenFetcher tokenFetcher) { + this.tokenFetcher = tokenFetcher; + this.fetchAccessTokenInternal(); + } + + public String getAccessToken() { + synchronized (this) { + if (tokenResponse == null) { + fetchAccessTokenInternal(); + } + return tokenResponse.getAccessToken(); + } + } + + public String refreshAccessToken() { + synchronized (this) { + fetchAccessTokenInternal(); + return tokenResponse.getAccessToken(); + } + } + + @SneakyThrows + private void fetchAccessTokenInternal() { + // If it crashes afterwards, the next request won't attempt to use the old token + tokenResponse = null; + tokenResponse = tokenFetcher.fetchToken(); + } + +} diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenFetcher.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenFetcher.java new file mode 100644 index 000000000..381252d04 --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenFetcher.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import de.sovity.edc.client.gen.ApiClient; +import de.sovity.edc.client.gen.ApiResponse; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import okhttp3.Call; +import okhttp3.FormBody; +import okhttp3.Request; + +/** + * OAuth2 Token Response Fetcher for the "Client Credentials Grant" Flow + */ +@RequiredArgsConstructor +public class OAuth2TokenFetcher { + private final OAuth2ClientCredentials clientCredentials; + private final ApiClient apiClient = new ApiClient(); + + /** + * Fetch an access token for a "Client Credentials" Grant + * + * @return the token response including the access token + */ + @SneakyThrows + public OAuth2TokenResponse fetchToken() { + var formData = new FormBody.Builder() + .add("grant_type", "client_credentials") + .add("client_id", clientCredentials.getClientId()) + .add("client_secret", clientCredentials.getClientSecret()) + .build(); + + var request = new Request.Builder() + .url(clientCredentials.getTokenUrl()) + .post(formData) + .build(); + + // Re-use the Utils for OkHttp from the OpenAPI generator + Call call = apiClient.getHttpClient().newCall(request); + ApiResponse response = apiClient.execute(call, OAuth2TokenResponse.class); + return response.getData(); + } +} diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenResponse.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenResponse.java new file mode 100644 index 000000000..5096169b9 --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OAuth2TokenResponse.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import com.google.gson.annotations.SerializedName; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * Credentials for connecting to the EDC via the OAuth2 "Client Credentials" flow. + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class OAuth2TokenResponse { + + @SerializedName("access_token") + private String accessToken; +} diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OkHttpRequestUtils.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OkHttpRequestUtils.java new file mode 100644 index 000000000..10ee1ca4e --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/OkHttpRequestUtils.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import okhttp3.Request; +import okhttp3.Response; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class OkHttpRequestUtils { + public static boolean hadBearerToken(@NonNull Response response) { + String header = response.request().header("Authorization"); + return header != null && header.startsWith("Bearer"); + } + + @NonNull + public static Request withBearerToken(@NonNull Request request, @NonNull String accessToken) { + return request.newBuilder() + .removeHeader("Authorization") + .header("Authorization", "Bearer " + accessToken) + .build(); + } +} + diff --git a/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/SovityKeycloakUrl.java b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/SovityKeycloakUrl.java new file mode 100644 index 000000000..1175628e6 --- /dev/null +++ b/extensions/wrapper/client/src/main/java/de/sovity/edc/client/oauth2/SovityKeycloakUrl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.client.oauth2; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Quick access to the Keycloak OAuth Token URLs for our staging and production environments. + *

+ * For ease of use of our API Wrapper Client Libraries in Use Case Applications. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SovityKeycloakUrl { + + /** + * Sovity Production Keycloak OAuth2 Token URL + */ + public static final String PRODUCTION = "https://keycloak.prod-sovity.azure.sovity.io/realms/Portal/protocol/openid-connect/token"; + + /** + * Sovity Staging Keycloak OAuth2 Token URL + */ + public static final String STAGING = "https://keycloak.stage-sovity.azure.sovity.io/realms/Portal/protocol/openid-connect/token"; +} diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ExampleClientTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/UseCaseClientTest.java similarity index 100% rename from extensions/wrapper/client/src/test/java/de/sovity/edc/client/ExampleClientTest.java rename to extensions/wrapper/client/src/test/java/de/sovity/edc/client/UseCaseClientTest.java diff --git a/extensions/wrapper/wrapper-ee-api/README.md b/extensions/wrapper/wrapper-ee-api/README.md index c85324549..8fb3a6372 100644 --- a/extensions/wrapper/wrapper-ee-api/README.md +++ b/extensions/wrapper/wrapper-ee-api/README.md @@ -24,7 +24,7 @@ make available for use with our generated API clients. ## License -Apache License 2.0 - see [LICENSE](../../LICENSE) +Apache License 2.0 - see [LICENSE](../../../LICENSE) ## Contact diff --git a/extensions/wrapper/wrapper/README.md b/extensions/wrapper/wrapper/README.md index 3b12d1cf6..e078f3abf 100644 --- a/extensions/wrapper/wrapper/README.md +++ b/extensions/wrapper/wrapper/README.md @@ -22,7 +22,7 @@ endpoints. ## License -Apache License 2.0 - see [LICENSE](../../LICENSE) +Apache License 2.0 - see [LICENSE](../../../LICENSE) ## Contact From 893e301dc106a1cb388aa32383e092beccf5f7c3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 May 2023 13:33:24 +0200 Subject: [PATCH 5/8] build(deps): bump io.quarkus from 2.16.6.Final to 3.0.2.Final (#314) * build(deps): bump io.quarkus from 2.16.6.Final to 3.0.2.Final Bumps io.quarkus from 2.16.6.Final to 3.0.2.Final. --- updated-dependencies: - dependency-name: io.quarkus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * build(deps): bump io.quarkus.platform:quarkus-bom (#313) Bumps [io.quarkus.platform:quarkus-bom](https://github.com/quarkusio/quarkus-platform) from 2.16.6.Final to 3.0.2.Final. - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.16.6.Final...3.0.2.Final) --- updated-dependencies: - dependency-name: io.quarkus.platform:quarkus-bom dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump io.quarkus.platform:quarkus-bom (#313) Bumps [io.quarkus.platform:quarkus-bom](https://github.com/quarkusio/quarkus-platform) from 2.16.6.Final to 3.0.2.Final. - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.16.6.Final...3.0.2.Final) --- updated-dependencies: - dependency-name: io.quarkus.platform:quarkus-bom dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tim Berthold <75306992+tmberthold@users.noreply.github.com> --- extensions/wrapper/client-example/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/wrapper/client-example/build.gradle.kts b/extensions/wrapper/client-example/build.gradle.kts index e05979a3b..b62decb5d 100644 --- a/extensions/wrapper/client-example/build.gradle.kts +++ b/extensions/wrapper/client-example/build.gradle.kts @@ -1,6 +1,6 @@ plugins { java - id("io.quarkus") version "2.16.6.Final" + id("io.quarkus") version "3.0.2.Final" } repositories { @@ -10,7 +10,7 @@ repositories { val quarkusPlatformGroupId = "io.quarkus.platform" val quarkusPlatformArtifactId = "quarkus-bom" -val quarkusPlatformVersion = "2.16.6.Final" +val quarkusPlatformVersion = "3.0.2.Final" dependencies { implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")) From e6b8ee9009c8462d71a34984375175fe6cf2ad52 Mon Sep 17 00:00:00 2001 From: AnurosePrakash Date: Tue, 9 May 2023 12:14:25 +0200 Subject: [PATCH 6/8] chore refactor --- .../sovity/edc/extension/LastCommitInfo.java | 7 +-- .../extension/LastCommitInfoController.java | 3 +- .../edc/extension/LastCommitInfoService.java | 52 ++++++++----------- .../resources/jar-latest-build-date-info.txt | 0 .../controller/LastCommitInfoTest.java | 7 +-- .../resources/jar-latest-build-date-info.txt | 1 + 6 files changed, 30 insertions(+), 40 deletions(-) create mode 100644 extensions/last-commit-info/src/main/resources/jar-latest-build-date-info.txt create mode 100644 extensions/last-commit-info/src/test/resources/jar-latest-build-date-info.txt diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java index 7ffe5b924..f4ef4c247 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java @@ -20,11 +20,8 @@ @Getter @Setter public class LastCommitInfo { - private String envLastCommitInfo; - private String envLastBuildDate; + private String envLatestBuildDate; private String jarLastCommitInfo; - private String jarLastBuildDate; - - + private String jarLatestBuildDate; } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java index 48b622642..394031cc3 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java @@ -19,7 +19,6 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; -import java.io.IOException; @Produces({MediaType.APPLICATION_JSON}) @Path("/last-commit-info") @@ -32,7 +31,7 @@ public LastCommitInfoController(LastCommitInfoService lastCommitInfoService) { @GET @Produces(MediaType.APPLICATION_JSON) - public LastCommitInfo getLastCommitInfo() throws IOException { + public LastCommitInfo getLastCommitInfo() { return lastCommitInfoService.getLastCommitInfo(); } } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java index 3307a3ef7..52ed6199c 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java @@ -16,56 +16,48 @@ import org.eclipse.edc.spi.system.ServiceExtensionContext; -import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; import java.util.Scanner; -import java.util.jar.Attributes; -import java.util.jar.Manifest; public class LastCommitInfoService { private final ServiceExtensionContext context; + private String readFileInCurrentClassClasspath(String path) { + var classLoader = LastCommitInfoService.class.getClassLoader(); + var is = classLoader.getResourceAsStream(path); + var scanner = new Scanner(Objects.requireNonNull(is), StandardCharsets.UTF_8).useDelimiter("\\A"); + return scanner.hasNext() ? scanner.next() : ""; + } public LastCommitInfoService(ServiceExtensionContext context) { this.context = context; } - public LastCommitInfo getLastCommitInfo() throws IOException { - var result = new LastCommitInfo(); - result.setEnvLastCommitInfo(getEnvLastCommitInfo()); - result.setEnvLastBuildDate(getEnvLastCommitDate()); - - result.setJarLastCommitInfo(getJarInfo().get(0)); - result.setJarLastBuildDate(getJarInfo().get(1)); - return result; - } - - public List getJarInfo() throws IOException { - - var jarInfo = new ArrayList(); - var classLoader = Thread.currentThread().getContextClassLoader(); - var is = classLoader.getResourceAsStream("jar-last-commit-info.txt"); - var scanner = new Scanner(Objects.requireNonNull(is), StandardCharsets.UTF_8).useDelimiter("\\A"); - jarInfo.add(scanner.hasNext() ? scanner.next() : ""); - - Manifest manifest = new Manifest(is); - Attributes attributes = manifest.getMainAttributes(); - jarInfo.add(attributes.getValue("Build-Date")); - - return jarInfo; + public String getJarLastCommitInfo() { + return this.readFileInCurrentClassClasspath("jar-last-commit-info.txt"); } public String getEnvLastCommitInfo() { return context.getSetting("edc.last.commit.info", ""); } - public String getEnvLastCommitDate() { - return context.getSetting("edc.env.last.commit.date", ""); + public String getLatestJarBuildDate() { + return readFileInCurrentClassClasspath("jar-latest-build-date-info.txt"); } + public String getLatestEnvBuildDate() { + return context.getSetting("edc.env.latest.build.date", ""); + } + + public LastCommitInfo getLastCommitInfo() { + var lastCommitInfo = new LastCommitInfo(); + lastCommitInfo.setEnvLastCommitInfo(getEnvLastCommitInfo()); + lastCommitInfo.setJarLastCommitInfo(getJarLastCommitInfo()); + lastCommitInfo.setJarLatestBuildDate(getLatestJarBuildDate()); + lastCommitInfo.setEnvLatestBuildDate(getLatestEnvBuildDate()); + return lastCommitInfo; + } } diff --git a/extensions/last-commit-info/src/main/resources/jar-latest-build-date-info.txt b/extensions/last-commit-info/src/main/resources/jar-latest-build-date-info.txt new file mode 100644 index 000000000..e69de29bb diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java index 5b513cbc8..9a39b264f 100644 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java @@ -40,7 +40,7 @@ void setUp(EdcExtension extension) { "web.http.management.path", "/api/v1/data", "edc.api.auth.key", TestUtils.AUTH_KEY, "edc.last.commit.info", "test env commit message", - "edc.env.last.commit.date", "2023-05-08T15:30:00Z")); + "edc.env.latest.build.date", "2023-05-08T15:30:00Z")); } @Test @@ -57,8 +57,9 @@ void testEnvAndJar() { .contentType(ContentType.JSON); request.assertThat().body("envLastCommitInfo", equalTo("test env commit message")) - .body("envLastBuildDate", equalTo("2023-05-08T15:30:00Z")) - .body("jarLastCommitInfo", equalTo("test jar commit message\n")); + .body("envLatestBuildDate", equalTo("2023-05-08T15:30:00Z")) + .body("jarLastCommitInfo", equalTo("test jar commit message\n")) + .body("jarLatestBuildDate", equalTo("2023-05-08T15:30:00Z\n")); } } diff --git a/extensions/last-commit-info/src/test/resources/jar-latest-build-date-info.txt b/extensions/last-commit-info/src/test/resources/jar-latest-build-date-info.txt new file mode 100644 index 000000000..f35ee2969 --- /dev/null +++ b/extensions/last-commit-info/src/test/resources/jar-latest-build-date-info.txt @@ -0,0 +1 @@ +2023-05-08T15:30:00Z From 27b4c4015075be8cd59d26341f3d9d22d31f7a9c Mon Sep 17 00:00:00 2001 From: AnurosePrakash Date: Tue, 9 May 2023 12:29:03 +0200 Subject: [PATCH 7/8] chore refactor --- .../main/java/de/sovity/edc/extension/LastCommitInfo.java | 4 ++-- .../de/sovity/edc/extension/LastCommitInfoService.java | 8 ++++---- .../extension/version/controller/LastCommitInfoTest.java | 6 +++--- ...t-build-date-info.txt => jar-last-build-date-info.txt} | 0 4 files changed, 9 insertions(+), 9 deletions(-) rename extensions/last-commit-info/src/test/resources/{jar-latest-build-date-info.txt => jar-last-build-date-info.txt} (100%) diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java index f4ef4c247..492c18758 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java @@ -21,7 +21,7 @@ @Setter public class LastCommitInfo { private String envLastCommitInfo; - private String envLatestBuildDate; + private String envLastBuildDate; private String jarLastCommitInfo; - private String jarLatestBuildDate; + private String jarLastBuildDate; } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java index 52ed6199c..bc5a26627 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java @@ -44,11 +44,11 @@ public String getEnvLastCommitInfo() { } public String getLatestJarBuildDate() { - return readFileInCurrentClassClasspath("jar-latest-build-date-info.txt"); + return readFileInCurrentClassClasspath("jar-last-build-date-info.txt"); } public String getLatestEnvBuildDate() { - return context.getSetting("edc.env.latest.build.date", ""); + return context.getSetting("edc.last.build.date", ""); } public LastCommitInfo getLastCommitInfo() { @@ -56,8 +56,8 @@ public LastCommitInfo getLastCommitInfo() { lastCommitInfo.setEnvLastCommitInfo(getEnvLastCommitInfo()); lastCommitInfo.setJarLastCommitInfo(getJarLastCommitInfo()); - lastCommitInfo.setJarLatestBuildDate(getLatestJarBuildDate()); - lastCommitInfo.setEnvLatestBuildDate(getLatestEnvBuildDate()); + lastCommitInfo.setJarLastBuildDate(getLatestJarBuildDate()); + lastCommitInfo.setEnvLastBuildDate(getLatestEnvBuildDate()); return lastCommitInfo; } } diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java index 9a39b264f..2751594e3 100644 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java @@ -40,7 +40,7 @@ void setUp(EdcExtension extension) { "web.http.management.path", "/api/v1/data", "edc.api.auth.key", TestUtils.AUTH_KEY, "edc.last.commit.info", "test env commit message", - "edc.env.latest.build.date", "2023-05-08T15:30:00Z")); + "edc.last.build.date", "2023-05-08T15:30:00Z")); } @Test @@ -57,9 +57,9 @@ void testEnvAndJar() { .contentType(ContentType.JSON); request.assertThat().body("envLastCommitInfo", equalTo("test env commit message")) - .body("envLatestBuildDate", equalTo("2023-05-08T15:30:00Z")) + .body("envLastBuildDate", equalTo("2023-05-08T15:30:00Z")) .body("jarLastCommitInfo", equalTo("test jar commit message\n")) - .body("jarLatestBuildDate", equalTo("2023-05-08T15:30:00Z\n")); + .body("jarLastBuildDate", equalTo("2023-05-08T15:30:00Z\n")); } } diff --git a/extensions/last-commit-info/src/test/resources/jar-latest-build-date-info.txt b/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt similarity index 100% rename from extensions/last-commit-info/src/test/resources/jar-latest-build-date-info.txt rename to extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt From 5ff92ec764b01ccb171d945b386120ed29dbc54f Mon Sep 17 00:00:00 2001 From: AnurosePrakash Date: Tue, 9 May 2023 12:48:41 +0200 Subject: [PATCH 8/8] chore refactor --- .../de/sovity/edc/extension/LastCommitInfoService.java | 8 ++++---- .../extension/version/controller/LastCommitInfoTest.java | 2 +- .../src/test/resources/jar-last-build-date-info.txt | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java index bc5a26627..c90ae2ad2 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java @@ -43,11 +43,11 @@ public String getEnvLastCommitInfo() { return context.getSetting("edc.last.commit.info", ""); } - public String getLatestJarBuildDate() { + public String getJarLastBuildDate() { return readFileInCurrentClassClasspath("jar-last-build-date-info.txt"); } - public String getLatestEnvBuildDate() { + public String getEnvLastBuildDate() { return context.getSetting("edc.last.build.date", ""); } @@ -56,8 +56,8 @@ public LastCommitInfo getLastCommitInfo() { lastCommitInfo.setEnvLastCommitInfo(getEnvLastCommitInfo()); lastCommitInfo.setJarLastCommitInfo(getJarLastCommitInfo()); - lastCommitInfo.setJarLastBuildDate(getLatestJarBuildDate()); - lastCommitInfo.setEnvLastBuildDate(getLatestEnvBuildDate()); + lastCommitInfo.setJarLastBuildDate(getJarLastBuildDate()); + lastCommitInfo.setEnvLastBuildDate(getEnvLastBuildDate()); return lastCommitInfo; } } diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java index 2751594e3..36f4a14e9 100644 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java @@ -59,7 +59,7 @@ void testEnvAndJar() { request.assertThat().body("envLastCommitInfo", equalTo("test env commit message")) .body("envLastBuildDate", equalTo("2023-05-08T15:30:00Z")) .body("jarLastCommitInfo", equalTo("test jar commit message\n")) - .body("jarLastBuildDate", equalTo("2023-05-08T15:30:00Z\n")); + .body("jarLastBuildDate", equalTo("2023-05-09T15:30:00Z\n")); } } diff --git a/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt b/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt index f35ee2969..3f3faacba 100644 --- a/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt +++ b/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt @@ -1 +1 @@ -2023-05-08T15:30:00Z +2023-05-09T15:30:00Z