Skip to content

Commit

Permalink
[JENKINS-51402] Presigned url has the wrong region (#29)
Browse files Browse the repository at this point in the history
Presigned url has the wrong region when running from a different one
  • Loading branch information
kuisathaverat authored and carlossg committed May 24, 2018
1 parent 3e8b770 commit 333330c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -128,3 +128,9 @@ docker run --rm -i --init -v <YOUR_HOME_DIR>/.aws:/home/jenkins/.aws -e AWS_REGI
```

but note that the mount will not work if your `~/.aws/` is set to be readable only by the user.


# Force the Region

If you have problems detecting the region on your environment you can force the region setting by adding this property
`-Dio.jenkins.plugins.artifact_manager_s3.S3BlobStore.region=REGION_NAME` to the Jenkins JVM options.
Expand Up @@ -34,18 +34,23 @@
import java.net.URLEncoder;
import java.util.Date;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;
import javax.ws.rs.HEAD;

import io.jenkins.plugins.artifact_manager_jclouds.JCloudsArtifactManager;
import org.apache.commons.lang.StringUtils;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.aws.s3.AWSS3ProviderMetadata;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.domain.Credentials;
import org.jclouds.location.reference.LocationConstants;
import org.jclouds.osgi.ProviderRegistry;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -75,6 +80,8 @@ public class S3BlobStore extends BlobStoreProvider {
private static String BLOB_CONTAINER = System.getenv("S3_BUCKET");
@SuppressWarnings("FieldMayBeFinal")
private static String PREFIX = System.getenv("S3_DIR");
@SuppressWarnings("FieldMayBeFinal")
private static String REGION = System.getProperty(S3BlobStore.class.getName() + ".region");

@DataBoundConstructor
public S3BlobStore() {}
Expand All @@ -94,6 +101,12 @@ public BlobStoreContext getContext() throws IOException {
LOGGER.log(Level.FINEST, "Building context");
ProviderRegistry.registerProvider(AWSS3ProviderMetadata.builder().build());
try {
Properties props = new Properties();

if(StringUtils.isNotBlank(REGION)) {
props.setProperty(LocationConstants.PROPERTY_REGIONS, REGION);
}

return ContextBuilder.newBuilder("aws-s3").credentialsSupplier(getCredentialsSupplier())
.buildView(BlobStoreContext.class);
} catch (NoSuchElementException x) {
Expand Down

0 comments on commit 333330c

Please sign in to comment.