Skip to content

Commit 32c4417

Browse files
authored
feat: set authorization as single object in registration message (#66)
1 parent 7784da3 commit 32c4417

11 files changed

Lines changed: 27 additions & 43 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "org.eclipse.dataplane-core"
11-
version = "0.0.8-SNAPSHOT"
11+
version = "0.0.9-SNAPSHOT"
1212

1313
repositories {
1414
mavenCentral()

src/main/java/org/eclipse/dataplane/Dataplane.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private Result<Void> notifyControlPlane(String action, DataFlow dataFlow, Object
352352

353353
controlPlaneStore.findById(dataFlow.getControlplaneId())
354354
.compose(controlPlane -> {
355-
var authorizationProfile = controlPlane.authorization();
355+
var authorizationProfile = controlPlane.getAuthorization();
356356
if (authorizationProfile != null) {
357357
var authorization = authorizations.get(authorizationProfile.getType());
358358
return authorization.authorizationHeader(authorizationProfile);
@@ -386,9 +386,10 @@ public ControlPlaneStore controlPlaneStore() {
386386
}
387387

388388
public Result<Void> registerControlPlane(ControlPlaneRegistrationMessage message) {
389-
for (var auth : message.authorization()) {
390-
if (!authorizations.containsKey(auth.getType())) {
391-
return Result.failure(new AuthorizationNotSupported(auth));
389+
var authorization = message.authorization();
390+
if (authorization != null) {
391+
if (!authorizations.containsKey(authorization.getType())) {
392+
return Result.failure(new AuthorizationNotSupported(authorization));
392393
}
393394
}
394395

src/main/java/org/eclipse/dataplane/domain/controlplane/ControlPlane.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
import org.eclipse.dataplane.domain.registration.AuthorizationProfile;
1919

2020
import java.net.URI;
21-
import java.util.ArrayList;
22-
import java.util.List;
2321
import java.util.Objects;
2422

2523
public class ControlPlane {
2624

2725
private String id;
2826
private URI endpoint;
29-
private final List<AuthorizationProfile> authorizations = new ArrayList<>();
27+
private AuthorizationProfile authorization;
3028

3129
public String getId() {
3230
return id;
@@ -40,12 +38,8 @@ public static ControlPlane.Builder newInstance() {
4038
return new ControlPlane.Builder();
4139
}
4240

43-
public List<AuthorizationProfile> getAuthorizations() {
44-
return authorizations;
45-
}
46-
47-
public AuthorizationProfile authorization() {
48-
return getAuthorizations().stream().findAny().orElse(null);
41+
public AuthorizationProfile getAuthorization() {
42+
return authorization;
4943
}
5044

5145
@JsonPOJOBuilder
@@ -72,8 +66,8 @@ public Builder endpoint(URI endpoint) {
7266
return this;
7367
}
7468

75-
public Builder authorization(List<AuthorizationProfile> authorizations) {
76-
controlPlane.authorizations.addAll(authorizations);
69+
public Builder authorization(AuthorizationProfile authorization) {
70+
controlPlane.authorization = authorization;
7771
return this;
7872
}
7973
}

src/main/java/org/eclipse/dataplane/domain/registration/ControlPlaneRegistrationMessage.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
package org.eclipse.dataplane.domain.registration;
1616

1717
import java.net.URI;
18-
import java.util.List;
19-
20-
import static java.util.Collections.emptyList;
2118

2219
public record ControlPlaneRegistrationMessage(
2320
String controlplaneId,
2421
URI endpoint,
25-
List<AuthorizationProfile> authorization
22+
AuthorizationProfile authorization
2623
) {
2724
public ControlPlaneRegistrationMessage(String controlplaneId, URI endpoint) {
28-
this(controlplaneId, endpoint, emptyList());
25+
this(controlplaneId, endpoint, null);
2926
}
3027
}

src/test/java/org/eclipse/dataplane/api/ControlPlaneRegistrationApiTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.junit.jupiter.api.Test;
2828

2929
import java.net.URI;
30-
import java.util.List;
3130
import java.util.UUID;
3231

3332
import static io.restassured.RestAssured.given;
@@ -115,7 +114,7 @@ void shouldReplaceControlPlane_whenSecondCall() {
115114
void shouldReturnBadRequest_whenRequestedAuthMethodNotSupported() {
116115
var controlPlaneId = UUID.randomUUID().toString();
117116
var authorization = new AuthorizationProfile("unsupported");
118-
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, List.of(authorization));
117+
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, authorization);
119118

120119
given()
121120
.contentType(ContentType.JSON)
@@ -128,12 +127,11 @@ void shouldReturnBadRequest_whenRequestedAuthMethodNotSupported() {
128127
.statusCode(400);
129128
}
130129

131-
132130
@Test
133131
void shouldRegisterAuthorizationType() {
134132
var controlPlaneId = UUID.randomUUID().toString();
135133
var authorization = new AuthorizationProfile("token");
136-
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, List.of(authorization));
134+
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(controlPlaneId, controlPlaneEndpoint, authorization);
137135

138136
given()
139137
.contentType(ContentType.JSON)

src/test/java/org/eclipse/dataplane/scenario/AuthorizationOauth2Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
import java.net.URI;
4545
import java.util.Date;
46-
import java.util.List;
4746
import java.util.Map;
4847
import java.util.Objects;
4948
import java.util.UUID;
@@ -103,7 +102,7 @@ void shouldCommunicateWithControlPlaneUsingOauth2Authorization() {
103102
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
104103
controlplaneId,
105104
controlPlane.consumerCallbackAddress(),
106-
List.of(oauth2AuthorizationProfile())
105+
oauth2AuthorizationProfile()
107106
);
108107
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);
109108

src/test/java/org/eclipse/dataplane/scenario/AuthorizationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.junit.jupiter.api.Test;
3030

3131
import java.net.URI;
32-
import java.util.List;
3332
import java.util.UUID;
3433

3534
import static java.util.Collections.emptyList;
@@ -74,7 +73,7 @@ void shouldCommunicateWithControlPlaneUsingRegisteredAuthorization() {
7473
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
7574
"control-plane-id",
7675
controlPlane.consumerCallbackAddress(),
77-
List.of(TestAuthorization.createAuthorizationProfile("data-plane-id"))
76+
TestAuthorization.createAuthorizationProfile("data-plane-id")
7877
);
7978
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);
8079

@@ -96,7 +95,7 @@ void shouldGetUnauthorized_whenControlPlaneIsNotAuthenticated() {
9695
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
9796
"unmatching-control-plane-id",
9897
controlPlane.consumerCallbackAddress(),
99-
List.of(TestAuthorization.createAuthorizationProfile("data-plane-id"))
98+
TestAuthorization.createAuthorizationProfile("data-plane-id")
10099
);
101100
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);
102101

@@ -113,7 +112,7 @@ void shouldGetUnauthorized_withDataPlaneIsNotAuthenticated() {
113112
var controlPlaneRegistrationMessage = new ControlPlaneRegistrationMessage(
114113
"control-plane-id",
115114
controlPlane.consumerCallbackAddress(),
116-
List.of(TestAuthorization.createAuthorizationProfile("data-plane-id"))
115+
TestAuthorization.createAuthorizationProfile("data-plane-id")
117116
);
118117
dataPlane.registerControlPlane(controlPlaneRegistrationMessage).orElseThrow(RuntimeException::new);
119118

src/test/java/org/eclipse/dataplane/scenario/ConsumerPullTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.net.URI;
3838
import java.nio.file.Files;
3939
import java.nio.file.Path;
40-
import java.util.List;
4140
import java.util.Objects;
4241
import java.util.UUID;
4342

@@ -144,7 +143,7 @@ private class ConsumerDataPlane {
144143

145144

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

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

src/test/java/org/eclipse/dataplane/scenario/ProviderPushTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.net.URI;
3636
import java.nio.file.Files;
3737
import java.nio.file.Path;
38-
import java.util.List;
3938
import java.util.UUID;
4039
import java.util.concurrent.CompletableFuture;
4140
import java.util.concurrent.ExecutorService;
@@ -171,7 +170,7 @@ private static class ProviderDataPlane {
171170
.build();
172171

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

177176
private Result<DataFlow> onStart(DataFlow dataFlow) {
@@ -213,7 +212,7 @@ private static class ConsumerDataPlane {
213212
.build();
214213

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

219218
public void completePreparation(String dataFlowId) {

src/test/java/org/eclipse/dataplane/scenario/StreamingPullTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.nio.file.Files;
4141
import java.nio.file.Path;
4242
import java.util.HashMap;
43-
import java.util.List;
4443
import java.util.Map;
4544
import java.util.Objects;
4645
import java.util.UUID;
@@ -171,7 +170,7 @@ private static class ConsumerDataPlane {
171170

172171

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

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

241240
public Object controller() {

0 commit comments

Comments
 (0)