Skip to content

Commit

Permalink
Fix configuring S3Presigner region (#937)
Browse files Browse the repository at this point in the history
The presigner now uses the region from properties if it is set.
  • Loading branch information
anappi-vc authored Nov 3, 2023
1 parent 0a176d0 commit e5c1010
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ S3Template s3Template(S3Client s3Client, S3OutputStreamProvider s3OutputStreamPr
S3Presigner s3Presigner(S3Properties properties, AwsProperties awsProperties,
AwsCredentialsProvider credentialsProvider, AwsRegionProvider regionProvider) {
S3Presigner.Builder builder = S3Presigner.builder().serviceConfiguration(properties.toS3Configuration())
.credentialsProvider(credentialsProvider).region(regionProvider.getRegion());
.credentialsProvider(credentialsProvider)
.region(AwsClientBuilderConfigurer.resolveRegion(properties, regionProvider));

if (properties.getEndpoint() != null) {
builder.endpointOverride(properties.getEndpoint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,22 @@ void setsCommonAwsPropertiesOnPresigner() {
assertThat(presigner.getRegion()).isEqualTo(Region.of("eu-west-1"));
});
}

@Test
void setsRegionFromProperties() {
contextRunner.withPropertyValues("spring.cloud.aws.s3.region:us-east-1").run(context -> {
ConfiguredAwsPresigner presigner = new ConfiguredAwsPresigner(context.getBean(S3Presigner.class));
assertThat(presigner.getRegion()).isEqualTo(Region.of("us-east-1"));
});
}

@Test
void setsRegionToDefault() {
contextRunner.run(context -> {
ConfiguredAwsPresigner presigner = new ConfiguredAwsPresigner(context.getBean(S3Presigner.class));
assertThat(presigner.getRegion()).isEqualTo(Region.of("eu-west-1"));
});
}
}

@Configuration(proxyBeanMethods = false)
Expand Down

0 comments on commit e5c1010

Please sign in to comment.