-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: api wrapper integration * fix: api wrapper integration * chore: checkstyle * chore: checkstyle
- Loading branch information
1 parent
72c2e89
commit 763227f
Showing
28 changed files
with
960 additions
and
128 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...roker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/ApiInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.ext.brokerserver.api; | ||
|
||
import io.swagger.v3.oas.annotations.ExternalDocumentation; | ||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.info.License; | ||
|
||
@OpenAPIDefinition( | ||
info = @Info( | ||
title = "Broker Server API", | ||
version = "0.0.0", | ||
description = "Broker Server API for the Broker Server built by sovity.", | ||
contact = @Contact( | ||
name = "sovity GmbH", | ||
email = "[email protected]", | ||
url = "https://github.com/sovity/edc-broker-server-extension/issues/new/choose" | ||
), | ||
license = @License( | ||
name = "Apache 2.0", | ||
url = "https://github.com/sovity/edc-broker-server-extension/blob/main/LICENSE" | ||
) | ||
), | ||
externalDocs = @ExternalDocumentation( | ||
description = "Broker Server API in sovity/edc-broker-server-extension", | ||
url = "https://github.com/sovity/edc-broker-server-extension/tree/main/extensions/broker-server-api" | ||
) | ||
) | ||
public interface ApiInformation { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<!-- PROJECT LOGO --> | ||
<br /> | ||
<div align="center"> | ||
<a href="https://github.com/sovity/edc-extensions"> | ||
<img src="https://raw.githubusercontent.com/sovity/edc-ui/main/src/assets/images/sovity_logo.svg" alt="Logo" width="300"> | ||
</a> | ||
|
||
<h3 align="center">EDC-Connector Extension:<br />API Wrapper & API Clients:<br />Java API Client</h3> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/sovity/edc-extensions/issues/new?template=bug_report.md">Report Bug</a> | ||
· | ||
<a href="https://github.com/sovity/edc-extensions/issues/new?template=feature_request.md">Request Feature</a> | ||
</p> | ||
</div> | ||
|
||
## About this component | ||
|
||
Java API Client Library to be imported and used in arbitrary applications like use-case backends. | ||
|
||
An example project using this client can be found [here](../client-example). | ||
|
||
## Installation | ||
|
||
```xml | ||
<!-- Requires the GitHub Maven Registry --> | ||
<dependency> | ||
<groupId>de.sovity.edc</groupId> | ||
<artifactId>client</artifactId> | ||
<version>${sovity-edc-extensions.version}</version> | ||
</dependency> | ||
``` | ||
|
||
## Usage | ||
|
||
### Example Using API Key Auth | ||
|
||
```java | ||
import de.sovity.edc.client.EdcClient; | ||
import de.sovity.edc.ext.brokerserver.client.gen.model.KpiResult; | ||
|
||
/** | ||
* Example using a sovity Community Edition EDC Connector | ||
*/ | ||
public class WrapperClientExample { | ||
|
||
public static final String CONNECTOR_ENDPOINT = "http://localhost:11002/api/v1/management"; | ||
public static final String CONNECTOR_API_KEY = "..."; | ||
|
||
public static void main(String[] args) { | ||
// Configure Client | ||
EdcClient client = EdcClient.builder() | ||
.managementApiUrl(CONNECTOR_ENDPOINT) | ||
.managementApiKey(CONNECTOR_API_KEY) | ||
.build(); | ||
|
||
// EDC API Wrapper APIs are now available for use | ||
KpiResult kpiResult = client.useCaseApi().kpiEndpoint(); | ||
System.out.println(kpiResult); | ||
} | ||
} | ||
|
||
``` | ||
|
||
### Example Using OAuth2 Client Credentials | ||
|
||
```java | ||
import de.sovity.edc.client.EdcClient; | ||
import de.sovity.edc.ext.brokerserver.client.gen.model.KpiResult; | ||
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 | ||
*/ | ||
public class WrapperClientExample { | ||
|
||
public static final String CONNECTOR_ENDPOINT = | ||
"https://{{your-connector}}.prod-sovity.azure.sovity.io/control/data"; | ||
public static final String CLIENT_ID = "{{your-connector}}-app"; | ||
public static final String CLIENT_SECRET = "..."; | ||
|
||
public static void main(String[] args) { | ||
// Configure Client | ||
EdcClient client = EdcClient.builder() | ||
.managementApiUrl(CONNECTOR_ENDPOINT) | ||
.oauth2ClientCredentials(OAuth2ClientCredentials.builder() | ||
.tokenUrl(SovityKeycloakUrl.PRODUCTION) | ||
.clientId(CLIENT_ID) | ||
.clientSecret(CLIENT_SECRET) | ||
.build()) | ||
.build(); | ||
|
||
// EDC API Wrapper APIs are now available for use | ||
KpiResult kpiResult = client.useCaseApi().kpiEndpoint(); | ||
System.out.println(kpiResult); | ||
} | ||
} | ||
``` | ||
|
||
## License | ||
|
||
Apache License 2.0 - see [LICENSE](../../LICENSE) | ||
|
||
## Contact | ||
|
||
sovity GmbH - [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
val edcVersion: String by project | ||
val edcGroup: String by project | ||
val restAssured: String by project | ||
val assertj: String by project | ||
|
||
|
||
plugins { | ||
`java-library` | ||
`maven-publish` | ||
id("org.openapi.generator") version "6.6.0" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
// By using a separate configuration we can skip having the Extension Jar in our runtime classpath | ||
val openapiYaml = configurations.create("openapiGenerator") | ||
|
||
dependencies { | ||
// We only need the openapi.yaml file from this dependency | ||
openapiYaml(project(":extensions:broker-server-api:api")) { | ||
isTransitive = false | ||
} | ||
|
||
// Generated Client's Dependencies | ||
implementation("io.swagger:swagger-annotations:1.6.11") | ||
implementation("com.google.code.findbugs:jsr305:3.0.2") | ||
implementation("com.squareup.okhttp3:okhttp:4.11.0") | ||
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0") | ||
implementation("com.google.code.gson:gson:2.10.1") | ||
implementation("io.gsonfire:gson-fire:1.8.5") | ||
implementation("org.openapitools:jackson-databind-nullable:0.2.6") | ||
implementation("org.apache.commons:commons-lang3:3.12.0") | ||
implementation("jakarta.annotation:jakarta.annotation-api:1.3.5") | ||
|
||
// Lombok | ||
compileOnly("org.projectlombok:lombok:1.18.28") | ||
annotationProcessor("org.projectlombok:lombok:1.18.28") | ||
|
||
testImplementation("${edcGroup}:control-plane-core:${edcVersion}") | ||
testImplementation("${edcGroup}:junit:${edcVersion}") | ||
testImplementation("${edcGroup}:http:${edcVersion}") | ||
testImplementation(project(":extensions:broker-server-api:api")) | ||
testImplementation("io.rest-assured:rest-assured:${restAssured}") | ||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") | ||
testImplementation("org.assertj:assertj-core:${assertj}") | ||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3") | ||
} | ||
|
||
tasks.getByName<Test>("test") { | ||
useJUnitPlatform() | ||
} | ||
|
||
// Extract the openapi file from the JAR | ||
val openapiFile = "broker-server.yaml" | ||
task<Copy>("extractOpenapiYaml") { | ||
dependsOn(openapiYaml) | ||
into("${project.buildDir}") | ||
from(zipTree(openapiYaml.singleFile)) { | ||
include("broker-server.yaml") | ||
} | ||
} | ||
|
||
tasks.getByName<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerate") { | ||
dependsOn("extractOpenapiYaml") | ||
generatorName.set("java") | ||
configOptions.set(mutableMapOf( | ||
"invokerPackage" to "de.sovity.edc.ext.brokerserver.client.gen", | ||
"apiPackage" to "de.sovity.edc.ext.brokerserver.client.gen.api", | ||
"modelPackage" to "de.sovity.edc.ext.brokerserver.client.gen.model", | ||
"caseInsensitiveResponseHeaders" to "true", | ||
"additionalModelTypeAnnotations" to "@lombok.AllArgsConstructor\n@lombok.Builder", | ||
"annotationLibrary" to "swagger1", | ||
"hideGenerationTimestamp" to "true", | ||
"useRuntimeException" to "true", | ||
)) | ||
|
||
inputSpec.set("${project.buildDir}/${openapiFile}") | ||
outputDir.set("${project.buildDir}/generated/client-project") | ||
} | ||
|
||
task<Copy>("postprocessGeneratedClient") { | ||
dependsOn("openApiGenerate") | ||
from("${project.buildDir}/generated/client-project/src/main/java") | ||
|
||
// @lombok.Builder clashes with the following generated model file. | ||
// It is the base class for OAS3 polymorphism via allOf/anyOf, which we won't use anyway. | ||
exclude("**/AbstractOpenApiSchema.java") | ||
|
||
// The Jax-RS dependency suggested by the generated project was causing issues with quarkus. | ||
// It was again only required for the polymorphism, which we won't use anyway. | ||
filter { if (it == "import javax.ws.rs.core.GenericType;") "" else it } | ||
|
||
into("${project.buildDir}/generated/sources/openapi/java/main") | ||
} | ||
sourceSets["main"].java.srcDir("${project.buildDir}/generated/sources/openapi/java/main") | ||
|
||
checkstyle { | ||
// Checkstyle loathes the generated files | ||
// TODO make checkstyle skip generated files only | ||
this.sourceSets = emptyList() | ||
} | ||
|
||
|
||
tasks.getByName<JavaCompile>("compileJava") { | ||
dependsOn("postprocessGeneratedClient") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
withSourcesJar() | ||
withJavadocJar() | ||
} | ||
|
||
tasks.withType<Javadoc> { | ||
val fullOptions = this.options as StandardJavadocDocletOptions | ||
fullOptions.tags = listOf("http.response.details:a:Http Response Details") | ||
fullOptions.addStringOption("Xdoclint:none", "-quiet") | ||
} | ||
|
||
val sovityEdcGroup: String by project | ||
group = sovityEdcGroup | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>(project.name) { | ||
from(components["java"]) | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
extensions/broker-server-api/client/src/main/java/de/sovity/edc/client/EdcClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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; | ||
|
||
import de.sovity.edc.ext.brokerserver.client.gen.api.BrokerServerApi; | ||
import lombok.Value; | ||
import lombok.experimental.Accessors; | ||
|
||
/** | ||
* API Client for our EDC API Wrapper. | ||
*/ | ||
@Value | ||
@Accessors(fluent = true) | ||
public class EdcClient { | ||
BrokerServerApi brokerServerApi; | ||
|
||
public static EdcClientBuilder builder() { | ||
return new EdcClientBuilder(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
extensions/broker-server-api/client/src/main/java/de/sovity/edc/client/EdcClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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; | ||
|
||
import de.sovity.edc.client.oauth2.OAuth2ClientCredentials; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
|
||
@Getter | ||
@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); | ||
} | ||
} |
Oops, something went wrong.