-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Gateway): replaced manual JWT checking with toke validation endp…
…oint call
- Loading branch information
Showing
23 changed files
with
372 additions
and
398 deletions.
There are no files selected for viewing
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
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,20 @@ | ||
# Control Plane Adapter API (EDR management) | ||
|
||
This module provide a new APIs on top of the EDC management APIs for dealing with EDRs token. | ||
|
||
The APIs are mounted in the same context of the `management` APIs. So no additional configuration is required. | ||
|
||
The base path of the API will be `<mgmtContext>/adapter/edrs` | ||
|
||
This module for now provides three APIs: | ||
|
||
- Initiating an EDR negotiation token | ||
- Fetching the available EDRs | ||
- Fetching the single EDR | ||
|
||
The initiate negotiation EDR leverage the callbacks mechanism introduced in the latest EDC, and it handles | ||
the contract negotiation and the transfer request in one API call. Once the transfer has been completed | ||
the provider will return the EDR that will be stored into the consumer EDR store/cache. Users can interact | ||
with the EDR store/cache for fetching the EDR and then requesting the data, or can use the `proxy` API described [here](../dataplane-proxy/edc-dataplane-proxy-consumer-api/README.md) | ||
|
||
An overview on how to use the EDR APIs is available [here](../../docs/samples/edr-api-overview/edr-api-overview.md) |
25 changes: 25 additions & 0 deletions
25
edc-extensions/dataplane-proxy/edc-dataplane-proxy-consumer-api/README.md
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,25 @@ | ||
# DataPlane Proxy Consumer API | ||
|
||
This is an API extension that interacts with the EDR/cache for directly fetching the data | ||
without knowing the EDR. | ||
|
||
It contains only one endpoint with `POST` for fetching data: | ||
|
||
The path is `<proxyContext>/aas/request` and the body is something like this example: | ||
|
||
```json | ||
{ | ||
"assetId": "1", | ||
"endpointUrl": "http://localhost:8181/api/gateway/aas/test" | ||
} | ||
``` | ||
|
||
The body should contain the `assetId` or the `transferProcessId` which identify the data that we want to fetch | ||
and an `endpointUrl` which is the provider gateway on which the data is available. More info [here](../edc-dataplane-proxy-provider-api/README.md) on the gateway. | ||
|
||
## Configuration | ||
|
||
| Key | Required | Default | Description | | ||
|---------------------------------|----------|--------------------------------------------| | ||
| web.http.proxy.port | | 8186 | | | ||
| web.http.proxy.path | | /proxy | | |
23 changes: 23 additions & 0 deletions
23
edc-extensions/dataplane-proxy/edc-dataplane-proxy-provider-api/README.md
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,23 @@ | ||
# DataPlane Proxy Provider API | ||
|
||
This extension provide additional dataplane extension for proxying requests to backends. | ||
The configuration of the proxy can be found [here](../edc-dataplane-proxy-provider-core/README.md) | ||
|
||
The provider proxy is mounted into the EDC default context, and it's available in the path `<defaultContext>/gateway` | ||
|
||
The proxy will look for subPath in the request and match the subpath with the configured ones and forward | ||
the rest of the path and query parameters. | ||
|
||
For example: | ||
|
||
with this URL `http://localhost:8181/api/gateway/aas/test` it will look for the `aas` alias in the configuration, | ||
and it will compose the final url to call based on that configuration appending to it the remaining part of the path and query | ||
parameters. | ||
|
||
When the proxy receive a request, it must contain the EDR, which will be decoded with the `token` validation endpoint. | ||
|
||
## Configuration | ||
|
||
| Key | Required | Default | Description | | ||
|---------------------------------|----------|----------------------------------------------------------------------------------------| | ||
| tx.dpf.provider.proxy.thread.pool | | 10 | Thread pool size for the provider data plane proxy gateway | |
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
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
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
67 changes: 67 additions & 0 deletions
67
...ractusx/edc/dataplane/proxy/provider/api/validation/ProxyProviderDataAddressResolver.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,67 @@ | ||
/* | ||
* Copyright (c) 2022 Amadeus | ||
* | ||
* 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: | ||
* Amadeus - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.dataplane.proxy.provider.api.validation; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import okhttp3.Request; | ||
import org.eclipse.edc.connector.dataplane.spi.resolver.DataAddressResolver; | ||
import org.eclipse.edc.spi.http.EdcHttpClient; | ||
import org.eclipse.edc.spi.result.Result; | ||
import org.eclipse.edc.spi.types.domain.DataAddress; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class ProxyProviderDataAddressResolver implements DataAddressResolver { | ||
|
||
private final EdcHttpClient httpClient; | ||
private final String endpoint; | ||
private final ObjectMapper mapper; | ||
|
||
public ProxyProviderDataAddressResolver(EdcHttpClient httpClient, String endpoint, ObjectMapper mapper) { | ||
this.httpClient = httpClient; | ||
this.endpoint = endpoint; | ||
this.mapper = mapper; | ||
} | ||
|
||
/** | ||
* Resolves access token received in input of Data Plane public API (consumer pull) into the {@link DataAddress} | ||
* of the requested data. | ||
* | ||
* @param token Access token received in input of the Data Plane public API | ||
* @return Data address | ||
*/ | ||
@Override | ||
public Result<DataAddress> resolve(String token) { | ||
var request = new Request.Builder().url(endpoint).header(HttpHeaders.AUTHORIZATION, token).get().build(); | ||
try (var response = httpClient.execute(request)) { | ||
var body = response.body(); | ||
var stringBody = body != null ? body.string() : null; | ||
if (stringBody == null) { | ||
return Result.failure("Token validation server returned null body"); | ||
} | ||
|
||
if (response.isSuccessful()) { | ||
return Result.success(mapper.readValue(stringBody, DataAddress.class)); | ||
} else { | ||
return Result.failure(format("Call to token validation sever failed: %s - %s. %s", response.code(), response.message(), stringBody)); | ||
} | ||
} catch (IOException e) { | ||
return Result.failure("Unhandled exception occurred during call to token validation server: " + e.getMessage()); | ||
} | ||
} | ||
} |
Oops, something went wrong.