Skip to content

Commit

Permalink
Remote S3 configs
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavr12 committed Jul 22, 2024
1 parent b764af8 commit 56d4fdf
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 31 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
*/
package io.trino.aws.proxy.server.remote;

import com.google.inject.Inject;
import jakarta.ws.rs.core.UriBuilder;

import java.net.URI;
import java.util.Optional;

import static io.trino.aws.proxy.server.remote.AwsRemoteS3FacadeConstants.PATH_BUILDER;
import static java.util.Objects.requireNonNull;

public class PathStyleRemoteS3Facade
Expand All @@ -28,9 +28,10 @@ public class PathStyleRemoteS3Facade
private final boolean https;
private final Optional<Integer> port;

public PathStyleRemoteS3Facade()
@Inject
public PathStyleRemoteS3Facade(RemoteS3Config remoteS3Config)
{
this(PATH_BUILDER, true, Optional.empty());
this((ignored, region) -> "s3.%s.%s".formatted(region, remoteS3Config.getDomain()), remoteS3Config.getHttps(), remoteS3Config.getPort());
}

public PathStyleRemoteS3Facade(RemoteS3HostBuilder hostBuilder, boolean https, Optional<Integer> port)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.NotNull;

import java.util.Optional;

public class RemoteS3Config
{
private boolean https = true;
private String domain = "amazonaws.com";
private Optional<Integer> port = Optional.empty();

@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;
}

@NotNull
public Boolean getHttps()
{
return https;
}

@NotNull
public String getDomain()
{
return domain;
}

@NotNull
public Optional<Integer> getPort()
{
return port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
*/
package io.trino.aws.proxy.server.remote;

import com.google.inject.Inject;
import jakarta.ws.rs.core.UriBuilder;

import java.net.URI;
import java.util.Optional;

import static io.trino.aws.proxy.server.remote.AwsRemoteS3FacadeConstants.VIRTUAL_HOST_BUILDER;
import static java.util.Objects.requireNonNull;

public class VirtualHostStyleRemoteS3Facade
Expand All @@ -28,9 +28,11 @@ public class VirtualHostStyleRemoteS3Facade
private final boolean https;
private final Optional<Integer> port;

public VirtualHostStyleRemoteS3Facade()
@Inject
public VirtualHostStyleRemoteS3Facade(RemoteS3Config remoteS3Config)
{
this(VIRTUAL_HOST_BUILDER, true, Optional.empty());
this((bucket, region) ->
(bucket.isEmpty() ? "" : "%s.".formatted(bucket)) + "s3.%s.%s".formatted(region, remoteS3Config.getDomain()), remoteS3Config.getHttps(), remoteS3Config.getPort());
}

public VirtualHostStyleRemoteS3Facade(RemoteS3HostBuilder hostBuilder, boolean https, Optional<Integer> port)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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));
}

@Test
public void testExplicitPropertyMappings()
{
Map<String, String> properties = ImmutableMap.of(
"remoteS3.https", "false",
"remoteS3.domain", "testS3Domain.com",
"remoteS3.port", "80");

RemoteS3Config expected = new RemoteS3Config().setHttps(false).setDomain("testS3Domain.com").setPort(80);
assertFullMapping(properties, expected);
}
}

0 comments on commit 56d4fdf

Please sign in to comment.