Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ jobs:
!:trino-hdfs,
!:trino-hive,
!:trino-hive-formats,
!:trino-hsqldb,
!:trino-hudi,
!:trino-iceberg,
!:trino-ignite,
Expand Down Expand Up @@ -491,6 +492,7 @@ jobs:
- { modules: plugin/trino-hive }
- { modules: plugin/trino-hive, profile: fte-tests }
- { modules: plugin/trino-hive, profile: test-parquet }
- { modules: plugin/trino-hsqldb }
- { modules: plugin/trino-hudi }
- { modules: plugin/trino-iceberg }
- { modules: plugin/trino-iceberg, profile: cloud-tests }
Expand Down
71 changes: 0 additions & 71 deletions client/trino-cli/src/main/java/io/trino/cli/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import static com.google.common.base.Strings.nullToEmpty;
import static io.trino.cli.TerminalUtils.getTerminal;
import static io.trino.client.KerberosUtil.defaultCredentialCachePath;
import static io.trino.client.ProtocolHeaders.TRINO_HEADERS;
import static io.trino.client.uri.PropertyName.ACCESS_TOKEN;
import static io.trino.client.uri.PropertyName.CATALOG;
import static io.trino.client.uri.PropertyName.CLIENT_INFO;
Expand All @@ -57,7 +56,6 @@
import static io.trino.client.uri.PropertyName.EXTERNAL_AUTHENTICATION;
import static io.trino.client.uri.PropertyName.EXTERNAL_AUTHENTICATION_REDIRECT_HANDLERS;
import static io.trino.client.uri.PropertyName.EXTRA_CREDENTIALS;
import static io.trino.client.uri.PropertyName.EXTRA_HEADERS;
import static io.trino.client.uri.PropertyName.HTTP_LOGGING_LEVEL;
import static io.trino.client.uri.PropertyName.HTTP_PROXY;
import static io.trino.client.uri.PropertyName.KERBEROS_CONFIG_PATH;
Expand Down Expand Up @@ -206,10 +204,6 @@ public class ClientOptions
@Option(names = "--client-tags", paramLabel = "<tags>", description = "Client tags", converter = ClientTagsConverter.class)
public Optional<Set<String>> clientTags;

@PropertyMapping(EXTRA_HEADERS)
@Option(names = "--extra-header", paramLabel = "<header>", description = "Additional HTTP header to add to HTTP requests (property can be used multiple times; format is key=value)")
public final List<ExtraHeader> extraHeaders = new ArrayList<>();

@PropertyMapping(TRACE_TOKEN)
@Option(names = "--trace-token", paramLabel = "<token>", description = "Trace token")
public Optional<String> traceToken;
Expand Down Expand Up @@ -428,9 +422,6 @@ public TrinoUri getTrinoUri(Map<PropertyName, String> restrictedProperties)
if (!sessionProperties.isEmpty()) {
builder.setSessionProperties(toProperties(sessionProperties));
}
if (!extraHeaders.isEmpty()) {
builder.setExtraHeaders(toExtraHeaders(extraHeaders));
}
if (!resourceEstimates.isEmpty()) {
builder.setResourceEstimates(toResourceEstimates(resourceEstimates));
}
Expand Down Expand Up @@ -507,15 +498,6 @@ public static URI parseServer(String server)
}
}

public static Map<String, String> toExtraHeaders(List<ExtraHeader> extraHeaders)
{
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (ExtraHeader extraHeader : extraHeaders) {
builder.put(extraHeader.getHeader(), extraHeader.getValue());
}
return builder.buildOrThrow();
}

private static Map<String, String> toProperties(List<ClientSessionProperty> sessionProperties)
{
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
Expand Down Expand Up @@ -623,59 +605,6 @@ public int hashCode()
}
}

