Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "org.eclipse.dataplane-core"
version = "0.0.8-SNAPSHOT"
version = "0.0.9-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/eclipse/dataplane/Dataplane.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private Result<Void> notifyControlPlane(String action, DataFlow dataFlow, Object

controlPlaneStore.findById(dataFlow.getControlplaneId())
.compose(controlPlane -> {
var authorizationProfile = controlPlane.authorization();
var authorizationProfile = controlPlane.getAuthorization();
if (authorizationProfile != null) {
var authorization = authorizations.get(authorizationProfile.getType());
return authorization.authorizationHeader(authorizationProfile);
Expand Down Expand Up @@ -386,9 +386,10 @@ public ControlPlaneStore controlPlaneStore() {
}

public Result<Void> registerControlPlane(ControlPlaneRegistrationMessage message) {
for (var auth : message.authorization()) {
if (!authorizations.containsKey(auth.getType())) {
return Result.failure(new AuthorizationNotSupported(auth));
var authorization = message.authorization();
if (authorization != null) {
if (!authorizations.containsKey(authorization.getType())) {
return Result.failure(new AuthorizationNotSupported(authorization));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
import org.eclipse.dataplane.domain.registration.AuthorizationProfile;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class ControlPlane {

private String id;
private URI endpoint;
private final List<AuthorizationProfile> authorizations = new ArrayList<>();
private AuthorizationProfile authorization;

public String getId() {
return id;
Expand All @@ -40,12 +38,8 @@ public static ControlPlane.Builder newInstance() {
return new ControlPlane.Builder();
}

public List<AuthorizationProfile> getAuthorizations() {
return authorizations;
}

public AuthorizationProfile authorization() {
return getAuthorizations().stream().findAny().orElse(null);
public AuthorizationProfile getAuthorization() {
return authorization;
}

@JsonPOJOBuilder
Expand All @@ -72,8 +66,8 @@ public Builder endpoint(URI endpoint) {
return this;
}

public Builder authorization(List<AuthorizationProfile> authorizations) {
controlPlane.authorizations.addAll(authorizations);
public Builder authorization(AuthorizationProfile authorization) {
controlPlane.authorization = authorization;
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
package org.eclipse.dataplane.domain.registration;

import java.net.URI;
import java.util.List;

import static java.util.Collections.emptyList;

public record ControlPlaneRegistrationMessage(
String controlplaneId,
URI endpoint,
List<AuthorizationProfile> authorization
AuthorizationProfile authorization
) {
public ControlPlaneRegistrationMessage(String controlplaneId, URI endpoint) {
this(controlplaneId, endpoint, emptyList());
this(controlplaneId, endpoint, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.util.List;
import java.util.UUID;

import static io.restassured.RestAssured.given;
Expand Down Expand Up @@ -115,7 +114,7 @@ void shouldReplaceControlPlane_whenSecondCall() {
void shouldReturnBadRequest_whenRequestedAuthMethodNotSupported() {
var controlPlaneId = UUID.randomUUID().toString();
var authorization = new AuthorizationProfile("unsupported");
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, List.of(authorization));
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, authorization);

given()
.contentType(ContentType.JSON)
Expand All @@ -128,12 +127,11 @@ void shouldReturnBadRequest_whenRequestedAuthMethodNotSupported() {
.statusCode(400);
}


@Test
void shouldRegisterAuthorizationType() {
var controlPlaneId = UUID.randomUUID().toString();
var authorization = new AuthorizationProfile("token");
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, List.of(authorization));
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, authorization);

given()
.contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -103,7 +102,7 @@ void shouldCommunicateWithControlPlaneUsingOauth2Authorization() {
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
controlplaneId,
controlPlane.consumerCallbackAddress(),
List.of(oauth2AuthorizationProfile())
oauth2AuthorizationProfile()
);
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.util.List;
import java.util.UUID;

import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -74,7 +73,7 @@ void shouldCommunicateWithControlPlaneUsingRegisteredAuthorization() {
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
"control-plane-id",
controlPlane.consumerCallbackAddress(),
List.of(TestAuthorization.createAuthorizationProfile("data-plane-id"))
TestAuthorization.createAuthorizationProfile("data-plane-id")
);
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);

Expand All @@ -96,7 +95,7 @@ void shouldGetUnauthorized_whenControlPlaneIsNotAuthenticated() {
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
"unmatching-control-plane-id",
controlPlane.consumerCallbackAddress(),
List.of(TestAuthorization.createAuthorizationProfile("data-plane-id"))
TestAuthorization.createAuthorizationProfile("data-plane-id")
);
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);

Expand All @@ -113,7 +112,7 @@ void shouldGetUnauthorized_withDataPlaneIsNotAuthenticated() {
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
"control-plane-id",
controlPlane.consumerCallbackAddress(),
List.of(TestAuthorization.createAuthorizationProfile("data-plane-id"))
TestAuthorization.createAuthorizationProfile("data-plane-id")
);
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

Expand Down Expand Up @@ -144,7 +143,7 @@ private class ConsumerDataPlane {


ConsumerDataPlane() {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("consumer"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("consumer")));
try {
storage = Files.createTempDirectory("consumer-storage");
} catch (IOException e) {
Expand Down Expand Up @@ -180,7 +179,7 @@ private class ProviderDataPlane {
private final int filesToBeCreated;

ProviderDataPlane(int fileToBeCreated) {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("provider"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("provider")));
this.filesToBeCreated = fileToBeCreated;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -171,7 +170,7 @@ private static class ProviderDataPlane {
.build();

ProviderDataPlane() {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("provider"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("provider")));
}

private Result<DataFlow> onStart(DataFlow dataFlow) {
Expand Down Expand Up @@ -213,7 +212,7 @@ private static class ConsumerDataPlane {
.build();

ConsumerDataPlane() {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("consumer"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("consumer")));
}

public void completePreparation(String dataFlowId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -171,7 +170,7 @@ private static class ConsumerDataPlane {


ConsumerDataPlane() {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("consumer"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("consumer")));
try {
storage = Files.createTempDirectory("consumer-storage");
} catch (IOException e) {
Expand Down Expand Up @@ -235,7 +234,7 @@ private static class ProviderDataPlane {
private final Map<String, ScheduledFuture<?>> flows = new HashMap<>();

ProviderDataPlane() {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("provider"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("provider")));
}

public Object controller() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -114,7 +113,7 @@ private static class ProviderDataPlane {
.build();

ProviderDataPlane() {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("provider"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("provider")));
}

private Result<DataFlow> onStart(DataFlow dataFlow) {
Expand Down Expand Up @@ -160,7 +159,7 @@ private static class ConsumerDataPlane {
private final Map<String, DataAddress> destinations = new HashMap<>();

ConsumerDataPlane() {
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), List.of(createAuthorizationProfile("consumer"))));
sdk.registerControlPlane(new ControlPlaneRegistrationMessage("control-plane-id", URI.create("http://localhost:any"), createAuthorizationProfile("consumer")));
}

private Result<DataFlow> onPrepare(DataFlow dataFlow) {
Expand Down