Search in sources :

Example 1 with ConfiguredS3SdkHttpRequest

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);
}
Also used : ConfiguredS3SdkHttpRequest(software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest) URI(java.net.URI) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest)

Example 2 with ConfiguredS3SdkHttpRequest

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();
}
Also used : SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) ConfiguredS3SdkHttpRequest(software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest) URI(java.net.URI)

Example 3 with ConfiguredS3SdkHttpRequest

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();
}
Also used : ConfiguredS3SdkHttpRequest(software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) S3AccessPointResource(software.amazon.awssdk.services.s3.internal.resource.S3AccessPointResource) S3Resource(software.amazon.awssdk.services.s3.internal.resource.S3Resource) PartitionMetadata(software.amazon.awssdk.regions.PartitionMetadata) Region(software.amazon.awssdk.regions.Region) S3EndpointUtils.isFipsRegion(software.amazon.awssdk.services.s3.internal.endpoints.S3EndpointUtils.isFipsRegion) URI(java.net.URI)

Example 4 with ConfiguredS3SdkHttpRequest

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();
}
Also used : S3Configuration(software.amazon.awssdk.services.s3.S3Configuration) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) ConfiguredS3SdkHttpRequest(software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest) S3Request(software.amazon.awssdk.services.s3.model.S3Request)

Example 5 with ConfiguredS3SdkHttpRequest

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();
}
Also used : S3Configuration(software.amazon.awssdk.services.s3.S3Configuration) ConfiguredS3SdkHttpRequest(software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest) S3EndpointResolverContext(software.amazon.awssdk.services.s3.internal.endpoints.S3EndpointResolverContext) S3EndpointResolverFactoryContext(software.amazon.awssdk.services.s3.internal.endpoints.S3EndpointResolverFactoryContext) S3Request(software.amazon.awssdk.services.s3.model.S3Request) URI(java.net.URI)

Aggregations

ConfiguredS3SdkHttpRequest (software.amazon.awssdk.services.s3.internal.ConfiguredS3SdkHttpRequest)9 URI (java.net.URI)7 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)5 S3Configuration (software.amazon.awssdk.services.s3.S3Configuration)2 S3Request (software.amazon.awssdk.services.s3.model.S3Request)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1 PartitionMetadata (software.amazon.awssdk.regions.PartitionMetadata)1 Region (software.amazon.awssdk.regions.Region)1 S3EndpointResolverContext (software.amazon.awssdk.services.s3.internal.endpoints.S3EndpointResolverContext)1 S3EndpointResolverFactoryContext (software.amazon.awssdk.services.s3.internal.endpoints.S3EndpointResolverFactoryContext)1 S3EndpointUtils.isFipsRegion (software.amazon.awssdk.services.s3.internal.endpoints.S3EndpointUtils.isFipsRegion)1 S3AccessPointResource (software.amazon.awssdk.services.s3.internal.resource.S3AccessPointResource)1 S3Resource (software.amazon.awssdk.services.s3.internal.resource.S3Resource)1 PutObjectRequest (software.amazon.awssdk.services.s3.model.PutObjectRequest)1 WriteGetObjectResponseRequest (software.amazon.awssdk.services.s3.model.WriteGetObjectResponseRequest)1