public static final class ExtraHeader
{
private final String header;
private final String value;

public ExtraHeader(String headerAndValue)
{
List<String> nameValue = NAME_VALUE_SPLITTER.splitToList(headerAndValue);
checkArgument(nameValue.size() == 2, "Header and value: %s", headerAndValue);
this.header = nameValue.get(0);
this.value = nameValue.get(1);

checkArgument(!TRINO_HEADERS.isProtocolHeader(header), "Header '%s' is a protocol header and cannot be set as an extra header", header);
checkArgument(!header.isEmpty(), "Header name is empty");
checkArgument(!value.isEmpty(), "Header value is empty");
}

public ExtraHeader(String header, String value)
{
this.header = header;
this.value = value;
}

public String getHeader()
{
return header;
}

public String getValue()
{
return value;
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ExtraHeader other = (ExtraHeader) o;
return Objects.equals(header, other.header) && Objects.equals(value, other.value);
}

@Override
public int hashCode()
{
return Objects.hash(header, value);
}
}

public static final class ClientSessionProperty
{
private static final Splitter NAME_SPLITTER = Splitter.on('.');
Expand Down
2 changes: 0 additions & 2 deletions client/trino-cli/src/main/java/io/trino/cli/Trino.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.trino.cli.ClientOptions.ClientExtraCredential;
import io.trino.cli.ClientOptions.ClientResourceEstimate;
import io.trino.cli.ClientOptions.ClientSessionProperty;
import io.trino.cli.ClientOptions.ExtraHeader;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import picocli.CommandLine;
Expand Down Expand Up @@ -63,7 +62,6 @@ public static CommandLine createCommandLine(Object command)
.registerConverter(ClientResourceEstimate.class, ClientResourceEstimate::new)
.registerConverter(ClientSessionProperty.class, ClientSessionProperty::new)
.registerConverter(ClientExtraCredential.class, ClientExtraCredential::new)
.registerConverter(ExtraHeader.class, ExtraHeader::new)
.registerConverter(HostAndPort.class, HostAndPort::fromString)
.registerConverter(Duration.class, Duration::valueOf)
.setResourceBundle(new TrinoResourceBundle())
Expand Down
14 changes: 0 additions & 14 deletions client/trino-cli/src/test/java/io/trino/cli/TestClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,6 @@ public void testExtraCredentials()
new ClientOptions.ClientExtraCredential("test.token.bar", "bar")));
}

@Test
public void testExtraHeaders()
{
Console console = createConsole("--extra-header", "X-Trino-Routing-Group=foo", "--extra-header", "x-foo=bar");
ClientOptions options = console.clientOptions;
assertThat(options.extraHeaders).isEqualTo(ImmutableList.of(
new ClientOptions.ExtraHeader("X-Trino-Routing-Group", "foo"),
new ClientOptions.ExtraHeader("x-foo", "bar")));

assertThatThrownBy(() -> createConsole("--extra-header", "X-Trino-User=Forbidden"))
.hasCauseInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Header 'X-Trino-User' is a protocol header and cannot be set as an extra header");
}

