Skip to content

Commit

Permalink
Don't require environment to be set on the agents
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandell committed Oct 13, 2021
1 parent 928d444 commit 622dc58
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/main/java/hudson/plugins/s3/ClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public class ClientHelper {
com.amazonaws.services.s3.model.Region.US_Standard.toAWSRegion().getName());
public static final String ENDPOINT = System.getProperty("hudson.plugins.s3.ENDPOINT", System.getenv("PLUGIN_S3_ENDPOINT"));

public static AmazonS3 createClient(String accessKey, String secretKey, boolean useRole, String region, ProxyConfiguration proxy)
public static AmazonS3 createClient(String accessKey, String secretKey, boolean useRole, String region, ProxyConfiguration proxy) {
return createClient(accessKey, secretKey, useRole, region, proxy, ENDPOINT);
}

public static AmazonS3 createClient(String accessKey, String secretKey, boolean useRole, String region, ProxyConfiguration proxy, String customEndpoint)
{
Region awsRegion = getRegionFromString(region);

Expand All @@ -36,8 +40,8 @@ public static AmazonS3 createClient(String accessKey, String secretKey, boolean
builder = builder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
}

if (StringUtils.isNotEmpty(ENDPOINT)) {
builder = builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(ENDPOINT, awsRegion.getName()))
if (StringUtils.isNotEmpty(customEndpoint)) {
builder = builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(customEndpoint, awsRegion.getName()))
.withPathStyleAccessEnabled(true);
} else {
builder = builder.withRegion(awsRegion.getName());
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/hudson/plugins/s3/callable/S3Callable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import hudson.ProxyConfiguration;
import hudson.plugins.s3.ClientHelper;
import hudson.util.Secret;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.remoting.RoleChecker;

import java.io.ObjectStreamException;
import java.util.HashMap;

abstract class S3Callable<T> implements FileCallable<T> {
Expand All @@ -19,6 +21,7 @@ abstract class S3Callable<T> implements FileCallable<T> {
private final boolean useRole;
private final String region;
private final ProxyConfiguration proxy;
private final String customEndpoint;

private static transient HashMap<String, TransferManager> transferManagers = new HashMap<>();

Expand All @@ -28,12 +31,13 @@ abstract class S3Callable<T> implements FileCallable<T> {
this.useRole = useRole;
this.region = region;
this.proxy = proxy;
this.customEndpoint = ClientHelper.ENDPOINT;
}

protected synchronized TransferManager getTransferManager() {
final String uniqueKey = getUniqueKey();
if (transferManagers.get(uniqueKey) == null) {
final AmazonS3 client = ClientHelper.createClient(accessKey, Secret.toString(secretKey), useRole, region, proxy);
final AmazonS3 client = ClientHelper.createClient(accessKey, Secret.toString(secretKey), useRole, region, proxy, customEndpoint);
transferManagers.put(uniqueKey, TransferManagerBuilder.standard().withS3Client(client).build());
}

Expand Down
8 changes: 3 additions & 5 deletions src/test/java/hudson/plugins/s3/MinIOTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ public static void setUpClass() throws Exception {
minioServiceEndpoint = String.format("%s:%s", minioServer.getContainerIpAddress(), mappedPort);

final AmazonS3 client = AmazonS3ClientBuilder.standard()
//.withRegion("local")
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY)))
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://" + minioServiceEndpoint, "us-east-1"))
//.withForceGlobalBucketAccessEnabled(true)
.withPathStyleAccessEnabled(true)
.build();

Expand All @@ -124,7 +122,7 @@ public void testS3BucketPublisher() throws Throwable {
rr.then(r -> {
/*r.jenkins.setLabelString("work"); //Able to debug when running on the controller but not an agent
r.jenkins.setNumExecutors(1);*/
r.createOnlineSlave(Label.get("work"), new EnvVars("PLUGIN_S3_ENDPOINT", "http://" + endpoint));
r.createOnlineSlave(Label.get("work"));
createProfile();
createAndRunPublisher(r);
});
Expand Down Expand Up @@ -170,8 +168,8 @@ private static void createProfile() {
public void testS3CopyArtifact() throws Throwable {
final String endpoint = minioServiceEndpoint;
rr.then(r -> {
r.createOnlineSlave(Label.get("work"), new EnvVars("PLUGIN_S3_ENDPOINT", "http://" + endpoint));
r.createOnlineSlave(Label.get("copy"), new EnvVars("PLUGIN_S3_ENDPOINT", "http://" + endpoint));
r.createOnlineSlave(Label.get("work"));
r.createOnlineSlave(Label.get("copy"));

createProfile();
createAndRunPublisher(r);
Expand Down

0 comments on commit 622dc58

Please sign in to comment.