Skip to content

Commit

Permalink
Feature/14/14 web context (with ADR) (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
algattik authored and cpeeyush committed Jul 18, 2022
1 parent 15bc8da commit cb3dee3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For example, to list dataspace participants:

```
java -jar client-cli/build/libs/registration-service-cli.jar \
-s=http://localhost:8181/api \
-s=http://localhost:8182/authority \
participants list
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ParticipantsCommand.class
})
public class RegistrationServiceCli {
@CommandLine.Option(names = "-s", required = true, description = "Registration service URL", defaultValue = "http://localhost:8181/api")
@CommandLine.Option(names = "-s", required = true, description = "Registration service URL", defaultValue = "http://localhost:8182/authority")
String service;

RegistryApi registryApiClient;
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
JVM_ARGS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
environment:
EDC_API_AUTH_KEY: ApiKeyDefaultValue
WEB_HTTP_AUTHORITY_PORT: 8182
WEB_HTTP_AUTHORITY_PATH: /authority
ports:
- "8181:8181"
- "8182:8182"
- "5005:5005"
27 changes: 27 additions & 0 deletions docs/developer/decision-records/2022-06-29-http-ports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# HTTP Ports

## Decision

The EDC `default` web context is deployed on HTTP port `8181`. This context contains the health endpoint at `http://localhost:8181/api/check/health`.

The Registration Service REST Controller is deployed in a additional EDC web context named `authority`.

The port mapping and REST URL path for this context must be specified in deployment.

For example in Docker Compose:

```
environment:
WEB_HTTP_AUTHORITY_PORT: 8182
WEB_HTTP_AUTHORITY_PATH: /authority
```

This makes the List Participants endpoint available at `http://localhost:8182/authority/registry/participants`.

## Rationale

DID-based JWS authentication will be used for the Registration Service controller, using a JAX-RS filter.

However, for docker health check (used in `docker-compose up --wait` in CI to wait until containers have successfully started), we use `curl` to access the health endpoint, which is deployed in the EDC default context. Therefore, we do not want to apply our authentication filter to the `default` context, and need to introduce an additional context for the API controller.

It is also good practice not to expose health and management endpoints to public access. Deploying them on a different ports allow deployments to expose their port on internal routes only.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.dataspaceconnector.registration.store.InMemoryParticipantStore;
import org.eclipse.dataspaceconnector.registration.store.spi.ParticipantStore;
import org.eclipse.dataspaceconnector.spi.WebService;
import org.eclipse.dataspaceconnector.spi.monitor.Monitor;
import org.eclipse.dataspaceconnector.spi.system.ExecutorInstrumentation;
import org.eclipse.dataspaceconnector.spi.system.Inject;
import org.eclipse.dataspaceconnector.spi.system.Provider;
Expand All @@ -33,6 +34,11 @@
*/
public class RegistrationServiceExtension implements ServiceExtension {

public static final String CONTEXT_ALIAS = "authority";

@Inject
private Monitor monitor;

@Inject
private WebService webService;

Expand All @@ -49,12 +55,11 @@ public class RegistrationServiceExtension implements ServiceExtension {

@Override
public void initialize(ServiceExtensionContext context) {
var monitor = context.getMonitor();

participantManager = new ParticipantManager(monitor, participantStore, credentialsVerifier, executorInstrumentation);

var registrationService = new RegistrationService(monitor, participantStore);
webService.registerResource(new RegistrationApiController(registrationService));
webService.registerResource(CONTEXT_ALIAS, new RegistrationApiController(registrationService));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions launcher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ RUN apt update \
WORKDIR /app
COPY ./build/libs/app.jar /app

EXPOSE 8181
EXPOSE 8182

# health status is determined by the availability of the /health endpoint
HEALTHCHECK --interval=5s --timeout=5s --retries=10 CMD curl -H "X-Api-Key: $EDC_API_AUTH_KEY" --fail http://localhost:8181/api/check/health
HEALTHCHECK --interval=5s --timeout=5s --retries=10 CMD curl --fail http://localhost:8181/api/check/health

ENV WEB_HTTP_PORT="8181"
ENV WEB_HTTP_PATH="/api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@IntegrationTest
public class RegistrationApiClientTest {
static final String API_URL = "http://localhost:8181/api";
static final String API_URL = "http://localhost:8182/authority";

ApiClient apiClient = ApiClientFactory.createApiClient(API_URL);
RegistryApi api = new RegistryApi(apiClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

@IntegrationTest
public class RegistrationApiCommandLineClientTest {
static final String API_URL = "http://localhost:8181/api";

static final ObjectMapper MAPPER = new ObjectMapper();
Participant participant = createParticipant();

Expand All @@ -44,7 +42,7 @@ void listParticipants() throws Exception {

var request = MAPPER.writeValueAsString(participant);

var addCmdExitCode = cmd.execute("-s", API_URL, "participants", "add", "--request", request);
var addCmdExitCode = cmd.execute("participants", "add", "--request", request);
assertThat(addCmdExitCode).isEqualTo(0);
assertThat(getParticipants(cmd)).contains(participant);
}
Expand Down

0 comments on commit cb3dee3

Please sign in to comment.