From b2e58fb2db8d2bc65f7f7db60b04b5b3a6b4f784 Mon Sep 17 00:00:00 2001 From: Patryk Owczarek Date: Tue, 19 Nov 2024 14:17:07 +0100 Subject: [PATCH] Make RemoteS3Facade a plugin This allows implementations to provide their custom implementation of RemoteS3Facade, e.g. to support multiple S3 endpoints based on bucket / path. The existing RemoteS3Facade implementation is named "default" and provided by default. --- .../plugin/TrinoAwsProxyServerBinding.java | 7 +++ .../spi/plugin/config/RemoteS3Config.java | 38 +++++++++++++ .../aws/proxy/spi}/remote/RemoteS3Facade.java | 2 +- .../server/TrinoAwsProxyServerModule.java | 19 ++++--- .../credentials/CredentialsController.java | 2 +- ...Config.java => DefaultRemoteS3Config.java} | 12 ++-- .../server/remote/DefaultRemoteS3Facade.java | 41 ++++++++++++++ .../server/remote/DefaultRemoteS3Module.java | 55 +++++++++++++++++++ ...va => PathStyleDefaultRemoteS3Facade.java} | 7 ++- .../proxy/server/remote/RemoteS3Module.java | 36 ------------ ...irtualHostStyleDefaultRemoteS3Facade.java} | 7 ++- .../proxy/server/rest/TrinoS3ProxyClient.java | 2 +- ...ig.java => TestDefaultRemoteS3Config.java} | 6 +- ...> TestPathStyleDefaultRemoteS3Facade.java} | 11 ++-- ...irtualHostStyleDefaultRemoteS3Facade.java} | 19 ++++--- .../rest/TestProxiedErrorResponses.java | 4 +- .../server/testing/ContainerS3Facade.java | 18 +++--- .../server/testing/TestingRemoteS3Facade.java | 12 +++- .../testing/TestingTrinoAwsProxyServer.java | 10 +++- .../TestingTrinoAwsProxyServerModule.java | 8 --- .../TrinoAwsProxyTestCommonModules.java | 13 +++-- .../harness/TrinoAwsProxyTestExtension.java | 8 --- 22 files changed, 223 insertions(+), 114 deletions(-) create mode 100644 trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/config/RemoteS3Config.java rename {trino-aws-proxy/src/main/java/io/trino/aws/proxy/server => trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi}/remote/RemoteS3Facade.java (95%) rename trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/{RemoteS3Config.java => DefaultRemoteS3Config.java} (84%) create mode 100644 trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Facade.java create mode 100644 trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Module.java rename trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/{PathStyleRemoteS3Facade.java => PathStyleDefaultRemoteS3Facade.java} (85%) delete mode 100644 trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Module.java rename trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/{VirtualHostStyleRemoteS3Facade.java => VirtualHostStyleDefaultRemoteS3Facade.java} (84%) rename trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/{TestRemoteS3Config.java => TestDefaultRemoteS3Config.java} (86%) rename trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/{TestPathStyleRemoteS3Facade.java => TestPathStyleDefaultRemoteS3Facade.java} (68%) rename trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/{TestVirtualHostStyleRemoteS3Facade.java => TestVirtualHostStyleDefaultRemoteS3Facade.java} (64%) diff --git a/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/TrinoAwsProxyServerBinding.java b/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/TrinoAwsProxyServerBinding.java index dfe852e4..af36474c 100644 --- a/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/TrinoAwsProxyServerBinding.java +++ b/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/TrinoAwsProxyServerBinding.java @@ -24,8 +24,10 @@ import io.trino.aws.proxy.spi.plugin.config.AssumedRoleProviderConfig; import io.trino.aws.proxy.spi.plugin.config.CredentialsProviderConfig; import io.trino.aws.proxy.spi.plugin.config.PluginIdentifierConfig; +import io.trino.aws.proxy.spi.plugin.config.RemoteS3Config; import io.trino.aws.proxy.spi.plugin.config.S3RequestRewriterConfig; import io.trino.aws.proxy.spi.plugin.config.S3SecurityFacadeProviderConfig; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import io.trino.aws.proxy.spi.rest.S3RequestRewriter; import io.trino.aws.proxy.spi.security.S3SecurityFacadeProvider; @@ -57,6 +59,11 @@ static Module s3RequestRewriterModule(String identifier, Class implementationClass, Module module) + { + return optionalPluginModule(RemoteS3Config.class, identifier, RemoteS3Facade.class, implementationClass, module); + } + static void bindIdentityType(Binder binder, Class type) { newOptionalBinder(binder, new TypeLiteral>() {}).setBinding().toProvider(() -> { diff --git a/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/config/RemoteS3Config.java b/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/config/RemoteS3Config.java new file mode 100644 index 00000000..c08c9d06 --- /dev/null +++ b/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/plugin/config/RemoteS3Config.java @@ -0,0 +1,38 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.aws.proxy.spi.plugin.config; + +import io.airlift.configuration.Config; +import jakarta.validation.constraints.NotNull; + +import java.util.Optional; + +public class RemoteS3Config + implements PluginIdentifierConfig +{ + private Optional identifier = Optional.of("default"); + + @NotNull + @Override + public Optional getPluginIdentifier() + { + return identifier; + } + + @Config("remote-s3.type") + public void setPluginIdentifier(String identifier) + { + this.identifier = Optional.of(identifier); + } +} diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Facade.java b/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/remote/RemoteS3Facade.java similarity index 95% rename from trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Facade.java rename to trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/remote/RemoteS3Facade.java index 77e714e9..5d71863d 100644 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Facade.java +++ b/trino-aws-proxy-spi/src/main/java/io/trino/aws/proxy/spi/remote/RemoteS3Facade.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.trino.aws.proxy.server.remote; +package io.trino.aws.proxy.spi.remote; import jakarta.ws.rs.core.UriBuilder; diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/TrinoAwsProxyServerModule.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/TrinoAwsProxyServerModule.java index aa3f824f..1c839a08 100644 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/TrinoAwsProxyServerModule.java +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/TrinoAwsProxyServerModule.java @@ -33,7 +33,8 @@ import io.trino.aws.proxy.server.credentials.JsonIdentityProvider; import io.trino.aws.proxy.server.credentials.file.FileBasedCredentialsModule; import io.trino.aws.proxy.server.credentials.http.HttpCredentialsModule; -import io.trino.aws.proxy.server.remote.RemoteS3Module; +import io.trino.aws.proxy.server.remote.DefaultRemoteS3Facade; +import io.trino.aws.proxy.server.remote.DefaultRemoteS3Module; import io.trino.aws.proxy.server.rest.LimitStreamController; import io.trino.aws.proxy.server.rest.ParamProvider; import io.trino.aws.proxy.server.rest.RequestLoggerController; @@ -57,6 +58,7 @@ import io.trino.aws.proxy.spi.plugin.TrinoAwsProxyServerPlugin; import io.trino.aws.proxy.spi.plugin.config.AssumedRoleProviderConfig; import io.trino.aws.proxy.spi.plugin.config.CredentialsProviderConfig; +import io.trino.aws.proxy.spi.plugin.config.RemoteS3Config; import io.trino.aws.proxy.spi.plugin.config.S3RequestRewriterConfig; import io.trino.aws.proxy.spi.plugin.config.S3SecurityFacadeProviderConfig; import io.trino.aws.proxy.spi.rest.S3RequestRewriter; @@ -74,6 +76,8 @@ import static io.airlift.http.client.HttpClientBinder.httpClientBinder; import static io.airlift.http.server.HttpServerBinder.httpServerBinder; import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder; +import static io.trino.aws.proxy.server.remote.DefaultRemoteS3Module.DEFAULT_REMOTE_S3_IDENTIFIER; +import static io.trino.aws.proxy.spi.plugin.TrinoAwsProxyServerBinding.remoteS3Module; public class TrinoAwsProxyServerModule extends AbstractConfigurationAwareModule @@ -147,8 +151,13 @@ protected void setup(Binder binder) return AssumedRoleProvider.NOOP; }); + // RemoteS3 binder + configBinder(binder).bindConfig(RemoteS3Config.class); + + // RemoteS3 provided implementations + install(remoteS3Module(DEFAULT_REMOTE_S3_IDENTIFIER, DefaultRemoteS3Facade.class, new DefaultRemoteS3Module())); + installSigningController(binder); - installRemoteS3Facade(binder); installS3SecurityController(binder); installPlugins(); @@ -167,12 +176,6 @@ public XmlMapper newXmlMapper() return xmlMapper; } - @VisibleForTesting - protected void installRemoteS3Facade(Binder binder) - { - install(new RemoteS3Module()); - } - @VisibleForTesting protected void installS3SecurityController(Binder binder) { diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/credentials/CredentialsController.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/credentials/CredentialsController.java index 0ead0edf..262e6eaf 100644 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/credentials/CredentialsController.java +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/credentials/CredentialsController.java @@ -15,10 +15,10 @@ import com.google.inject.Inject; import io.airlift.log.Logger; -import io.trino.aws.proxy.server.remote.RemoteS3Facade; import io.trino.aws.proxy.spi.credentials.Credential; import io.trino.aws.proxy.spi.credentials.Credentials; import io.trino.aws.proxy.spi.credentials.CredentialsProvider; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import io.trino.aws.proxy.spi.remote.RemoteSessionRole; import jakarta.annotation.PreDestroy; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Config.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Config.java similarity index 84% rename from trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Config.java rename to trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Config.java index e7657134..88309d89 100644 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Config.java +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Config.java @@ -20,7 +20,7 @@ import java.util.Optional; -public class RemoteS3Config +public class DefaultRemoteS3Config { private boolean https = true; private String domain = "amazonaws.com"; @@ -29,35 +29,35 @@ public class RemoteS3Config private String hostnameTemplate = "${bucket}.s3.${region}.${domain}"; @Config("remoteS3.https") - public RemoteS3Config setHttps(boolean https) + public DefaultRemoteS3Config setHttps(boolean https) { this.https = https; return this; } @Config("remoteS3.domain") - public RemoteS3Config setDomain(String s3Domain) + public DefaultRemoteS3Config setDomain(String s3Domain) { this.domain = s3Domain; return this; } @Config("remoteS3.port") - public RemoteS3Config setPort(Integer port) + public DefaultRemoteS3Config setPort(Integer port) { this.port = Optional.ofNullable(port); return this; } @Config("remoteS3.virtual-host-style") - public RemoteS3Config setVirtualHostStyle(boolean virtualHostStyle) + public DefaultRemoteS3Config setVirtualHostStyle(boolean virtualHostStyle) { this.virtualHostStyle = virtualHostStyle; return this; } @Config("remoteS3.hostname.template") - public RemoteS3Config setHostnameTemplate(String hostnameTemplate) + public DefaultRemoteS3Config setHostnameTemplate(String hostnameTemplate) { this.hostnameTemplate = hostnameTemplate; return this; diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Facade.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Facade.java new file mode 100644 index 00000000..e1b87786 --- /dev/null +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Facade.java @@ -0,0 +1,41 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.aws.proxy.server.remote; + +import com.google.inject.Inject; +import io.trino.aws.proxy.server.remote.DefaultRemoteS3Module.ForDefaultRemoteS3Facade; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; +import jakarta.ws.rs.core.UriBuilder; + +import java.net.URI; + +import static java.util.Objects.requireNonNull; + +public class DefaultRemoteS3Facade + implements RemoteS3Facade +{ + private final RemoteS3Facade delegate; + + @Inject + public DefaultRemoteS3Facade(@ForDefaultRemoteS3Facade RemoteS3Facade delegate) + { + this.delegate = requireNonNull(delegate, "delegate is null"); + } + + @Override + public URI buildEndpoint(UriBuilder uriBuilder, String path, String bucket, String region) + { + return delegate.buildEndpoint(uriBuilder, path, bucket, region); + } +} diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Module.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Module.java new file mode 100644 index 00000000..5cfdeaaf --- /dev/null +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/DefaultRemoteS3Module.java @@ -0,0 +1,55 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.aws.proxy.server.remote; + +import com.google.inject.Binder; +import com.google.inject.BindingAnnotation; +import com.google.inject.Key; +import com.google.inject.Scopes; +import io.airlift.configuration.AbstractConfigurationAwareModule; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static io.airlift.configuration.ConditionalModule.conditionalModule; +import static io.airlift.configuration.ConfigBinder.configBinder; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +public class DefaultRemoteS3Module + extends AbstractConfigurationAwareModule +{ + public static final String DEFAULT_REMOTE_S3_IDENTIFIER = "default"; + + @Override + protected void setup(Binder binder) + { + configBinder(binder).bindConfig(DefaultRemoteS3Config.class); + install(conditionalModule( + DefaultRemoteS3Config.class, + DefaultRemoteS3Config::getVirtualHostStyle, + innerBinder -> innerBinder.bind(Key.get(RemoteS3Facade.class, ForDefaultRemoteS3Facade.class)) + .to(VirtualHostStyleDefaultRemoteS3Facade.class).in(Scopes.SINGLETON), + innerBinder -> innerBinder.bind(Key.get(RemoteS3Facade.class, ForDefaultRemoteS3Facade.class)) + .to(PathStyleDefaultRemoteS3Facade.class).in(Scopes.SINGLETON))); + } + + @Retention(RUNTIME) + @Target({FIELD, PARAMETER, METHOD}) + @BindingAnnotation + public @interface ForDefaultRemoteS3Facade {} +} diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/PathStyleRemoteS3Facade.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/PathStyleDefaultRemoteS3Facade.java similarity index 85% rename from trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/PathStyleRemoteS3Facade.java rename to trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/PathStyleDefaultRemoteS3Facade.java index 6ff4c31f..00bf95b4 100644 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/PathStyleRemoteS3Facade.java +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/PathStyleDefaultRemoteS3Facade.java @@ -14,6 +14,7 @@ package io.trino.aws.proxy.server.remote; import com.google.inject.Inject; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import jakarta.ws.rs.core.UriBuilder; import java.net.URI; @@ -21,7 +22,7 @@ import static java.util.Objects.requireNonNull; -public class PathStyleRemoteS3Facade +public class PathStyleDefaultRemoteS3Facade implements RemoteS3Facade { private final RemoteS3HostBuilder hostBuilder; @@ -29,12 +30,12 @@ public class PathStyleRemoteS3Facade private final Optional port; @Inject - public PathStyleRemoteS3Facade(RemoteS3Config remoteS3Config) + public PathStyleDefaultRemoteS3Facade(DefaultRemoteS3Config remoteS3Config) { this((bucket, region) -> RemoteS3HostBuilder.getHostName(bucket, region, remoteS3Config.getDomain(), remoteS3Config.getHostnameTemplate()), remoteS3Config.getHttps(), remoteS3Config.getPort()); } - public PathStyleRemoteS3Facade(RemoteS3HostBuilder hostBuilder, boolean https, Optional port) + public PathStyleDefaultRemoteS3Facade(RemoteS3HostBuilder hostBuilder, boolean https, Optional port) { this.hostBuilder = requireNonNull(hostBuilder, "hostBuilder is null"); this.port = requireNonNull(port, "port is null"); diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Module.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Module.java deleted file mode 100644 index f4025c34..00000000 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Module.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.aws.proxy.server.remote; - -import com.google.inject.Binder; -import com.google.inject.Scopes; -import io.airlift.configuration.AbstractConfigurationAwareModule; - -import static io.airlift.configuration.ConditionalModule.conditionalModule; -import static io.airlift.configuration.ConfigBinder.configBinder; - -public class RemoteS3Module - extends AbstractConfigurationAwareModule -{ - @Override - protected void setup(Binder binder) - { - configBinder(binder).bindConfig(RemoteS3Config.class); - install(conditionalModule( - RemoteS3Config.class, - RemoteS3Config::getVirtualHostStyle, - innerBinder -> innerBinder.bind(RemoteS3Facade.class).to(VirtualHostStyleRemoteS3Facade.class).in(Scopes.SINGLETON), - innerBinder -> innerBinder.bind(RemoteS3Facade.class).to(PathStyleRemoteS3Facade.class).in(Scopes.SINGLETON))); - } -} diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/VirtualHostStyleRemoteS3Facade.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/VirtualHostStyleDefaultRemoteS3Facade.java similarity index 84% rename from trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/VirtualHostStyleRemoteS3Facade.java rename to trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/VirtualHostStyleDefaultRemoteS3Facade.java index f5cf249f..2dc7935e 100644 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/VirtualHostStyleRemoteS3Facade.java +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/VirtualHostStyleDefaultRemoteS3Facade.java @@ -14,6 +14,7 @@ package io.trino.aws.proxy.server.remote; import com.google.inject.Inject; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import jakarta.ws.rs.core.UriBuilder; import java.net.URI; @@ -21,7 +22,7 @@ import static java.util.Objects.requireNonNull; -public class VirtualHostStyleRemoteS3Facade +public class VirtualHostStyleDefaultRemoteS3Facade implements RemoteS3Facade { private final RemoteS3HostBuilder hostBuilder; @@ -29,12 +30,12 @@ public class VirtualHostStyleRemoteS3Facade private final Optional port; @Inject - public VirtualHostStyleRemoteS3Facade(RemoteS3Config remoteS3Config) + public VirtualHostStyleDefaultRemoteS3Facade(DefaultRemoteS3Config remoteS3Config) { this((bucket, region) -> RemoteS3HostBuilder.getHostName(bucket, region, remoteS3Config.getDomain(), remoteS3Config.getHostnameTemplate()), remoteS3Config.getHttps(), remoteS3Config.getPort()); } - public VirtualHostStyleRemoteS3Facade(RemoteS3HostBuilder hostBuilder, boolean https, Optional port) + public VirtualHostStyleDefaultRemoteS3Facade(RemoteS3HostBuilder hostBuilder, boolean https, Optional port) { this.hostBuilder = requireNonNull(hostBuilder, "hostBuilder is null"); this.port = requireNonNull(port, "port is null"); diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/TrinoS3ProxyClient.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/TrinoS3ProxyClient.java index 92f5325c..0837887a 100644 --- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/TrinoS3ProxyClient.java +++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/TrinoS3ProxyClient.java @@ -20,9 +20,9 @@ import io.airlift.http.client.Request; import io.airlift.log.Logger; import io.trino.aws.proxy.server.TrinoAwsProxyConfig; -import io.trino.aws.proxy.server.remote.RemoteS3Facade; import io.trino.aws.proxy.server.security.S3SecurityController; import io.trino.aws.proxy.spi.credentials.Credentials; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import io.trino.aws.proxy.spi.rest.ParsedS3Request; import io.trino.aws.proxy.spi.rest.RequestContent; import io.trino.aws.proxy.spi.rest.S3RequestRewriter; diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestRemoteS3Config.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestDefaultRemoteS3Config.java similarity index 86% rename from trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestRemoteS3Config.java rename to trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestDefaultRemoteS3Config.java index a89ad96a..2b1615f4 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestRemoteS3Config.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestDefaultRemoteS3Config.java @@ -22,12 +22,12 @@ import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; -public class TestRemoteS3Config +public class TestDefaultRemoteS3Config { @Test public void testDefaults() { - assertRecordedDefaults(recordDefaults(RemoteS3Config.class) + assertRecordedDefaults(recordDefaults(DefaultRemoteS3Config.class) .setDomain("amazonaws.com").setHttps(true).setPort(null) .setVirtualHostStyle(true) .setHostnameTemplate("${bucket}.s3.${region}.${domain}")); @@ -43,7 +43,7 @@ public void testExplicitPropertyMappings() "remoteS3.virtual-host-style", "false", "remoteS3.hostname.template", "s3.${region}.${domain}"); - RemoteS3Config expected = new RemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80).setVirtualHostStyle(false) + DefaultRemoteS3Config expected = new DefaultRemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80).setVirtualHostStyle(false) .setHostnameTemplate("s3.${region}.${domain}"); assertFullMapping(properties, expected); } diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestPathStyleRemoteS3Facade.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestPathStyleDefaultRemoteS3Facade.java similarity index 68% rename from trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestPathStyleRemoteS3Facade.java rename to trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestPathStyleDefaultRemoteS3Facade.java index 7b983f8e..c52f5d0b 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestPathStyleRemoteS3Facade.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestPathStyleDefaultRemoteS3Facade.java @@ -13,6 +13,7 @@ */ package io.trino.aws.proxy.server.remote; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import jakarta.ws.rs.core.UriBuilder; import org.junit.jupiter.api.Test; @@ -20,13 +21,13 @@ import static org.assertj.core.api.Assertions.assertThat; -public class TestPathStyleRemoteS3Facade +public class TestPathStyleDefaultRemoteS3Facade { @Test public void testBuildEndpoint() { - RemoteS3Config remoteS3Config = new RemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80).setVirtualHostStyle(false).setHostnameTemplate("s3.${region}.${domain}"); - RemoteS3Facade remoteS3Facade = new PathStyleRemoteS3Facade(remoteS3Config); + DefaultRemoteS3Config remoteS3Config = new DefaultRemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80).setVirtualHostStyle(false).setHostnameTemplate("s3.${region}.${domain}"); + RemoteS3Facade remoteS3Facade = new PathStyleDefaultRemoteS3Facade(remoteS3Config); URI expectedEndpoint = UriBuilder.fromUri("http://s3.us-east-1.testS3Domain.com:80/test_bucket/object_path/foo").build(); URI actual = remoteS3Facade.buildEndpoint(UriBuilder.newInstance(), "object_path/foo", "test_bucket", "us-east-1"); assertThat(actual).isEqualTo(expectedEndpoint); @@ -35,8 +36,8 @@ public void testBuildEndpoint() @Test public void testBuildEndpointWithoutRegion() { - RemoteS3Config remoteS3Config = new RemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setVirtualHostStyle(false).setHostnameTemplate("s3.${domain}"); - RemoteS3Facade remoteS3Facade = new PathStyleRemoteS3Facade(remoteS3Config); + DefaultRemoteS3Config remoteS3Config = new DefaultRemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setVirtualHostStyle(false).setHostnameTemplate("s3.${domain}"); + RemoteS3Facade remoteS3Facade = new PathStyleDefaultRemoteS3Facade(remoteS3Config); URI expectedEndpoint = UriBuilder.fromUri("https://s3.testS3Domain.com:80/test_bucket/object_path/foo").build(); URI actual = remoteS3Facade.buildEndpoint(UriBuilder.newInstance(), "object_path/foo", "test_bucket", "us-east-1"); assertThat(actual).isEqualTo(expectedEndpoint); diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestVirtualHostStyleRemoteS3Facade.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestVirtualHostStyleDefaultRemoteS3Facade.java similarity index 64% rename from trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestVirtualHostStyleRemoteS3Facade.java rename to trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestVirtualHostStyleDefaultRemoteS3Facade.java index 1c8b1b8d..2279201e 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestVirtualHostStyleRemoteS3Facade.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestVirtualHostStyleDefaultRemoteS3Facade.java @@ -13,6 +13,7 @@ */ package io.trino.aws.proxy.server.remote; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import jakarta.ws.rs.core.UriBuilder; import org.junit.jupiter.api.Test; @@ -20,13 +21,13 @@ import static org.assertj.core.api.Assertions.assertThat; -public class TestVirtualHostStyleRemoteS3Facade +public class TestVirtualHostStyleDefaultRemoteS3Facade { @Test public void testBuildEndpoint() { - RemoteS3Config remoteS3Config = new RemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80); - RemoteS3Facade remoteS3Facade = new VirtualHostStyleRemoteS3Facade(remoteS3Config); + DefaultRemoteS3Config remoteS3Config = new DefaultRemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80); + RemoteS3Facade remoteS3Facade = new VirtualHostStyleDefaultRemoteS3Facade(remoteS3Config); URI expectedEndpoint = UriBuilder.fromUri("http://test_bucket.s3.us-east-1.testS3Domain.com:80/object_path/foo").build(); URI actual = remoteS3Facade.buildEndpoint(UriBuilder.newInstance(), "object_path/foo", "test_bucket", "us-east-1"); assertThat(actual).isEqualTo(expectedEndpoint); @@ -35,8 +36,8 @@ public void testBuildEndpoint() @Test public void testBuildEndpointWithoutRegion() { - RemoteS3Config remoteS3Config = new RemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setHostnameTemplate("${bucket}.s3.${domain}"); - RemoteS3Facade remoteS3Facade = new VirtualHostStyleRemoteS3Facade(remoteS3Config); + DefaultRemoteS3Config remoteS3Config = new DefaultRemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setHostnameTemplate("${bucket}.s3.${domain}"); + RemoteS3Facade remoteS3Facade = new VirtualHostStyleDefaultRemoteS3Facade(remoteS3Config); URI expectedEndpoint = UriBuilder.fromUri("https://test_bucket.s3.testS3Domain.com:80/object_path/foo").build(); URI actual = remoteS3Facade.buildEndpoint(UriBuilder.newInstance(), "object_path/foo", "test_bucket", "us-east-1"); assertThat(actual).isEqualTo(expectedEndpoint); @@ -45,8 +46,8 @@ public void testBuildEndpointWithoutRegion() @Test public void testBuildEndpointWithEmptyBucketTemplate1() { - RemoteS3Config remoteS3Config = new RemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setHostnameTemplate("${bucket}.s3.${region}.${domain}"); - RemoteS3Facade remoteS3Facade = new VirtualHostStyleRemoteS3Facade(remoteS3Config); + DefaultRemoteS3Config remoteS3Config = new DefaultRemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setHostnameTemplate("${bucket}.s3.${region}.${domain}"); + RemoteS3Facade remoteS3Facade = new VirtualHostStyleDefaultRemoteS3Facade(remoteS3Config); URI expectedEndpoint = UriBuilder.fromUri("https://s3.us-east-1.testS3Domain.com:80").build(); URI actual = remoteS3Facade.buildEndpoint(UriBuilder.newInstance(), "", "", "us-east-1"); assertThat(actual).isEqualTo(expectedEndpoint); @@ -55,8 +56,8 @@ public void testBuildEndpointWithEmptyBucketTemplate1() @Test public void testBuildEndpointWithEmptyBucketTemplate2() { - RemoteS3Config remoteS3Config = new RemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setHostnameTemplate("s3.${bucket}.${region}.${domain}"); - RemoteS3Facade remoteS3Facade = new VirtualHostStyleRemoteS3Facade(remoteS3Config); + DefaultRemoteS3Config remoteS3Config = new DefaultRemoteS3Config().setHttps(true).setDomain("testS3Domain.com").setPort(80).setHostnameTemplate("s3.${bucket}.${region}.${domain}"); + RemoteS3Facade remoteS3Facade = new VirtualHostStyleDefaultRemoteS3Facade(remoteS3Config); URI expectedEndpoint = UriBuilder.fromUri("https://s3.us-east-1.testS3Domain.com:80").build(); URI actual = remoteS3Facade.buildEndpoint(UriBuilder.newInstance(), "", "", "us-east-1"); assertThat(actual).isEqualTo(expectedEndpoint); diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/rest/TestProxiedErrorResponses.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/rest/TestProxiedErrorResponses.java index 20585a24..011dfbfa 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/rest/TestProxiedErrorResponses.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/rest/TestProxiedErrorResponses.java @@ -19,7 +19,7 @@ import com.google.inject.Key; import io.airlift.http.client.HttpStatus; import io.airlift.http.server.testing.TestingHttpServer; -import io.trino.aws.proxy.server.remote.PathStyleRemoteS3Facade; +import io.trino.aws.proxy.server.remote.PathStyleDefaultRemoteS3Facade; import io.trino.aws.proxy.server.testing.TestingRemoteS3Facade; import io.trino.aws.proxy.server.testing.TestingTrinoAwsProxyServer.Builder; import io.trino.aws.proxy.server.testing.harness.BuilderFilter; @@ -98,7 +98,7 @@ public Builder filter(Builder builder) public TestProxiedErrorResponses(S3Client internalClient, TestingRemoteS3Facade delegatingFacade, @ForErrorResponseTest TestingHttpServer httpErrorResponseServer) { this.internalClient = requireNonNull(internalClient, "internal client is null"); - delegatingFacade.setDelegate(new PathStyleRemoteS3Facade((_, _) -> httpErrorResponseServer.getBaseUrl().getHost(), false, Optional.of(httpErrorResponseServer.getBaseUrl().getPort()))); + delegatingFacade.setDelegate(new PathStyleDefaultRemoteS3Facade((_, _) -> httpErrorResponseServer.getBaseUrl().getHost(), false, Optional.of(httpErrorResponseServer.getBaseUrl().getPort()))); } @Test diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/ContainerS3Facade.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/ContainerS3Facade.java index 351abc77..c4dda26a 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/ContainerS3Facade.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/ContainerS3Facade.java @@ -14,8 +14,8 @@ package io.trino.aws.proxy.server.testing; import com.google.inject.Inject; -import io.trino.aws.proxy.server.remote.PathStyleRemoteS3Facade; -import io.trino.aws.proxy.server.remote.VirtualHostStyleRemoteS3Facade; +import io.trino.aws.proxy.server.remote.PathStyleDefaultRemoteS3Facade; +import io.trino.aws.proxy.server.remote.VirtualHostStyleDefaultRemoteS3Facade; import io.trino.aws.proxy.server.testing.containers.S3Container; import java.util.Optional; @@ -24,25 +24,23 @@ public final class ContainerS3Facade { - public static class PathStyleContainerS3Facade - extends PathStyleRemoteS3Facade + public static class PathStyleDefaultContainerS3Facade + extends PathStyleDefaultRemoteS3Facade { @Inject - public PathStyleContainerS3Facade(S3Container s3Container, TestingRemoteS3Facade delegatingFacade) + public PathStyleDefaultContainerS3Facade(S3Container s3Container) { super((ignored1, ignored2) -> s3Container.containerHost().getHost(), false, Optional.of(s3Container.containerHost().getPort())); - delegatingFacade.setDelegate(this); } } - public static class VirtualHostStyleContainerS3Facade - extends VirtualHostStyleRemoteS3Facade + public static class VirtualHostStyleDefaultContainerS3Facade + extends VirtualHostStyleDefaultRemoteS3Facade { @Inject - public VirtualHostStyleContainerS3Facade(S3Container s3Container, TestingRemoteS3Facade delegatingFacade) + public VirtualHostStyleDefaultContainerS3Facade(S3Container s3Container) { super((bucket, ignored) -> bucket.isEmpty() ? LOCALHOST_DOMAIN : "%s.%s".formatted(bucket, LOCALHOST_DOMAIN), false, Optional.of(s3Container.containerHost().getPort())); - delegatingFacade.setDelegate(this); } } } diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingRemoteS3Facade.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingRemoteS3Facade.java index afff1a48..eb7aa652 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingRemoteS3Facade.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingRemoteS3Facade.java @@ -13,7 +13,9 @@ */ package io.trino.aws.proxy.server.testing; -import io.trino.aws.proxy.server.remote.RemoteS3Facade; +import com.google.inject.Inject; +import io.trino.aws.proxy.server.testing.TestingUtil.ForTesting; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import jakarta.ws.rs.core.UriBuilder; import java.net.URI; @@ -26,6 +28,14 @@ public class TestingRemoteS3Facade { private final AtomicReference delegate = new AtomicReference<>(); + public TestingRemoteS3Facade() {} + + @Inject + public TestingRemoteS3Facade(@ForTesting RemoteS3Facade delegate) + { + setDelegate(delegate); + } + @Override public URI buildEndpoint(UriBuilder uriBuilder, String path, String bucket, String region) { diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServer.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServer.java index a90b2917..62fd195c 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServer.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServer.java @@ -30,7 +30,6 @@ import io.airlift.log.Level; import io.airlift.log.Logging; import io.airlift.node.testing.TestingNodeModule; -import io.trino.aws.proxy.server.remote.RemoteS3Facade; import io.trino.aws.proxy.server.testing.TestingTrinoAwsProxyServerModule.ForTestingRemoteCredentials; import io.trino.aws.proxy.server.testing.TestingUtil.ForTesting; import io.trino.aws.proxy.server.testing.containers.MetastoreContainer; @@ -42,6 +41,7 @@ import io.trino.aws.proxy.server.testing.containers.S3Container; import io.trino.aws.proxy.server.testing.containers.S3Container.ForS3Container; import io.trino.aws.proxy.spi.credentials.Credentials; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import java.io.Closeable; import java.util.Collection; @@ -52,6 +52,7 @@ import static io.trino.aws.proxy.server.testing.TestingUtil.TESTING_CREDENTIALS; import static io.trino.aws.proxy.spi.plugin.TrinoAwsProxyServerBinding.assumedRoleProviderModule; import static io.trino.aws.proxy.spi.plugin.TrinoAwsProxyServerBinding.credentialsProviderModule; +import static io.trino.aws.proxy.spi.plugin.TrinoAwsProxyServerBinding.remoteS3Module; public final class TestingTrinoAwsProxyServer implements Closeable @@ -116,8 +117,8 @@ public Builder withS3Container() newOptionalBinder(binder, Key.get(RemoteS3Facade.class, ForTesting.class)) .setDefault() - .to(ContainerS3Facade.PathStyleContainerS3Facade.class) - .asEagerSingleton(); + .to(ContainerS3Facade.PathStyleDefaultContainerS3Facade.class) + .in(Scopes.SINGLETON); }); return this; } @@ -222,6 +223,9 @@ public TestingTrinoAwsProxyServer buildAndStart() modules.add(binder -> binder.bind(Credentials.class).annotatedWith(ForTestingRemoteCredentials.class).toProvider(TestingRemoteCredentialsProvider.class)); } + addModule(remoteS3Module("testing", TestingRemoteS3Facade.class, (binder) -> binder.bind(TestingRemoteS3Facade.class).in(Scopes.SINGLETON))); + withProperty("remote-s3.type", "testing"); + return start(modules.build(), properties.buildKeepingLast()); } } diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServerModule.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServerModule.java index 2c771cc4..f3a60226 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServerModule.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingTrinoAwsProxyServerModule.java @@ -17,7 +17,6 @@ import com.google.inject.BindingAnnotation; import com.google.inject.Scopes; import io.trino.aws.proxy.server.TrinoAwsProxyServerModule; -import io.trino.aws.proxy.server.remote.RemoteS3Facade; import io.trino.aws.proxy.server.rest.S3PresignController; import io.trino.aws.proxy.server.security.S3SecurityController; @@ -37,13 +36,6 @@ public class TestingTrinoAwsProxyServerModule @BindingAnnotation public @interface ForTestingRemoteCredentials {} - @Override - protected void installRemoteS3Facade(Binder binder) - { - binder.bind(RemoteS3Facade.class).to(TestingRemoteS3Facade.class).in(Scopes.SINGLETON); - binder.bind(TestingRemoteS3Facade.class).in(Scopes.SINGLETON); - } - @Override protected void installS3SecurityController(Binder binder) { diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestCommonModules.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestCommonModules.java index 3bdbba92..28e58f36 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestCommonModules.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestCommonModules.java @@ -15,16 +15,17 @@ import com.google.common.collect.ImmutableList; import com.google.inject.Key; +import com.google.inject.Scopes; import com.google.inject.TypeLiteral; -import com.google.inject.multibindings.OptionalBinder; -import io.trino.aws.proxy.server.remote.RemoteS3Facade; import io.trino.aws.proxy.server.testing.ContainerS3Facade; import io.trino.aws.proxy.server.testing.TestingTrinoAwsProxyServer; import io.trino.aws.proxy.server.testing.TestingUtil.ForTesting; import io.trino.aws.proxy.server.testing.containers.S3Container.ForS3Container; +import io.trino.aws.proxy.spi.remote.RemoteS3Facade; import java.util.List; +import static com.google.inject.multibindings.OptionalBinder.newOptionalBinder; import static io.airlift.http.client.HttpClientBinder.httpClientBinder; import static io.trino.aws.proxy.server.testing.TestingUtil.LOCALHOST_DOMAIN; @@ -39,7 +40,7 @@ public static class WithConfiguredBuckets public TestingTrinoAwsProxyServer.Builder filter(TestingTrinoAwsProxyServer.Builder builder) { return builder.addModule(binder -> - OptionalBinder.newOptionalBinder(binder, Key.get(new TypeLiteral>() {}, ForS3Container.class)) + newOptionalBinder(binder, Key.get(new TypeLiteral>() {}, ForS3Container.class)) .setBinding() .toInstance(CONFIGURED_BUCKETS)); } @@ -52,10 +53,10 @@ public static class WithVirtualHostAddressing public TestingTrinoAwsProxyServer.Builder filter(TestingTrinoAwsProxyServer.Builder builder) { return builder.addModule(binder -> - OptionalBinder.newOptionalBinder(binder, Key.get(RemoteS3Facade.class, ForTesting.class)) + newOptionalBinder(binder, Key.get(RemoteS3Facade.class, ForTesting.class)) .setBinding() - .to(ContainerS3Facade.VirtualHostStyleContainerS3Facade.class) - .asEagerSingleton()); + .to(ContainerS3Facade.VirtualHostStyleDefaultContainerS3Facade.class) + .in(Scopes.SINGLETON)); } } diff --git a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestExtension.java b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestExtension.java index cd5e2e97..950aa632 100644 --- a/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestExtension.java +++ b/trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/harness/TrinoAwsProxyTestExtension.java @@ -14,15 +14,11 @@ package io.trino.aws.proxy.server.testing.harness; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Scopes; -import io.trino.aws.proxy.server.remote.RemoteS3Facade; -import io.trino.aws.proxy.server.testing.ContainerS3Facade; import io.trino.aws.proxy.server.testing.TestingS3ClientModule; import io.trino.aws.proxy.server.testing.TestingS3RequestRewriteController; import io.trino.aws.proxy.server.testing.TestingS3RequestRewriter; import io.trino.aws.proxy.server.testing.TestingTrinoAwsProxyServer; -import io.trino.aws.proxy.server.testing.TestingUtil.ForTesting; import io.trino.aws.proxy.server.testing.containers.S3Container; import io.trino.aws.proxy.server.testing.containers.S3Container.ForS3Container; import org.junit.jupiter.api.extension.ExtensionContext; @@ -64,10 +60,6 @@ public Object createTestInstance(TestInstanceFactoryContext factoryContext, Exte .withS3Container() .addModule(binder -> { binder.bind(S3Client.class).annotatedWith(ForS3Container.class).toProvider(S3Container.class); - newOptionalBinder(binder, Key.get(RemoteS3Facade.class, ForTesting.class)) - .setDefault() - .to(ContainerS3Facade.PathStyleContainerS3Facade.class) - .asEagerSingleton(); newOptionalBinder(binder, TestingS3RequestRewriter.class).setDefault().toInstance(TestingS3RequestRewriter.NOOP); binder.bind(TestingS3RequestRewriteController.class).in(Scopes.SINGLETON); })