-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
318 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/AwsRemoteS3FacadeConstants.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 io.airlift.configuration.Config; | ||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.Optional; | ||
|
||
public class RemoteS3Config | ||
{ | ||
private boolean https = true; | ||
private String domain = "amazonaws.com"; | ||
private Optional<@Min(1) @Max(65535) Integer> port = Optional.empty(); | ||
private boolean virtualHostStyle = true; | ||
private String hostnameTemplate = "${bucket}.s3.${region}.${domain}"; | ||
|
||
@Config("remoteS3.https") | ||
public RemoteS3Config setHttps(boolean https) | ||
{ | ||
this.https = https; | ||
return this; | ||
} | ||
|
||
@Config("remoteS3.domain") | ||
public RemoteS3Config setDomain(String s3Domain) | ||
{ | ||
this.domain = s3Domain; | ||
return this; | ||
} | ||
|
||
@Config("remoteS3.port") | ||
public RemoteS3Config setPort(Integer port) | ||
{ | ||
this.port = Optional.ofNullable(port); | ||
return this; | ||
} | ||
|
||
@Config("remoteS3.virtual-host-style") | ||
public RemoteS3Config setVirtualHostStyle(boolean virtualHostStyle) | ||
{ | ||
this.virtualHostStyle = virtualHostStyle; | ||
return this; | ||
} | ||
|
||
@Config("remoteS3.hostname.template") | ||
public RemoteS3Config setHostnameTemplate(String hostnameTemplate) | ||
{ | ||
this.hostnameTemplate = hostnameTemplate; | ||
return this; | ||
} | ||
|
||
public boolean getHttps() | ||
{ | ||
return https; | ||
} | ||
|
||
@NotNull | ||
public String getDomain() | ||
{ | ||
return domain; | ||
} | ||
|
||
@NotNull | ||
public Optional<Integer> getPort() | ||
{ | ||
return port; | ||
} | ||
|
||
public boolean getVirtualHostStyle() | ||
{ | ||
return virtualHostStyle; | ||
} | ||
|
||
@NotNull | ||
public String getHostnameTemplate() | ||
{ | ||
return hostnameTemplate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/remote/RemoteS3Module.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestPathStyleRemoteS3Facade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 jakarta.ws.rs.core.UriBuilder; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.URI; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestPathStyleRemoteS3Facade | ||
{ | ||
@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); | ||
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); | ||
} | ||
|
||
@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); | ||
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); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/remote/TestRemoteS3Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.common.collect.ImmutableMap; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; | ||
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; | ||
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; | ||
|
||
public class TestRemoteS3Config | ||
{ | ||
@Test | ||
public void testDefaults() | ||
{ | ||
assertRecordedDefaults(recordDefaults(RemoteS3Config.class) | ||
.setDomain("amazonaws.com").setHttps(true).setPort(null) | ||
.setVirtualHostStyle(true) | ||
.setHostnameTemplate("${bucket}.s3.${region}.${domain}")); | ||
} | ||
|
||
@Test | ||
public void testExplicitPropertyMappings() | ||
{ | ||
Map<String, String> properties = ImmutableMap.of( | ||
"remoteS3.https", "false", | ||
"remoteS3.domain", "testS3Domain.com", | ||
"remoteS3.port", "80", | ||
"remoteS3.virtual-host-style", "false", | ||
"remoteS3.hostname.template", "s3.${region}.${domain}"); | ||
|
||
RemoteS3Config expected = new RemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80).setVirtualHostStyle(false) | ||
.setHostnameTemplate("s3.${region}.${domain}"); | ||
assertFullMapping(properties, expected); | ||
} | ||
} |
Oops, something went wrong.