use of software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest in project aws-sdk-java-v2 by aws.
the class S3AccessPointEndpointResolverTest method verifyAccesspointArn.
private void verifyAccesspointArn(String protocol, String accessPointArn, String expectedEndpoint, Region expectedSigningRegion, S3Configuration.Builder configBuilder, Region region) {
String key = "test-key";
URI customUri = URI.create(String.format("%s://s3-test.com/%s/%s", protocol, urlEncode(accessPointArn), key));
URI expectedUri = URI.create(String.format("%s/%s", expectedEndpoint, key));
PutObjectRequest putObjectRequest = PutObjectRequest.builder().bucket(accessPointArn).key(key).build();
S3EndpointResolverContext context = S3EndpointResolverContext.builder().request(InterceptorTestUtils.sdkHttpRequest(customUri)).originalRequest(putObjectRequest).region(region).serviceConfiguration(configBuilder.build()).build();
ConfiguredS3SdkHttpRequest s3SdkHttpRequest = endpointResolver.applyEndpointConfiguration(context);
assertThat(s3SdkHttpRequest.sdkHttpRequest().getUri()).isEqualTo(expectedUri);
assertSigningRegion(s3SdkHttpRequest, expectedSigningRegion);
assertSigningService(accessPointArn, s3SdkHttpRequest);
}
use of software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest in project aws-sdk-java-v2 by aws.
the class S3BucketEndpointResolver method applyEndpointConfiguration.
@Override
public ConfiguredS3SdkHttpRequest applyEndpointConfiguration(S3EndpointResolverContext context) {
URI endpoint = resolveEndpoint(context);
SdkHttpRequest.Builder mutableRequest = context.request().toBuilder();
mutableRequest.uri(endpoint);
String bucketName = context.originalRequest().getValueForField("Bucket", String.class).orElse(null);
if (canUseVirtualAddressing(context.serviceConfiguration(), bucketName)) {
changeToDnsEndpoint(mutableRequest, bucketName);
}
return ConfiguredS3SdkHttpRequest.builder().sdkHttpRequest(mutableRequest.build()).build();
}
use of software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest in project aws-sdk-java-v2 by aws.
the class S3AccessPointEndpointResolver method applyEndpointConfiguration.
@Override
public ConfiguredS3SdkHttpRequest applyEndpointConfiguration(S3EndpointResolverContext context) {
S3Resource s3Resource = S3ArnConverter.create().convertArn(Arn.fromString(getBucketName(context)));
S3AccessPointResource s3EndpointResource = Validate.isInstanceOf(S3AccessPointResource.class, s3Resource, "An ARN was passed as a bucket parameter to an S3 operation, however it does not " + "appear to be a valid S3 access point ARN.");
PartitionMetadata clientPartitionMetadata = PartitionMetadata.of(context.region());
validateConfiguration(context, s3EndpointResource);
URI accessPointUri = getUriForAccessPointResource(context, clientPartitionMetadata, s3EndpointResource);
String path = buildPath(accessPointUri, context);
SdkHttpRequest httpRequest = context.request().toBuilder().protocol(accessPointUri.getScheme()).host(accessPointUri.getHost()).port(accessPointUri.getPort()).encodedPath(path).build();
Region signingRegionModification = s3EndpointResource.region().map(Region::of).orElse(null);
String signingServiceModification = s3EndpointResource.parentS3Resource().flatMap(S3AccessPointEndpointResolver::resolveSigningService).orElse(null);
return ConfiguredS3SdkHttpRequest.builder().sdkHttpRequest(httpRequest).signingRegionModification(signingRegionModification).signingServiceModification(signingServiceModification).build();
}
use of software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest in project aws-sdk-java-v2 by aws.
the class S3ObjectLambdaOperationEndpointResolver method applyEndpointConfiguration.
@Override
public ConfiguredS3SdkHttpRequest applyEndpointConfiguration(S3EndpointResolverContext context) {
S3Request originalRequest = (S3Request) context.originalRequest();
validateObjectLambdaRequest(originalRequest);
S3Configuration configuration = context.serviceConfiguration();
validateConfiguration(configuration);
SdkHttpRequest updatedRequest = context.request();
if (context.endpointOverride() == null) {
String newHost = getUriForObjectLambdaOperation(context).getHost();
if (!context.isDisableHostPrefixInjection()) {
newHost = applyHostPrefix(newHost, originalRequest);
}
updatedRequest = updatedRequest.toBuilder().host(newHost).build();
}
return ConfiguredS3SdkHttpRequest.builder().sdkHttpRequest(updatedRequest).signingServiceModification(SIGNING_NAME).build();
}
use of software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest in project aws-sdk-java-v2 by aws.
the class EndpointAddressInterceptor method modifyHttpRequest.
@Override
public SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) {
boolean endpointOverridden = Boolean.TRUE.equals(executionAttributes.getAttribute(SdkExecutionAttribute.ENDPOINT_OVERRIDDEN));
URI endpointOverride = endpointOverridden ? executionAttributes.getAttribute(SdkExecutionAttribute.CLIENT_ENDPOINT) : null;
S3Configuration serviceConfiguration = (S3Configuration) executionAttributes.getAttribute(AwsSignerExecutionAttribute.SERVICE_CONFIG);
boolean disableHostPrefixInjection = isDisableHostPrefixInjection(executionAttributes);
S3EndpointResolverContext resolverContext = S3EndpointResolverContext.builder().request(context.httpRequest()).originalRequest(context.request()).region(executionAttributes.getAttribute(AwsExecutionAttribute.AWS_REGION)).endpointOverride(endpointOverride).serviceConfiguration(serviceConfiguration).fipsEnabled(executionAttributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED)).disableHostPrefixInjection(disableHostPrefixInjection).build();
String bucketName = context.request().getValueForField("Bucket", String.class).orElse(null);
S3EndpointResolverFactoryContext resolverFactoryContext = S3EndpointResolverFactoryContext.builder().bucketName(bucketName).originalRequest((S3Request) context.request()).build();
ConfiguredS3SdkHttpRequest configuredRequest = S3EndpointResolverFactory.getEndpointResolver(resolverFactoryContext).applyEndpointConfiguration(resolverContext);
if (configuredRequest.signingRegionModification().isPresent()) {
executionAttributes.putAttribute(AwsSignerExecutionAttribute.SIGNING_REGION, configuredRequest.signingRegionModification().get());
} else {
executionAttributes.putAttribute(AwsSignerExecutionAttribute.SIGNING_REGION_SCOPE, RegionScope.GLOBAL);
}
configuredRequest.signingServiceModification().ifPresent(name -> executionAttributes.putAttribute(AwsSignerExecutionAttribute.SERVICE_SIGNING_NAME, name));
return configuredRequest.sdkHttpRequest();
}
Aggregations