Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#353] leave region empty if none is provided #354

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/main/java/software/amazon/nio/spi/s3/S3ClientProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,14 @@ private S3AsyncClient configureClientForRegion(
S3AsyncClientBuilder builder
) {
var region = getRegionFromRegionName(regionName);
logger.debug("bucket region is: '{}'", region.id());
// no region provided => leave it to the provider chain to figure it out (e.g. env var AWS_REGION)
if (region != null) {
logger.debug("bucket region is: '{}'", region.id());
asyncClientBuilder.region(region);
}

builder
.forcePathStyle(configuration.getForcePathStyle())
.region(region)
.overrideConfiguration(
conf -> conf.retryPolicy(
configBuilder -> configBuilder.retryCondition(retryCondition).backoffStrategy(backoffStrategy)
Expand All @@ -279,7 +282,11 @@ private S3AsyncClient configureClientForRegion(

private S3AsyncClient configureCrtClientForRegion(String regionName) {
var region = getRegionFromRegionName(regionName);
logger.debug("bucket region is: '{}'", region.id());
// no region provided => leave it to the provider chain to figure it out (e.g. env var AWS_REGION)
if (region != null) {
logger.debug("bucket region is: '{}'", region.id());
asyncClientBuilder.region(region);
}

var endpointUri = configuration.endpointUri();
if (endpointUri != null) {
Expand All @@ -292,12 +299,11 @@ private S3AsyncClient configureCrtClientForRegion(String regionName) {
}

return asyncClientBuilder.forcePathStyle(configuration.getForcePathStyle())
.region(region)
.build();
}

private static Region getRegionFromRegionName(String regionName) {
return (regionName == null || regionName.isBlank()) ? Region.US_EAST_1 : Region.of(regionName);
return (regionName == null || regionName.isBlank()) ? null : Region.of(regionName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public void generateAsyncClientByEndpointBucketCredentials() {
provider.configuration.withEndpoint("endpoint1:1010");
provider.generateClient("bucket1", true);
then(BUILDER.endpointOverride.toString()).isEqualTo("https://endpoint1:1010");
then(BUILDER.region).isEqualTo(Region.US_EAST_1); // just a default in the case not provide
then(BUILDER.region).isNull(); // no default => leave it to the provider chain

provider.configuration.withEndpoint("endpoint2:2020");
provider.generateClient("bucket2", true);
then(BUILDER.endpointOverride.toString()).isEqualTo("https://endpoint2:2020");
then(BUILDER.region).isEqualTo(Region.US_EAST_1); // just a default in the case not provide
then(BUILDER.region).isNull(); // no default => leave it to the provider chain
}
}
Loading