Skip to content

Commit e7035a5

Browse files
committed
feat: add auth profile for dataplane
1 parent 24fa08f commit e7035a5

5 files changed

Lines changed: 44 additions & 4 deletions

File tree

dataplane-sdk-core/src/main/java/org/eclipse/dataplane/Dataplane.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.dataplane.domain.dataflow.DataFlowSuspendMessage;
3232
import org.eclipse.dataplane.domain.dataflow.DataFlowTerminateMessage;
3333
import org.eclipse.dataplane.domain.registration.Authorization;
34+
import org.eclipse.dataplane.domain.registration.AuthorizationProfile;
3435
import org.eclipse.dataplane.domain.registration.ControlPlaneRegistrationMessage;
3536
import org.eclipse.dataplane.domain.registration.DataPlaneRegistrationMessage;
3637
import org.eclipse.dataplane.logic.OnCompleted;
@@ -75,6 +76,7 @@ public class Dataplane {
7576
private ControlPlaneStore controlPlaneStore = new InMemoryControlPlaneStore(objectMapper);
7677
private String id;
7778
private URI endpoint;
79+
private AuthorizationProfile authorizationProfile;
7880
private final Set<String> transferTypes = new HashSet<>();
7981
private final Set<String> labels = new HashSet<>();
8082

@@ -325,7 +327,7 @@ public Result<String> extractControlplaneId(String authorizationHeader) {
325327

326328
public Result<Void> registerOn(String controlPlaneEndpoint) {
327329

328-
var message = new DataPlaneRegistrationMessage(id, endpoint, transferTypes, labels);
330+
var message = new DataPlaneRegistrationMessage(id, endpoint, transferTypes, labels, authorizationProfile);
329331

330332
return toJson(message)
331333
.map(body -> HttpRequest.newBuilder()
@@ -445,6 +447,11 @@ public Builder endpoint(URI endpoint) {
445447
return this;
446448
}
447449

450+
public Builder authorizationProfile(AuthorizationProfile authorizationProfile) {
451+
dataplane.authorizationProfile = authorizationProfile;
452+
return this;
453+
}
454+
448455
public Builder transferType(String transferType) {
449456
dataplane.transferTypes.add(transferType);
450457
return this;

dataplane-sdk-core/src/main/java/org/eclipse/dataplane/domain/registration/AuthorizationProfile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.fasterxml.jackson.annotation.JsonAnyGetter;
1818
import com.fasterxml.jackson.annotation.JsonAnySetter;
19+
import com.fasterxml.jackson.annotation.JsonIgnore;
1920
import org.eclipse.dataplane.port.exception.IllegalAttributeTypeException;
2021

2122
import java.util.HashMap;
@@ -34,6 +35,7 @@ public AuthorizationProfile(String type) {
3435
attributes.put("type", type);
3536
}
3637

38+
@JsonIgnore
3739
public String getType() {
3840
return attributes.get("type").toString();
3941
}

dataplane-sdk-core/src/main/java/org/eclipse/dataplane/domain/registration/DataPlaneRegistrationMessage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public record DataPlaneRegistrationMessage(
2121
String dataplaneId,
2222
URI endpoint,
2323
Set<String> transferTypes,
24-
Set<String> labels
25-
// TODO: authorization
24+
Set<String> labels,
25+
AuthorizationProfile authorization
2626
) {
2727
}

docs/getting-started.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Additionally, the `Dataplane.Builder` class provides methods for the following p
5757
- `endpoint`: the URL under which the Dataplane API is reachable, will be your application's base URL and path plus `/v1/dataflows`
5858
- `transferType`: a [transfer type](https://github.com/eclipse-dataplane-signaling/dataplane-signaling/blob/main/specifications/signaling.md#data-transfer-types) supported by the dataplane (multiple transfer types can be added)
5959
- `label`: a label for the dataplane instance which can be used by control planes to filter for specific dataplanes (multiple labels can be added)
60-
- `authorization`: defines the authorization used between control and dataplane, for more information see [Authorizations](#authorizations)
60+
- `authorization`: defines a supported authorization for communication with the control plane, for more information see [Authorizations](#authorizations)
61+
- `authorizationProfile`: defines the authorization profile used by this dataplane, i.e. how a control plane should authenticate when talking to this dataplane
6162

6263
*There is one additional builder method called `stores()`, which will be detailed later in this guide. When not setting
6364
any stores specifically, both `DataFlow` and `ControlPlane` information will be stored in-memory.*

e2e-tests/src/test/java/org/eclipse/dataplane/DataplaneTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.github.tomakehurst.wiremock.WireMockServer;
1919
import org.eclipse.dataplane.domain.Result;
2020
import org.eclipse.dataplane.domain.dataflow.DataFlowPrepareMessage;
21+
import org.eclipse.dataplane.domain.registration.AuthorizationProfile;
2122
import org.eclipse.dataplane.domain.registration.ControlPlaneRegistrationMessage;
2223
import org.eclipse.dataplane.port.exception.DataFlowNotifyControlPlaneFailed;
2324
import org.eclipse.dataplane.port.exception.DataplaneNotRegistered;
@@ -35,6 +36,7 @@
3536
import static com.github.tomakehurst.wiremock.client.WireMock.and;
3637
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
3738
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
39+
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
3840
import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath;
3941
import static com.github.tomakehurst.wiremock.client.WireMock.post;
4042
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
@@ -177,6 +179,34 @@ void shouldRegisterOnTheControlPlane() {
177179
);
178180
}
179181

182+
@Test
183+
void shouldRegisterOnTheControlPlane_withAuthProfile() {
184+
controlPlane.stubFor(put(anyUrl()).willReturn(aResponse().withStatus(200)));
185+
186+
var authProfile = new AuthorizationProfile("test")
187+
.withAttribute("key", "value");
188+
189+
var dataplane = Dataplane.newInstance()
190+
.id("dataplane-id")
191+
.endpoint(URI.create("http://localhost/dataplane"))
192+
.authorizationProfile(authProfile)
193+
.transferType("SupportedTransferType-PUSH")
194+
.label("label-one").label("label-two")
195+
.build();
196+
197+
var result = dataplane.registerOn(controlPlane.baseUrl());
198+
199+
assertThat(result.succeeded()).isTrue();
200+
controlPlane.verify(putRequestedFor(urlPathEqualTo("/dataplanes"))
201+
.withRequestBody(and(
202+
matchingJsonPath("endpoint", equalTo("http://localhost/dataplane")),
203+
matchingJsonPath("authorization", equalToJson("{\"type\":\"test\",\"key\":\"value\"}")),
204+
matchingJsonPath("transferTypes[0]", equalTo("SupportedTransferType-PUSH")),
205+
matchingJsonPath("labels.size()", equalTo("2"))
206+
))
207+
);
208+
}
209+
180210
@Test
181211
void shouldFail_whenStatusIsNot200() {
182212
controlPlane.stubFor(post(anyUrl()).willReturn(aResponse().withStatus(409)));

0 commit comments

Comments
 (0)