Skip to content

Commit a45705b

Browse files
Add path-style-access-enabled config to S3 CRT client (#872)
Co-authored-by: Maciej Walkowiak <[email protected]>
1 parent 1d2edf4 commit a45705b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfiguration.java

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ S3AsyncClient s3AsyncClient(AwsCredentialsProvider credentialsProvider) {
6767
Optional.ofNullable(this.awsProperties.getEndpoint()).ifPresent(builder::endpointOverride);
6868
Optional.ofNullable(this.properties.getEndpoint()).ifPresent(builder::endpointOverride);
6969
Optional.ofNullable(this.properties.getCrossRegionEnabled()).ifPresent(builder::crossRegionAccessEnabled);
70+
Optional.ofNullable(this.properties.getPathStyleAccessEnabled()).ifPresent(builder::forcePathStyle);
7071

7172
if (this.properties.getCrt() != null) {
7273
S3CrtClientProperties crt = this.properties.getCrt();

spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfigurationTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@
2828
import org.springframework.boot.test.context.FilteredClassLoader;
2929
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3030
import org.springframework.test.util.ReflectionTestUtils;
31+
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
32+
import software.amazon.awssdk.core.client.config.SdkClientOption;
3133
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
3234
import software.amazon.awssdk.services.s3.S3AsyncClient;
35+
import software.amazon.awssdk.services.s3.endpoints.S3ClientContextParams;
3336
import software.amazon.awssdk.services.s3.internal.crt.S3NativeClientConfiguration;
37+
import software.amazon.awssdk.utils.AttributeMap;
3438

3539
/**
3640
* Tests for {@link S3CrtAsyncClientAutoConfiguration}.
@@ -78,6 +82,17 @@ void withCustomGlobalEndpointAndS3Endpoint() {
7882
}
7983
}
8084

85+
@Test
86+
void withPathStyleAccessEnabled() {
87+
contextRunner.withPropertyValues("spring.cloud.aws.s3.path-style-access-enabled:true").run(context -> {
88+
S3AsyncClient client = context.getBean(S3AsyncClient.class);
89+
S3AsyncClient delegate = (S3AsyncClient) ReflectionTestUtils.getField(client, "delegate");
90+
SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(delegate, "clientConfiguration");
91+
AttributeMap contextParams = clientConfiguration.option(SdkClientOption.CLIENT_CONTEXT_PARAMS);
92+
assertThat(contextParams.get(S3ClientContextParams.FORCE_PATH_STYLE)).isTrue();
93+
});
94+
}
95+
8196
@Test
8297
void setsPropertiesOnClient() {
8398
contextRunner.withPropertyValues("spring.cloud.aws.s3.crt.minimum-part-size-in-bytes=50",

0 commit comments

Comments
 (0)