Skip to content

Commit

Permalink
Develop (#436)
Browse files Browse the repository at this point in the history
Co-authored-by: Yalz <[email protected]>
Co-authored-by: jonasbul <[email protected]>
Co-authored-by: Jonas Bulcke <[email protected]>
  • Loading branch information
4 people authored Dec 20, 2023
1 parent 9d78580 commit d020040
Show file tree
Hide file tree
Showing 98 changed files with 386 additions and 283 deletions.
33 changes: 20 additions & 13 deletions docs/_ldio/ldio-core/ldio-http-requester.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,29 @@ Different LDIO components use the Http Requester to make HTTP requests.
This requester supports the below config:


| Property | Description | Required | Default | Example | Supported values |
|:------------------------------------|:----------------------------------------------------------------------------------------------|:---------|:----------|:----------------------------|:----------------------------------------------|
| auth.type | The type of authentication required by the LDES server | No | NO_AUTH | OAUTH2_CLIENT_CREDENTIALS | NO_AUTH, API_KEY or OAUTH2_CLIENT_CREDENTIALS |
| auth.api-key | The api key when using auth.type 'API_KEY' | No | N/A | myKey | String |
| auth.api-key-header | The header for the api key when using auth.type 'API_KEY' | No | X-API-KEY | X-API-KEY | String |
| auth.client-id | The client identifier when using auth.type 'OAUTH2_CLIENT_CREDENTIALS' | No | N/A | myId | String |
| auth.client-secret | The client secret when using auth.type 'OAUTH2_CLIENT_CREDENTIALS' | No | N/A | mySecret | String |
| auth.token-endpoint | The token endpoint when using auth.type 'OAUTH2_CLIENT_CREDENTIALS' | No | N/A | http://localhost:8000/token | HTTP and HTTPS urls |
| retries.enabled | Indicates if the http client should retry http requests when the server cannot be reached. | No | true | true | true or false |
| retries.max | Max number of retries the http client should do when retries.enabled = true | No | 5 | 100 | Integer |
| retries.statuses-to-retry | Custom comma seperated list of http status codes that can trigger a retry in the http client. | No | N/A | 410,451 | Comma seperated list of Integers |
| rate-limit.enabled | Indicates if the http client should limit http requests when calling the server. | No | false | false | true or false |
| rate-limit.max-requests-per-minute | Max number of requests per minute the http client should do when rate-limit.enabled = true | No | 500 | 500 | Integer |
| Property | Description | Required | Default | Example | Supported values |
|:-----------------------------------|:-------------------------------------------------------------------------------------------------|:---------|:----------|:----------------------------|:----------------------------------------------|
| auth.type | The type of authentication required by the LDES server | No | NO_AUTH | OAUTH2_CLIENT_CREDENTIALS | NO_AUTH, API_KEY or OAUTH2_CLIENT_CREDENTIALS |
| auth.api-key | The api key when using auth.type 'API_KEY' | No | N/A | myKey | String |
| auth.api-key-header | The header for the api key when using auth.type 'API_KEY' | No | X-API-KEY | X-API-KEY | String |
| auth.client-id | The client identifier when using auth.type 'OAUTH2_CLIENT_CREDENTIALS' | No | N/A | myId | String |
| auth.client-secret | The client secret when using auth.type 'OAUTH2_CLIENT_CREDENTIALS' | No | N/A | mySecret | String |
| auth.token-endpoint | The token endpoint when using auth.type 'OAUTH2_CLIENT_CREDENTIALS' | No | N/A | http://localhost:8000/token | HTTP and HTTPS urls |
| retries.enabled | Indicates if the http client should retry http requests when the server cannot be reached. | No | true | true | true or false |
| retries.max | Max number of retries the http client should do when retries.enabled = true | No | 5 | 100 | Integer |
| retries.statuses-to-retry | Custom comma seperated list of http status codes that can trigger a retry in the http client. | No | N/A | 410,451 | Comma seperated list of Integers |
| rate-limit.enabled | Indicates if the http client should limit http requests when calling the server. | No | false | false | true or false |
| rate-limit.max-requests-per-minute | Max number of requests per minute the http client should do when rate-limit.enabled = true | No | 500 | 500 | Integer |
| http.headers.[].key/value | A list of custom http headers can be added. A key and value has to be provided for every header. | No | N/A | role | String |

```yaml
config:
http:
headers:
- key: role
value: developer
- key: alt-role
value: programmer
auth:
type: API_KEY
api-key: my-secret
Expand Down
2 changes: 1 addition & 1 deletion ldi-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes</groupId>
<artifactId>linked-data-interactions</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ldi-core/file-archiving/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-core</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>

<artifactId>file-archiving</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/geojson-to-wkt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-core</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>

<artifactId>geojson-to-wkt</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/json-to-ld-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-core</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>

<artifactId>json-to-ld-adapter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/ldes-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-core</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ldi-core/ldes-client/starting-node/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ldes-client</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes.client</groupId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>starting-node</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ldes.client.startingtreenode;

import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.noauth.DefaultConfig;
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.services.RequestExecutorFactory;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
Expand All @@ -10,16 +10,18 @@
import ldes.client.startingtreenode.exception.StartingNodeNotFoundException;
import org.apache.jena.riot.RDFLanguages;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class StartingTreeNodeFinderSteps {

private final RequestExecutorFactory requestExecutorFactory = new RequestExecutorFactory();
private StartingTreeNodeFinder startingTreeNodeFinder;
private StartingNodeRequest startingNodeRequest;

@Given("I have a StartingTreeNodeFinder$")
public void initializeCalculator() {
startingTreeNodeFinder = new StartingTreeNodeFinder(new DefaultConfig().createRequestExecutor());
startingTreeNodeFinder = new StartingTreeNodeFinder(requestExecutorFactory.createNoAuthExecutor());
}

@Then("the starting Tree Node of the LDES Stream is the url of the View: {string}")
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/ldes-client/tree-node-fetcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ldes-client</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes.client</groupId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tree-node-fetcher</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ldes.client.treenodefetcher;

import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.noauth.DefaultConfig;
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.services.RequestExecutorFactory;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
Expand All @@ -14,13 +14,14 @@

public class TreeNodeFetcherSteps {

private final RequestExecutorFactory requestExecutorFactory = new RequestExecutorFactory();
private TreeNodeFetcher treeNodeFetcher;
private TreeNodeRequest treeNodeRequest;
private TreeNodeResponse treeNodeResponse;

@Given("I have a TreeNodeFetcher")
public void initializeCalculator() {
treeNodeFetcher = new TreeNodeFetcher(new DefaultConfig().createRequestExecutor());
treeNodeFetcher = new TreeNodeFetcher(requestExecutorFactory.createNoAuthExecutor());
}

@When("I create a TreeNodeRequest with Lang {string} and url {string}")
Expand All @@ -41,7 +42,7 @@ public void theObtainedTreeNodeHasMembersAndRelations(int numberOfMembers, int n

@When("I create a TreeNodeRequest with Lang {string} and url {string} and etag {string}")
public void iCreateATreeNodeRequestWithLangAndUrlAndEtag(String lang, String url, String etag) {
treeNodeRequest = new TreeNodeRequest(url, RDFLanguages.nameToLang(lang), etag.equals("") ? null : etag);
treeNodeRequest = new TreeNodeRequest(url, RDFLanguages.nameToLang(lang), etag.isEmpty() ? null : etag);
}

@Then("An UnSupportedOperationException is thrown")
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/ldes-client/tree-node-supplier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ldes-client</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes.client</groupId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tree-node-supplier</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ldes.client.performance;

import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.RequestExecutor;
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.noauth.DefaultConfig;
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.services.RequestExecutorFactory;
import ldes.client.treenodesupplier.TreeNodeProcessor;
import ldes.client.treenodesupplier.domain.services.MemberRepositoryFactory;
import ldes.client.treenodesupplier.domain.services.TreeNodeRecordRepositoryFactory;
Expand All @@ -18,6 +18,8 @@

class TreeNodeProcessorFactory {

private final RequestExecutorFactory requestExecutorFactory = new RequestExecutorFactory();

TreeNodeProcessor createTreeNodeProcessor(StatePersistenceStrategy statePersistenceStrategy, String url) {
final LdesMetaData ldesMetaData = new LdesMetaData(url, Lang.TURTLE);
final StatePersistence statePersistence = switch (statePersistenceStrategy) {
Expand All @@ -26,7 +28,7 @@ TreeNodeProcessor createTreeNodeProcessor(StatePersistenceStrategy statePersiste
case FILE -> createFileStatePersistence();
case POSTGRES -> createPostgresPersistence();
};
final RequestExecutor requestExecutor = new DefaultConfig().createRequestExecutor();
final RequestExecutor requestExecutor = requestExecutorFactory.createNoAuthExecutor();
return new TreeNodeProcessor(ldesMetaData, statePersistence, requestExecutor);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ldes.client.treenodesupplier;

import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.noauth.DefaultConfig;
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.services.RequestExecutorFactory;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
Expand All @@ -23,6 +23,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MemberSupplierSteps {
private final RequestExecutorFactory requestExecutorFactory = new RequestExecutorFactory();
private TreeNodeProcessor treeNodeProcessor;
private TreeNodeRecordRepository treeNodeRecordRepository;
private MemberRepository memberRepository;
Expand All @@ -33,7 +34,7 @@ public class MemberSupplierSteps {

// Multi MemberSupplier
private final MemberSupplier[] memberSuppliers = new MemberSupplier[2];
private SuppliedMember[] suppliedMembers = new SuppliedMember[2];
private final SuppliedMember[] suppliedMembers = new SuppliedMember[2];

@When("I request one member from the MemberSupplier")
public void iRequestOneMemberFromTheMemberSupplier() {
Expand All @@ -60,7 +61,7 @@ public void aStartingUrl(String url) {
public void iCreateAProcessor() {
treeNodeProcessor = new TreeNodeProcessor(ldesMetaData,
new StatePersistence(memberRepository, treeNodeRecordRepository),
new DefaultConfig().createRequestExecutor());
requestExecutorFactory.createNoAuthExecutor());
}

@Then("Member {string} is processed")
Expand Down Expand Up @@ -161,10 +162,10 @@ private StatePersistence defineStatePersistence(String persistenceStrategy) {
public void aStatePersistenceStrategyProcessorAndAStatePersistenceStrategyProcessor(String arg0, String arg1) {
memberSuppliers[0] = new MemberSupplier(new TreeNodeProcessor(ldesMetaData,
defineStatePersistence(arg0),
new DefaultConfig().createRequestExecutor()), false);
requestExecutorFactory.createNoAuthExecutor()), false);
memberSuppliers[1] = new MemberSupplier(new TreeNodeProcessor(ldesMetaData,
defineStatePersistence(arg0),
new DefaultConfig().createRequestExecutor()), false);
requestExecutorFactory.createNoAuthExecutor()), false);
}

@When("I request one member from the MemberSuppliers")
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/ldi-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-core</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>

<artifactId>ldi-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/ngsiv2-to-ld-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-core</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>

<artifactId>ngsiv2-to-ld-adapter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>linked-data-interactions</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes</groupId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ldi-core/rdf-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ldi-core</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ldi-core/repository-materialiser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<artifactId>ldi-core</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion ldi-core/request-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ldi-core</artifactId>
<groupId>be.vlaanderen.informatievlaanderen.ldes.ldi</groupId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>request-executor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.RequestExecutor;
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.RequestExecutorSupplier;
import org.apache.http.Header;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;

import java.util.Collection;

import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.oauth.OAuth20Service;
Expand All @@ -14,11 +17,13 @@

public class ClientCredentialsConfig implements RequestExecutorSupplier {

private final Collection<Header> headers;
private final String clientId;
private final String secret;
private final String tokenEndpoint;

public ClientCredentialsConfig(String clientId, String secret, String tokenEndpoint) {
public ClientCredentialsConfig(Collection<Header> headers, String clientId, String secret, String tokenEndpoint) {
this.headers = headers;
this.clientId = notNull(clientId);
this.secret = notNull(secret);
this.tokenEndpoint = notNull(tokenEndpoint);
Expand All @@ -31,7 +36,7 @@ public RequestExecutor createRequestExecutor() {
private OAuth20Service createService() {
final RequestConfig clientConfig = RequestConfig.custom().setRedirectsEnabled(false).build();
final ApacheHttpClient apacheHttpClient = new ApacheHttpClient(
HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig).build());
HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig).setDefaultHeaders(headers).build());
final DefaultApi20 authorizationApi = createAuthorizationApi(tokenEndpoint);
return new ServiceBuilder(clientId)
.apiSecret(secret)
Expand Down
Loading

0 comments on commit d020040

Please sign in to comment.