Skip to content

Commit dcfce5a

Browse files
Fix setting endpoint from connection details to S3Presigner. (#1390)
`S3Presigner` auto-configuration did not take into account the endpoint override from `ConnectionDetails`.
1 parent 8eed682 commit dcfce5a

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ S3Presigner s3Presigner(S3Properties properties, AwsProperties awsProperties,
116116
else if (awsProperties.getEndpoint() != null) {
117117
builder.endpointOverride(awsProperties.getEndpoint());
118118
}
119+
connectionDetails.ifAvailable(it -> {
120+
if (it.getEndpoint() != null) {
121+
builder.endpointOverride(it.getEndpoint());
122+
}
123+
});
119124
Optional.ofNullable(awsProperties.getFipsEnabled()).ifPresent(builder::fipsEnabled);
120125
Optional.ofNullable(awsProperties.getDualstackEnabled()).ifPresent(builder::dualstackEnabled);
121126
return builder.build();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ S3AsyncClient s3AsyncClient(AwsCredentialsProvider credentialsProvider,
6969
S3CrtAsyncClientBuilder builder = S3AsyncClient.crtBuilder().credentialsProvider(credentialsProvider).region(
7070
this.awsClientBuilderConfigurer.resolveRegion(this.properties, connectionDetails.getIfAvailable()));
7171
Optional.ofNullable(connectionDetails.getIfAvailable()).map(AwsConnectionDetails::getEndpoint)
72-
.ifPresent(builder::endpointOverride);
72+
.ifPresent(builder::endpointOverride);
7373
Optional.ofNullable(this.awsProperties.getEndpoint()).ifPresent(builder::endpointOverride);
7474
Optional.ofNullable(this.properties.getEndpoint()).ifPresent(builder::endpointOverride);
7575
Optional.ofNullable(this.properties.getCrossRegionEnabled()).ifPresent(builder::crossRegionAccessEnabled);

spring-cloud-aws-testcontainers/src/test/java/io/awspring/cloud/testcontainers/AwsContainerConnectionDetailsFactoryTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import io.awspring.cloud.autoconfigure.ses.SesAutoConfiguration;
3030
import io.awspring.cloud.autoconfigure.sns.SnsAutoConfiguration;
3131
import io.awspring.cloud.autoconfigure.sqs.SqsAutoConfiguration;
32+
import io.awspring.cloud.s3.S3Template;
33+
import java.net.URL;
34+
import java.time.Duration;
3235
import org.junit.jupiter.api.Test;
3336
import org.springframework.beans.factory.annotation.Autowired;
3437
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -90,6 +93,13 @@ void configuresS3ClientWithServiceConnection(@Autowired S3Client client) {
9093
assertThatCode(client::listBuckets).doesNotThrowAnyException();
9194
}
9295

96+
@Test
97+
void configuresS3PresignedWithServiceConnection(@Autowired S3Template s3Template) {
98+
URL signedGetURL = s3Template.createSignedGetURL("foo", "bar", Duration.ofMinutes(1));
99+
assertThat(signedGetURL.getHost()).isNotNull().isNotEqualTo("foo.s3.amazonaws.com")
100+
.as("Signed URL does not point to AWS as the endpoint has been overwritten by @ServiceConnection");
101+
}
102+
93103
@Test
94104
void configuresS3AsyncClientWithServiceConnection(@Autowired S3AsyncClient client) {
95105
assertThatCode(client.listBuckets()::join).doesNotThrowAnyException();

0 commit comments

Comments
 (0)