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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.dataplane.domain.dataflow.DataFlowSuspendMessage;
import org.eclipse.dataplane.domain.dataflow.DataFlowTerminateMessage;
import org.eclipse.dataplane.domain.registration.Authorization;
import org.eclipse.dataplane.domain.registration.AuthorizationProfile;
import org.eclipse.dataplane.domain.registration.ControlPlaneRegistrationMessage;
import org.eclipse.dataplane.domain.registration.DataPlaneRegistrationMessage;
import org.eclipse.dataplane.logic.OnCompleted;
Expand Down Expand Up @@ -75,6 +76,7 @@ public class Dataplane {
private ControlPlaneStore controlPlaneStore = new InMemoryControlPlaneStore(objectMapper);
private String id;
private URI endpoint;
private AuthorizationProfile authorizationProfile;
private final Set<String> profiles = new HashSet<>();
private final Set<String> labels = new HashSet<>();

Expand Down Expand Up @@ -317,7 +319,7 @@ public Result<String> extractControlplaneId(String authorizationHeader) {

public Result<Void> registerOn(String controlPlaneEndpoint) {

var message = new DataPlaneRegistrationMessage(id, endpoint, profiles, labels);
var message = new DataPlaneRegistrationMessage(id, endpoint, profiles, labels, authorizationProfile);

return toJson(message)
.map(body -> HttpRequest.newBuilder()
Expand Down Expand Up @@ -445,6 +447,11 @@ public Builder endpoint(URI endpoint) {
return this;
}

public Builder authorizationProfile(AuthorizationProfile authorizationProfile) {
dataplane.authorizationProfile = authorizationProfile;
return this;
}

public Builder profile(String profile) {
dataplane.profiles.add(profile);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.eclipse.dataplane.port.exception.IllegalAttributeTypeException;

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

@JsonIgnore
public String getType() {
return attributes.get("type").toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public record DataPlaneRegistrationMessage(
String dataplaneId,
URI endpoint,
Set<String> profiles,
Set<String> labels
// TODO: authorization
Set<String> labels,
AuthorizationProfile authorization
) {
}
3 changes: 2 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Additionally, the `Dataplane.Builder` class provides methods for the following p
- `endpoint`: the URL under which the Dataplane API is reachable, will be your application's base URL and path plus `/v1/dataflows`
- `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)
- `label`: a label for the dataplane instance which can be used by control planes to filter for specific dataplanes (multiple labels can be added)
- `authorization`: defines the authorization used between control and dataplane, for more information see [Authorizations](#authorizations)
- `authorization`: defines a supported authorization for communication with the control plane, for more information see [Authorizations](#authorizations)
- `authorizationProfile`: defines the authorization profile used by this dataplane, i.e. how a control plane should authenticate when talking to this dataplane

*There is one additional builder method called `stores()`, which will be detailed later in this guide. When not setting
any stores specifically, both `DataFlow` and `ControlPlane` information will be stored in-memory.*
Expand Down
30 changes: 30 additions & 0 deletions e2e-tests/src/test/java/org/eclipse/dataplane/DataplaneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.github.tomakehurst.wiremock.WireMockServer;
import org.eclipse.dataplane.domain.Result;
import org.eclipse.dataplane.domain.dataflow.DataFlowPrepareMessage;
import org.eclipse.dataplane.domain.registration.AuthorizationProfile;
import org.eclipse.dataplane.domain.registration.ControlPlaneRegistrationMessage;
import org.eclipse.dataplane.port.exception.DataFlowNotifyControlPlaneFailed;
import org.eclipse.dataplane.port.exception.DataplaneNotRegistered;
Expand All @@ -35,6 +36,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.and;
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
Expand Down Expand Up @@ -177,6 +179,34 @@ void shouldRegisterOnTheControlPlane() {
);
}

@Test
void shouldRegisterOnTheControlPlane_withAuthProfile() {
controlPlane.stubFor(put(anyUrl()).willReturn(aResponse().withStatus(200)));

var authProfile = new AuthorizationProfile("test")
.withAttribute("key", "value");

var dataplane = Dataplane.newInstance()
.id("dataplane-id")
.endpoint(URI.create("http://localhost/dataplane"))
.authorizationProfile(authProfile)
.profile("SupportedTransferType-PUSH")
.label("label-one").label("label-two")
.build();

var result = dataplane.registerOn(controlPlane.baseUrl());

assertThat(result.succeeded()).isTrue();
controlPlane.verify(putRequestedFor(urlPathEqualTo("/dataplanes"))
.withRequestBody(and(
matchingJsonPath("endpoint", equalTo("http://localhost/dataplane")),
matchingJsonPath("authorization", equalToJson("{\"type\":\"test\",\"key\":\"value\"}")),
matchingJsonPath("profiles[0]", equalTo("SupportedTransferType-PUSH")),
matchingJsonPath("labels.size()", equalTo("2"))
))
);
}

@Test
void shouldFail_whenStatusIsNot200() {
controlPlane.stubFor(post(anyUrl()).willReturn(aResponse().withStatus(409)));
Expand Down