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 @@ -39,7 +39,7 @@ public static RESTCatalog restCatalog(
.put(CatalogProperties.URI, endpoints.catalogApiEndpoint().toString())
.put(OAuth2Properties.TOKEN, authToken)
.put("warehouse", catalog)
.put("header." + endpoints.realmHeaderName(), endpoints.realmId())
.putAll(endpoints.extraHeaders("header."))
.putAll(extraProperties);

restCatalog.initialize("polaris", propertiesBuilder.buildKeepingLast());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.Serializable;
import java.net.URI;
import java.util.Map;
import java.util.stream.Collectors;

/**
* This class contains the most fundamental information for accessing Polaris APIs, such as the base
Expand All @@ -30,12 +32,16 @@ public final class PolarisApiEndpoints implements Serializable {

private final URI baseUri;
private final String realmId;
private final String realmHeaderName;
private final Map<String, String> headers;

public PolarisApiEndpoints(URI baseUri, String realmId, String realmHeaderName) {
this(baseUri, realmId, Map.of(realmHeaderName, realmId));
}

public PolarisApiEndpoints(URI baseUri, String realmId, Map<String, String> headers) {
this.baseUri = baseUri;
this.realmId = realmId;
this.realmHeaderName = realmHeaderName;
this.headers = headers;
}

public URI catalogApiEndpoint() {
Expand All @@ -50,7 +56,13 @@ public String realmId() {
return realmId;
}

public String realmHeaderName() {
return realmHeaderName;
public Map<String, String> extraHeaders() {
return headers;
}

public Map<String, String> extraHeaders(String keyPrefix) {
return headers.entrySet().stream()
.map(e -> Map.entry(keyPrefix + e.getKey(), e.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class PolarisRestApi extends RestApi {
}

protected Map<String, String> defaultHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put(endpoints.realmHeaderName(), endpoints.realmId());
Map<String, String> headers = new HashMap<>(endpoints.extraHeaders());
if (authToken != null) {
headers.put("Authorization", "Bearer " + authToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.polaris.service.it.env;

import java.net.URI;
import java.util.Map;

/**
* This is a holder for access information to a particular Polaris Server. Test cases may use only
Expand All @@ -37,6 +38,10 @@ default String realmHeaderName() {
return DEFAULT_REALM_HEADER;
}

default Map<String, String> headers() {
return Map.of(realmHeaderName(), realmId());
}

/**
* The base URI to all Polaris APIs (e.g. the common base of the Iceberg REST API endpoints and
* Polaris Management API endpoints).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static class Env implements AutoCloseable {
private Env(Server server) {
this.server = server;
this.endpoints =
new PolarisApiEndpoints(server.baseUri(), server.realmId(), server.realmHeaderName());
new PolarisApiEndpoints(server.baseUri(), server.realmId(), server.headers());
}

PolarisApiEndpoints endpoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,12 @@ private static RESTSessionCatalog newSessionCatalog(String catalog) {
RESTSessionCatalog sessionCatalog = new RESTSessionCatalog();
sessionCatalog.initialize(
"polaris_catalog_test",
Map.of(
"uri",
endpoints.catalogApiEndpoint().toString(),
OAuth2Properties.TOKEN,
authToken,
"warehouse",
catalog,
"header." + endpoints.realmHeaderName(),
realm));
ImmutableMap.<String, String>builder()
.put("uri", endpoints.catalogApiEndpoint().toString())
.put(OAuth2Properties.TOKEN, authToken)
.put("warehouse", catalog)
.putAll(endpoints.extraHeaders("header."))
.build());
return sessionCatalog;
}

Expand Down Expand Up @@ -590,15 +587,12 @@ public void testWarehouseNotSpecified() throws IOException {
() ->
sessionCatalog.initialize(
"polaris_catalog_test",
Map.of(
"uri",
endpoints.catalogApiEndpoint().toString(),
OAuth2Properties.TOKEN,
authToken,
"warehouse",
emptyEnvironmentVariable,
"header." + endpoints.realmHeaderName(),
realm)))
ImmutableMap.<String, String>builder()
.put("uri", endpoints.catalogApiEndpoint().toString())
.put(OAuth2Properties.TOKEN, authToken)
.put("warehouse", emptyEnvironmentVariable)
.putAll(endpoints.extraHeaders("header."))
.build()))
.isInstanceOf(BadRequestException.class)
.hasMessage("Malformed request: Please specify a warehouse");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private RESTCatalog createCatalog(
org.apache.iceberg.CatalogProperties.URI, endpoints.catalogApiEndpoint().toString())
.put(OAuth2Properties.TOKEN, authToken)
.put("warehouse", catalogName)
.put("header." + endpoints.realmHeaderName(), endpoints.realmId())
.putAll(endpoints.extraHeaders("header."))
.put("header.X-Iceberg-Access-Delegation", "vended-credentials");

restCatalog.initialize("polaris", propertiesBuilder.buildKeepingLast());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testIcebergRestApiRefreshExpiredToken(
String path = endpoints.catalogApiEndpoint() + "/v1/oauth/tokens";
try (RESTClient client =
HTTPClient.builder(Map.of())
.withHeader(endpoints.realmHeaderName(), endpoints.realmId())
.withHeaders(endpoints.extraHeaders())
.uri(path)
.withAuthSession(AuthSession.EMPTY)
.build()) {
Expand Down Expand Up @@ -106,7 +106,7 @@ public void testIcebergRestApiRefreshValidToken(
String path = endpoints.catalogApiEndpoint() + "/v1/oauth/tokens";
try (RESTClient client =
HTTPClient.builder(Map.of())
.withHeader(endpoints.realmHeaderName(), endpoints.realmId())
.withHeaders(endpoints.extraHeaders())
.uri(path)
.withAuthSession(AuthSession.EMPTY)
.build()) {
Expand Down Expand Up @@ -147,7 +147,7 @@ public void testIcebergRestApiInvalidToken(
String path = endpoints.catalogApiEndpoint() + "/v1/oauth/tokens";
try (RESTClient client =
HTTPClient.builder(Map.of())
.withHeader(endpoints.realmHeaderName(), endpoints.realmId())
.withHeaders(endpoints.extraHeaders())
.uri(path)
.withAuthSession(AuthSession.EMPTY)
.build()) {
Expand Down