Skip to content

Commit

Permalink
feat: change /metadata REST path to /v1/metadata (#3467)
Browse files Browse the repository at this point in the history
  • Loading branch information
spena authored Oct 10, 2019
1 parent 804c578 commit ed94895
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,28 +31,36 @@ 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<String, String> scope;
private final Map<String, Object> scope;

@JsonCreator
ServerClusterId(
@JsonProperty("scope") final Map<String, String> scope
@JsonProperty("scope") final Map<String, Object> 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
)
));
}

public String getId() {
return id;
}

public Map<String, String> getScope() {
public Map<String, Object> getScope() {
return scope;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,15 +33,18 @@ public void shouldReturnServerClusterId() {

// When:
final String id = serverClusterId.getId();
final Map<String, String> scope = serverClusterId.getScope();
final Map<String, Object> 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")
))
);
}
}

0 comments on commit ed94895

Please sign in to comment.