Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
vagaerg committed Jun 4, 2024
1 parent 476cdf3 commit 5989fa2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static S3Client buildInternalClient(Credentials credentials, TestingHttp
{
AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(credentials.emulated().accessKey(), credentials.emulated().secretKey());

return clientBuilder(httpServer)
return clientBuilder(httpServer.getBaseUrl())
.credentialsProvider(() -> awsBasicCredentials)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testStsSession()
EmulatedAssumedRole emulatedAssumedRole = credentialsController.assumeEmulatedRole(testingCredentials.emulated(), "us-east-1", ARN, Optional.empty(), Optional.empty(), Optional.empty())
.orElseThrow(() -> new RuntimeException("Failed to assume role"));

try (S3Client client = clientBuilder(httpServer)
try (S3Client client = clientBuilder(httpServer.getBaseUrl())
.credentialsProvider(() -> AwsSessionCredentials.create(emulatedAssumedRole.credential().accessKey(), emulatedAssumedRole.credential().secretKey(), emulatedAssumedRole.session()))
.build()) {
// valid assumed role session - should work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.airlift.http.server.testing.TestingHttpServer;
import io.trino.s3.proxy.server.credentials.Credential;
import io.trino.s3.proxy.server.credentials.Credentials;
import io.trino.s3.proxy.server.rest.TrinoS3ProxyResource;
import io.trino.s3.proxy.server.testing.TestingUtil.ForTesting;
import jakarta.ws.rs.core.UriBuilder;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
Expand All @@ -41,7 +42,6 @@ public class TestingS3ClientProvider
{
private final URI proxyUri;
private final Credential testingCredentials;
private final TestingHttpServer httpServer;
private final boolean forcePathStyle;

@Retention(RUNTIME)
Expand All @@ -50,11 +50,9 @@ public class TestingS3ClientProvider
public @interface ForS3ClientProvider {}

@Inject
public TestingS3ClientProvider(TestingTrinoS3ProxyServer trinoS3ProxyServer, TestingHttpServer testingHttpServer, @ForTesting Credentials testingCredentials, @ForS3ClientProvider Optional<String> hostName)
public TestingS3ClientProvider(TestingHttpServer httpServer, @ForTesting Credentials testingCredentials, @ForS3ClientProvider Optional<String> hostName)
{
// TODO below
httpServer = testingHttpServer;
URI localProxyServerUri = trinoS3ProxyServer.getInjector().getInstance(TestingHttpServer.class).getBaseUrl();
URI localProxyServerUri = httpServer.getBaseUrl();
this.proxyUri = requireNonNull(hostName, "hostName is null")
.map(serverHostName -> UriBuilder.newInstance().host(serverHostName).port(localProxyServerUri.getPort()).scheme("http").path(TrinoS3ProxyResource.class).build())
.orElse(UriBuilder.fromUri(localProxyServerUri).path(TrinoS3ProxyResource.class).build());
Expand All @@ -67,7 +65,7 @@ public S3Client get()
{
AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(testingCredentials.accessKey(), testingCredentials.secretKey());

return clientBuilder(httpServer)
return clientBuilder(proxyUri)
.credentialsProvider(() -> awsBasicCredentials)
.forcePathStyle(forcePathStyle)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package io.trino.s3.proxy.server.testing;

import com.google.inject.BindingAnnotation;
import io.airlift.http.server.testing.TestingHttpServer;
import io.trino.s3.proxy.server.credentials.Credential;
import io.trino.s3.proxy.server.credentials.Credentials;
import io.trino.s3.proxy.server.rest.TrinoS3ProxyRestConstants;
Expand Down Expand Up @@ -46,9 +45,8 @@ public final class TestingUtil
@BindingAnnotation
public @interface ForTesting {}

public static S3ClientBuilder clientBuilder(TestingHttpServer httpServer)
public static S3ClientBuilder clientBuilder(URI baseUrl)
{
URI baseUrl = httpServer.getBaseUrl();
URI localProxyServerUri = baseUrl.resolve(TrinoS3ProxyRestConstants.S3_PATH);

return S3Client.builder()
Expand Down

0 comments on commit 5989fa2

Please sign in to comment.