Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@
String customEndpoint = getConfiguration().getResolvedCustomEndpoint();
S3Presigner.Builder presignerBuilder = S3Presigner.builder()
.fipsEnabled(FIPS140.useCompliantAlgorithms())
.region(getConfiguration().getRegion())
.credentialsProvider(CredentialsAwsGlobalConfiguration.get().getCredentials())
.s3Client(s3Client);
if (StringUtils.isNotBlank(customEndpoint)) {
Expand All @@ -225,7 +224,7 @@

String customRegion = getConfiguration().getCustomSigningRegion();
if(StringUtils.isBlank(customRegion)) {
customRegion = getConfiguration().getRegion().id();
customRegion = getRegion();

Check warning on line 227 in src/main/java/io/jenkins/plugins/artifact_manager_jclouds/s3/S3BlobStore.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 227 is not covered by tests
}
if(StringUtils.isNotBlank(customRegion)) {
presignerBuilder.region(Region.of(customRegion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@
}

public Region getRegion() {
// Short-circuit for custom endpoints (e.g., MinIO, LocalStack).
// AWS region auto-detection is expensive and irrelevant for non-AWS services.
if (StringUtils.isNotBlank(customEndpoint)) {

Check warning on line 331 in src/main/java/io/jenkins/plugins/artifact_manager_jclouds/s3/S3BlobStoreConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 331 is only partially covered, one branch is missing
if (StringUtils.isNotBlank(customSigningRegion)) {
return Region.of(customSigningRegion);
}
return Region.US_EAST_1;
}
String regionStr = CredentialsAwsGlobalConfiguration.get().getRegion();
if (regionStr == null) {
try {
Expand All @@ -352,7 +360,6 @@
throw new IOException("No session AWS credentials found");
}
}
builder = builder.region(getRegion());
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.logging.Logger;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
Expand All @@ -12,6 +13,8 @@
import hudson.util.FormValidation;
import jenkins.model.ArtifactManagerConfiguration;

import software.amazon.awssdk.regions.Region;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -128,6 +131,39 @@ public void checkValidationCustomSigningRegion() {
assertTrue(descriptor.doCheckCustomSigningRegion("").getMessage().contains("us-east-1"));
}

@Test
public void getRegionWithCustomEndpointAndSigningRegion() {
S3BlobStoreConfig config = S3BlobStoreConfig.get();
config.setCustomEndpoint("minio.example.com:9000");
config.setCustomSigningRegion("eu-west-1");
assertEquals(Region.of("eu-west-1"), config.getRegion());
}

@Test
public void getRegionWithCustomEndpointAndBlankSigningRegion() {
S3BlobStoreConfig config = S3BlobStoreConfig.get();
config.setCustomEndpoint("minio.example.com:9000");
config.setCustomSigningRegion("");
assertEquals(Region.US_EAST_1, config.getRegion());
}

@Test
public void getRegionWithCustomEndpointAndNullSigningRegion() {
S3BlobStoreConfig config = S3BlobStoreConfig.get();
config.setCustomEndpoint("minio.example.com:9000");
config.setCustomSigningRegion(null);
assertEquals(Region.US_EAST_1, config.getRegion());
}

@Test
@Ignore("because we rely on aws sdk autodetection of region, and for some people the auto detect can return somehting different")
public void getRegionWithoutCustomEndpoint() {
S3BlobStoreConfig config = S3BlobStoreConfig.get();
config.setCustomEndpoint("");
Region region = config.getRegion();
assertEquals(Region.US_EAST_1, region);
}

@Test
public void checkValidationUseHttpsWithFipsDisabled() {
S3BlobStoreConfig descriptor = S3BlobStoreConfig.get();
Expand Down
Loading