From ed94895642f777a1ada2b9fa5ca481bd7698058c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Pe=C3=B1a?= Date: Thu, 10 Oct 2019 15:14:40 -0500 Subject: [PATCH] feat: change /metadata REST path to /v1/metadata (#3467) --- .../resources/ServerMetadataResource.java | 2 +- .../filters/KsqlAuthorizationFilterTest.java | 4 ++-- .../ksql/rest/entity/ServerClusterId.java | 20 ++++++++++++---- .../ksql/rest/entity/ServerClusterIdTest.java | 23 ++++++++++++------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/resources/ServerMetadataResource.java b/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/resources/ServerMetadataResource.java index 1af0e787de10..48a0720c58f6 100644 --- a/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/resources/ServerMetadataResource.java +++ b/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/resources/ServerMetadataResource.java @@ -29,7 +29,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -@Path("/metadata") +@Path("/v1/metadata") @Produces({Versions.KSQL_V1_JSON, MediaType.APPLICATION_JSON}) public final class ServerMetadataResource { private final ServerMetadata serverMetadata; diff --git a/ksql-rest-app/src/test/java/io/confluent/ksql/rest/server/filters/KsqlAuthorizationFilterTest.java b/ksql-rest-app/src/test/java/io/confluent/ksql/rest/server/filters/KsqlAuthorizationFilterTest.java index e88850b55ce2..eb81184ea035 100644 --- a/ksql-rest-app/src/test/java/io/confluent/ksql/rest/server/filters/KsqlAuthorizationFilterTest.java +++ b/ksql-rest-app/src/test/java/io/confluent/ksql/rest/server/filters/KsqlAuthorizationFilterTest.java @@ -90,7 +90,7 @@ public void filterShouldAbortIfAuthorizationIsDenied() { @Test public void filterShouldContinueOnUnauthorizedMetadataPath() { // Given: - ContainerRequest request = givenRequestContext(userPrincipal, "GET", "metadata"); + ContainerRequest request = givenRequestContext(userPrincipal, "GET", "v1/metadata"); // When: authorizationFilter.filter(request); @@ -103,7 +103,7 @@ public void filterShouldContinueOnUnauthorizedMetadataPath() { @Test public void filterShouldContinueOnUnauthorizedMetadataIdPath() { // Given: - ContainerRequest request = givenRequestContext(userPrincipal, "GET", "metadata/id"); + ContainerRequest request = givenRequestContext(userPrincipal, "GET", "v1/metadata/id"); // When: authorizationFilter.filter(request); diff --git a/ksql-rest-model/src/main/java/io/confluent/ksql/rest/entity/ServerClusterId.java b/ksql-rest-model/src/main/java/io/confluent/ksql/rest/entity/ServerClusterId.java index adc8075ebb8f..70f2f6f70a75 100644 --- a/ksql-rest-model/src/main/java/io/confluent/ksql/rest/entity/ServerClusterId.java +++ b/ksql-rest-model/src/main/java/io/confluent/ksql/rest/entity/ServerClusterId.java @@ -20,6 +20,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableMap; import com.google.errorprone.annotations.Immutable; + +import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -29,20 +31,28 @@ public final class ServerClusterId { private static final String KAFKA_CLUSTER = "kafka-cluster"; private static final String KSQL_CLUSTER = "ksql-cluster"; + // ID is unused for now, but it might be used later to include a URL that joins both, kafka and + // ksql, clusters names into one single string. This one URL string will be easier to pass + // through authorization commands to authorize access to this KSQL cluster. private static final String id = ""; - private final Map scope; + private final Map scope; @JsonCreator ServerClusterId( - @JsonProperty("scope") final Map scope + @JsonProperty("scope") final Map scope ) { this.scope = ImmutableMap.copyOf(Objects.requireNonNull(scope, "scope")); } public static ServerClusterId of(final String kafkaClusterId, final String ksqlClusterId) { return new ServerClusterId(ImmutableMap.of( - KAFKA_CLUSTER, kafkaClusterId, - KSQL_CLUSTER, ksqlClusterId + // 'path' is unused for now, but it might be used by Cloud environments that specify + // which account organization this cluster belongs to. + "path", Collections.emptyList(), + "clusters", ImmutableMap.of( + KAFKA_CLUSTER, kafkaClusterId, + KSQL_CLUSTER, ksqlClusterId + ) )); } @@ -50,7 +60,7 @@ public String getId() { return id; } - public Map getScope() { + public Map getScope() { return scope; } diff --git a/ksql-rest-model/src/test/java/io/confluent/ksql/rest/entity/ServerClusterIdTest.java b/ksql-rest-model/src/test/java/io/confluent/ksql/rest/entity/ServerClusterIdTest.java index f2c5fc67ee2c..1c569367117d 100644 --- a/ksql-rest-model/src/test/java/io/confluent/ksql/rest/entity/ServerClusterIdTest.java +++ b/ksql-rest-model/src/test/java/io/confluent/ksql/rest/entity/ServerClusterIdTest.java @@ -15,9 +15,13 @@ package io.confluent.ksql.rest.entity; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; import com.google.common.collect.ImmutableMap; + +import java.util.Collections; import java.util.Map; import org.junit.Test; @@ -29,15 +33,18 @@ public void shouldReturnServerClusterId() { // When: final String id = serverClusterId.getId(); - final Map scope = serverClusterId.getScope(); + final Map scope = serverClusterId.getScope(); // Then: - assertEquals("", id); - assertEquals( - ImmutableMap.of( - "kafka-cluster", "kafka1", - "ksql-cluster", "ksql1"), - scope + assertThat(id, is("")); + assertThat( + scope, + equalTo(ImmutableMap.of( + "path", Collections.emptyList(), + "clusters", ImmutableMap.of( + "kafka-cluster", "kafka1", + "ksql-cluster", "ksql1") + )) ); } }