Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
import java.util.concurrent.CompletableFuture;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsExecutionAttribute;
import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider;
import software.amazon.awssdk.core.ClientEndpointProvider;
import software.amazon.awssdk.core.Protocol;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.SelectedAuthScheme;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.interceptor.Context;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
import software.amazon.awssdk.http.SdkHttpFullRequest;
import software.amazon.awssdk.http.SdkHttpMethod;
import software.amazon.awssdk.http.SdkHttpRequest;
Expand All @@ -48,6 +45,7 @@
import software.amazon.awssdk.identity.spi.Identity;
import software.amazon.awssdk.protocols.query.AwsQueryProtocolFactory;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.docdb.endpoints.DocDbEndpointProvider;
import software.amazon.awssdk.services.docdb.model.DocDbRequest;
import software.amazon.awssdk.utils.CompletableFutureUtils;

Expand All @@ -72,7 +70,6 @@ public abstract class RdsPresignInterceptor<T extends DocDbRequest> implements E
.build())
.build();

private static final String SERVICE_NAME = "rds";
private static final String PARAM_SOURCE_REGION = "SourceRegion";
private static final String PARAM_DESTINATION_REGION = "DestinationRegion";
private static final String PARAM_PRESIGNED_URL = "PreSignedUrl";
Expand Down Expand Up @@ -109,7 +106,7 @@ public final SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context,
SelectedAuthScheme<?> selectedAuthScheme = executionAttributes.getAttribute(SELECTED_AUTH_SCHEME);
String sourceRegion = presignableRequest.getSourceRegion();
String destinationRegion = selectedAuthScheme.authSchemeOption().signerProperty(AwsV4HttpSigner.REGION_NAME);
URI endpoint = createEndpoint(sourceRegion, SERVICE_NAME, executionAttributes);
URI endpoint = createEndpoint(sourceRegion, executionAttributes);
SdkHttpFullRequest.Builder marshalledRequest = presignableRequest.marshall().toBuilder().uri(endpoint);

SdkHttpFullRequest requestToPresign =
Expand Down Expand Up @@ -218,17 +215,14 @@ private SdkHttpFullRequest toSdkHttpFullRequest(SignedRequest signedRequest) {
.build();
}

private URI createEndpoint(String regionName, String serviceName, ExecutionAttributes attributes) {
return AwsClientEndpointProvider.builder()
.serviceEndpointPrefix(SERVICE_NAME)
.defaultProtocol(Protocol.HTTPS.toString())
.region(Region.of(regionName))
.profileFile(attributes.getAttribute(SdkExecutionAttribute.PROFILE_FILE_SUPPLIER))
.profileName(attributes.getAttribute(SdkExecutionAttribute.PROFILE_NAME))
.dualstackEnabled(
attributes.getAttribute(AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED))
.fipsEnabled(attributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED))
.build()
.clientEndpoint();
private URI createEndpoint(String regionName, ExecutionAttributes attributes) {
return CompletableFutureUtils.joinLikeSync(
DocDbEndpointProvider.defaultProvider()
.resolveEndpoint(p -> p.region(Region.of(regionName))
.useDualStack(attributes.getAttribute(
AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED))
.useFips(attributes.getAttribute(
AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED)))
).url();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
import java.util.concurrent.CompletableFuture;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsExecutionAttribute;
import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider;
import software.amazon.awssdk.core.ClientEndpointProvider;
import software.amazon.awssdk.core.Protocol;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.SelectedAuthScheme;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.interceptor.Context;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
import software.amazon.awssdk.http.SdkHttpFullRequest;
import software.amazon.awssdk.http.SdkHttpMethod;
import software.amazon.awssdk.http.SdkHttpRequest;
Expand All @@ -48,6 +45,7 @@
import software.amazon.awssdk.identity.spi.Identity;
import software.amazon.awssdk.protocols.query.AwsQueryProtocolFactory;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.neptune.endpoints.NeptuneEndpointProvider;
import software.amazon.awssdk.services.neptune.model.NeptuneRequest;
import software.amazon.awssdk.utils.CompletableFutureUtils;

Expand All @@ -73,7 +71,6 @@ public abstract class RdsPresignInterceptor<T extends NeptuneRequest> implements
.build())
.build();