@Test
public void testSessionProperties()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class ClientSession
private final ZoneId timeZone;
private final Locale locale;
private final Map<String, String> resourceEstimates;
private final Map<String, String> extraHeaders;
private final Map<String, String> properties;
private final Map<String, String> preparedStatements;
private final Map<String, ClientSelectedRole> roles;
Expand Down Expand Up @@ -88,7 +87,6 @@ private ClientSession(
String source,
Optional<String> traceToken,
Set<String> clientTags,
Map<String, String> extraHeaders,
String clientInfo,
Optional<String> catalog,
Optional<String> schema,
Expand All @@ -114,7 +112,6 @@ private ClientSession(
this.source = requireNonNull(source, "source is null");
this.traceToken = requireNonNull(traceToken, "traceToken is null");
this.clientTags = ImmutableSet.copyOf(requireNonNull(clientTags, "clientTags is null"));
this.extraHeaders = ImmutableMap.copyOf(requireNonNull(extraHeaders, "extraHeaders is null"));
this.clientInfo = clientInfo;
this.catalog = catalog;
this.schema = schema;
Expand Down Expand Up @@ -201,11 +198,6 @@ public Set<String> getClientTags()
return clientTags;
}

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

public String getClientInfo()
{
return clientInfo;
Expand Down Expand Up @@ -303,7 +295,6 @@ public String toString()
.add("sessionUser", sessionUser)
.add("authorizationUser", authorizationUser)
.add("clientTags", clientTags)
.add("extraHeaders", extraHeaders)
.add("clientInfo", clientInfo)
.add("catalog", catalog)
.add("schema", schema)
Expand Down Expand Up @@ -333,7 +324,6 @@ public static final class Builder
private String source;
private Optional<String> traceToken = Optional.empty();
private Set<String> clientTags = ImmutableSet.of();
private Map<String, String> extraHeaders = ImmutableMap.of();
private String clientInfo;
private String catalog;
private String schema;
Expand Down Expand Up @@ -364,7 +354,6 @@ private Builder(ClientSession clientSession)
source = clientSession.getSource();
traceToken = clientSession.getTraceToken();
clientTags = clientSession.getClientTags();
extraHeaders = clientSession.getExtraHeaders();
clientInfo = clientSession.getClientInfo();
catalog = clientSession.getCatalog().orElse(null);
schema = clientSession.getSchema().orElse(null);
Expand Down Expand Up @@ -430,12 +419,6 @@ public Builder clientTags(Set<String> clientTags)
return this;
}

public Builder extraHeaders(Map<String, String> extraHeaders)
{
this.extraHeaders = extraHeaders;
return this;
}

public Builder clientInfo(String clientInfo)
{
this.clientInfo = clientInfo;
Expand Down Expand Up @@ -543,7 +526,6 @@ public ClientSession build()
source,
traceToken,
clientTags,
extraHeaders,
clientInfo,
Optional.ofNullable(catalog),
Optional.ofNullable(schema),
Expand Down
12 changes: 0 additions & 12 deletions client/trino-client/src/main/java/io/trino/client/OkHttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -110,17 +109,6 @@ public static Interceptor tokenAuth(String accessToken)
.build());
}

public static Interceptor extraHeaders(Map<String, String> extraHeaders)
{
requireNonNull(extraHeaders, "extraHeaders is null");

return chain -> {
okhttp3.Request.Builder builder = chain.request().newBuilder();
extraHeaders.forEach(builder::addHeader);
return chain.proceed(builder.build());
};
}

public static void setupTimeouts(OkHttpClient.Builder clientBuilder, int timeout, TimeUnit unit)
{
clientBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,6 @@ private ProtocolHeaders(String name)
responseOriginalRole = RESPONSE_SET_ORIGINAL_ROLES.withProtocolName(name);
}

public boolean isProtocolHeader(String headerName)
{
for (Headers header : Headers.values()) {
if (header.withProtocolName(name).equalsIgnoreCase(headerName)) {
return true;
}
}
return false;
}

public String getProtocolName()
{
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort;
import io.airlift.units.Duration;
Expand Down Expand Up @@ -45,7 +44,6 @@
import static com.google.common.collect.Streams.stream;
import static io.trino.client.ClientSelectedRole.Type.ALL;
import static io.trino.client.ClientSelectedRole.Type.NONE;
import static io.trino.client.ProtocolHeaders.TRINO_HEADERS;
import static io.trino.client.uri.AbstractConnectionProperty.Validator;
import static io.trino.client.uri.AbstractConnectionProperty.validator;
import static io.trino.client.uri.ConnectionProperties.SslVerificationMode.FULL;
Expand Down Expand Up @@ -101,7 +99,6 @@ enum SslVerificationMode
public static final ConnectionProperty<String, Map<String, String>> EXTRA_CREDENTIALS = new ExtraCredentials();
public static final ConnectionProperty<String, String> CLIENT_INFO = new ClientInfo();
public static final ConnectionProperty<String, Set<String>> CLIENT_TAGS = new ClientTags();
public static final ConnectionProperty<String, Map<String, String>> EXTRA_HEADERS = new ExtraHeaders();
public static final ConnectionProperty<String, String> TRACE_TOKEN = new TraceToken();
public static final ConnectionProperty<String, Map<String, String>> SESSION_PROPERTIES = new SessionProperties();
public static final ConnectionProperty<String, String> SOURCE = new Source();
Expand Down Expand Up @@ -142,7 +139,6 @@ enum SslVerificationMode
.add(EXTERNAL_AUTHENTICATION_TIMEOUT)
.add(EXTERNAL_AUTHENTICATION_TOKEN_CACHE)
.add(EXTRA_CREDENTIALS)
.add(EXTRA_HEADERS)
.add(HOSTNAME_IN_CERTIFICATE)
.add(HTTP_LOGGING_LEVEL)
.add(HTTP_PROXY)
Expand Down Expand Up @@ -793,42 +789,6 @@ public static String toString(Map<String, String> values)
}
}