private static final String SERVICE_NAME = "rds";
private static final String PARAM_SOURCE_REGION = "SourceRegion";
private static final String PARAM_DESTINATION_REGION = "DestinationRegion";
private static final String PARAM_PRESIGNED_URL = "PreSignedUrl";
Expand Down Expand Up @@ -110,7 +107,7 @@ public final SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context,
SelectedAuthScheme<?> selectedAuthScheme = executionAttributes.getAttribute(SELECTED_AUTH_SCHEME);
String sourceRegion = presignableRequest.getSourceRegion();
String destinationRegion = selectedAuthScheme.authSchemeOption().signerProperty(AwsV4HttpSigner.REGION_NAME);
URI endpoint = createEndpoint(sourceRegion, SERVICE_NAME, executionAttributes);
URI endpoint = createEndpoint(sourceRegion, executionAttributes);
SdkHttpFullRequest.Builder marshalledRequest = presignableRequest.marshall().toBuilder().uri(endpoint);

SdkHttpFullRequest requestToPresign =
Expand Down Expand Up @@ -219,17 +216,14 @@ private SdkHttpFullRequest toSdkHttpFullRequest(SignedRequest signedRequest) {
.build();
}

private URI createEndpoint(String regionName, String serviceName, ExecutionAttributes attributes) {
return AwsClientEndpointProvider.builder()
.serviceEndpointPrefix(SERVICE_NAME)
.defaultProtocol(Protocol.HTTPS.toString())
.region(Region.of(regionName))
.profileFile(attributes.getAttribute(SdkExecutionAttribute.PROFILE_FILE_SUPPLIER))
.profileName(attributes.getAttribute(SdkExecutionAttribute.PROFILE_NAME))
.dualstackEnabled(
attributes.getAttribute(AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED))
.fipsEnabled(attributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED))
.build()
.clientEndpoint();
private URI createEndpoint(String regionName, ExecutionAttributes attributes) {
return CompletableFutureUtils.joinLikeSync(
NeptuneEndpointProvider.defaultProvider()
.resolveEndpoint(p -> p.region(Region.of(regionName))
.useDualStack(attributes.getAttribute(
AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED))
.useFips(attributes.getAttribute(
AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED)))
).url();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
import java.util.concurrent.CompletableFuture;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsExecutionAttribute;
import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider;
import software.amazon.awssdk.core.ClientEndpointProvider;
import software.amazon.awssdk.core.Protocol;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.SelectedAuthScheme;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.interceptor.Context;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
import software.amazon.awssdk.http.SdkHttpFullRequest;
import software.amazon.awssdk.http.SdkHttpMethod;
import software.amazon.awssdk.http.SdkHttpRequest;
Expand All @@ -48,6 +45,7 @@
import software.amazon.awssdk.identity.spi.Identity;
import software.amazon.awssdk.protocols.query.AwsQueryProtocolFactory;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.rds.endpoints.RdsEndpointProvider;
import software.amazon.awssdk.services.rds.model.RdsRequest;
import software.amazon.awssdk.utils.CompletableFutureUtils;

Expand All @@ -72,7 +70,6 @@ public abstract class RdsPresignInterceptor<T extends RdsRequest> implements Exe
.build())
.build();

private static final String SERVICE_NAME = "rds";
private static final String PARAM_SOURCE_REGION = "SourceRegion";
private static final String PARAM_DESTINATION_REGION = "DestinationRegion";
private static final String PARAM_PRESIGNED_URL = "PreSignedUrl";
Expand Down Expand Up @@ -109,7 +106,7 @@ public final SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context,
SelectedAuthScheme<?> selectedAuthScheme = executionAttributes.getAttribute(SELECTED_AUTH_SCHEME);
String sourceRegion = presignableRequest.getSourceRegion();
String destinationRegion = selectedAuthScheme.authSchemeOption().signerProperty(AwsV4HttpSigner.REGION_NAME);
URI endpoint = createEndpoint(sourceRegion, SERVICE_NAME, executionAttributes);
URI endpoint = createEndpoint(sourceRegion, executionAttributes);
SdkHttpFullRequest.Builder marshalledRequest = presignableRequest.marshall().toBuilder().uri(endpoint);

SdkHttpFullRequest requestToPresign =
Expand Down Expand Up @@ -217,17 +214,14 @@ private SdkHttpFullRequest toSdkHttpFullRequest(SignedRequest signedRequest) {
.build();
}