private static class ExtraHeaders
extends AbstractConnectionProperty<String, Map<String, String>>
{
private static final Validator<Properties> VALIDATE_EXTRA_HEADER = validator(
ExtraHeaders::isNotReservedHeader,
format("Connection property %s cannot override any of the Trino protocol headers", PropertyName.EXTRA_HEADERS));

public ExtraHeaders()
{
super(PropertyName.EXTRA_HEADERS, NOT_REQUIRED, VALIDATE_EXTRA_HEADER, converter(ExtraHeaders::parseExtraHeaders, ExtraHeaders::toString));
}

// Extra headers consists of a list of header name value pairs.
// E.g., `jdbc:trino://example.net:8080/?extraHeaders=X-Trino-Route:foo;X-Trino-Custom:bar` will send
// HTTP headers `X-Trino-Route=foo` and `X-Trino-Custom=bar`.
// These headers must not conflict with Trino protocol headers.
public static Map<String, String> parseExtraHeaders(String extraHeadersString)
{
return new MapPropertyParser(PropertyName.EXTRA_HEADERS.toString()).parse(extraHeadersString);
}

public static String toString(Map<String, String> values)
{
return values.entrySet().stream()
.map(entry -> entry.getKey() + ":" + entry.getValue())
.collect(Collectors.joining(";"));
}

private static boolean isNotReservedHeader(Properties properties)
{
Map<String, String> extraHeaders = EXTRA_HEADERS.getValueOrDefault(properties, ImmutableMap.of());
return extraHeaders.keySet().stream()
.noneMatch(TRINO_HEADERS::isProtocolHeader);
}
}

private static class SessionProperties
extends AbstractConnectionProperty<String, Map<String, String>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import static io.trino.client.KerberosUtil.defaultCredentialCachePath;
import static io.trino.client.OkHttpUtil.basicAuth;
import static io.trino.client.OkHttpUtil.extraHeaders;
import static io.trino.client.OkHttpUtil.setupAlternateHostnameVerification;
import static io.trino.client.OkHttpUtil.setupCookieJar;
import static io.trino.client.OkHttpUtil.setupHttpLogging;
Expand Down Expand Up @@ -88,10 +87,6 @@ public static OkHttpClient.Builder toHttpClientBuilder(TrinoUri uri, String user
builder.addNetworkInterceptor(tokenAuth(uri.getAccessToken().get()));
}

if (!uri.getExtraHeaders().isEmpty()) {
builder.addNetworkInterceptor(extraHeaders(uri.getExtraHeaders()));
}

if (uri.isExternalAuthenticationEnabled()) {
if (!uri.isUseSecureConnection()) {
throw new RuntimeException("TLS/SSL required for authentication using external authorization");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public enum PropertyName
CLIENT_INFO("clientInfo"),
CLIENT_TAGS("clientTags"),
DISABLE_COMPRESSION("disableCompression"),
EXTRA_HEADERS("extraHeaders"),
DNS_RESOLVER("dnsResolver"),
DNS_RESOLVER_CONTEXT("dnsResolverContext"),
ENCODING("encoding"),
Expand Down
Loading
Loading