private URI createEndpoint(String regionName, String serviceName, ExecutionAttributes attributes) {
return AwsClientEndpointProvider.builder()
.serviceEndpointPrefix(SERVICE_NAME)
.defaultProtocol(Protocol.HTTPS.toString())
.region(Region.of(regionName))
.profileFile(attributes.getAttribute(SdkExecutionAttribute.PROFILE_FILE_SUPPLIER))
.profileName(attributes.getAttribute(SdkExecutionAttribute.PROFILE_NAME))
.dualstackEnabled(
attributes.getAttribute(AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED))
.fipsEnabled(attributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED))
.build()
.clientEndpoint();
private URI createEndpoint(String regionName, ExecutionAttributes attributes) {
return CompletableFutureUtils.joinLikeSync(
RdsEndpointProvider.defaultProvider()
.resolveEndpoint(p -> p.region(Region.of(regionName))
.useDualStack(attributes.getAttribute(
AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED))
.useFips(attributes.getAttribute(
AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED)))
).url();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public void testExpectations(TestCase testCase) {
if (testCase.expectedUri != null) {
assertEquals(normalize(URI.create(testCase.expectedUri)), normalize(presignedUrlAsUri));
}
if (testCase.expectedPresignedUrlHost != null) {
assertEquals(testCase.expectedPresignedUrlHost, presignedUrlAsUri.getHost());
}
} else {
assertFalse(rawQueryParameters.containsKey("PreSignedUrl"));
}
Expand Down Expand Up @@ -169,6 +172,24 @@ public static List<TestCase> testCases() {
builder("StartDBInstanceAutomatedBackupsReplication Without SourceRegion Does NOT Send PresignedUrl")
.clientConsumer(c -> c.startDBInstanceAutomatedBackupsReplication(r -> r.kmsKeyId(TEST_KMS_KEY_ID)))
.shouldContainPreSignedUrl(false)
.build(),

builder("CopyDbClusterSnapshot - With FIPS enabled resolves to fips endpoint")
.clientConfigure(c -> c.region(Region.US_EAST_1).fipsEnabled(true))
.clientConsumer(c -> c.copyDBClusterSnapshot(makeTestRequestBuilder()
.sourceRegion("us-west-2")
.build()))
.shouldContainPreSignedUrl(true)
.expectedPresignedUrlHost("rds-fips.us-west-2.amazonaws.com")
.build(),

builder("CopyDbClusterSnapshot - With dualstack enabled resolves to dualstack endpoint")
.clientConfigure(c -> c.region(Region.US_EAST_1).dualstackEnabled(true))
.clientConsumer(c -> c.copyDBClusterSnapshot(makeTestRequestBuilder()
.sourceRegion("us-west-2")
.build()))
.shouldContainPreSignedUrl(true)
.expectedPresignedUrlHost("rds.us-west-2.api.aws")
.build()
);
}
Expand Down Expand Up @@ -296,6 +317,7 @@ static class TestCase {
private final String expectedDestinationRegion;
private final Clock signingClockOverride;
private final String expectedUri;
private final String expectedPresignedUrlHost;

TestCase(TestCaseBuilder builder) {
this.name = Validate.notNull(builder.name, "name");
Expand All @@ -305,6 +327,7 @@ static class TestCase {
this.expectedDestinationRegion = builder.expectedDestinationRegion;
this.signingClockOverride = builder.signingClockOverride;
this.expectedUri = builder.expectedUri;
this.expectedPresignedUrlHost = builder.expectedPresignedUrlHost;
}
}

Expand All @@ -316,6 +339,7 @@ static class TestCaseBuilder {
private String expectedDestinationRegion;
private Clock signingClockOverride;
private String expectedUri;
private String expectedPresignedUrlHost;

private TestCaseBuilder name(String name) {
this.name = name;
Expand Down Expand Up @@ -352,6 +376,11 @@ public TestCaseBuilder expectedUri(String expectedUri) {
return this;
}

public TestCaseBuilder expectedPresignedUrlHost(String expectedPresignedUrlHost) {
this.expectedPresignedUrlHost = expectedPresignedUrlHost;
return this;
}

public TestCase build() {
return new TestCase(this);
}
Expand Down
Loading