Skip to content

Commit

Permalink
Added Region Support which fixes JENKINS-18839
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbeer committed Aug 8, 2013
1 parent 0e172b7 commit 4dfe576
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/java/hudson/plugins/s3/Entry.java
@@ -1,5 +1,7 @@
package hudson.plugins.s3;

import com.amazonaws.regions.Regions;

public final class Entry {
/**
* Destination bucket for the copy. Can contain macros.
Expand All @@ -18,4 +20,12 @@ public final class Entry {
* what x-amz-storage-class is currently set
*/
public String storageClass;
/**
* Regions Values
*/
public static final Regions[] regions = Regions.values();
/**
* Stores the Region Value
*/
public String selectedRegion;
}
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/s3/S3BucketPublisher.java
Expand Up @@ -131,6 +131,7 @@ public boolean perform(AbstractBuild<?, ?> build,
}
String bucket = Util.replaceMacro(entry.bucket, envVars);
String storageClass = Util.replaceMacro(entry.storageClass, envVars);
String selRegion = entry.selectedRegion;
List<MetadataPair> escapedUserMetadata = new ArrayList<MetadataPair>();
for (MetadataPair metadataPair : userMetadata) {
MetadataPair escapedMetadataPair = new MetadataPair();
Expand All @@ -139,8 +140,8 @@ public boolean perform(AbstractBuild<?, ?> build,
escapedUserMetadata.add(escapedMetadataPair);
}
for (FilePath src : paths) {
log(listener.getLogger(), "bucket=" + bucket + ", file=" + src.getName());
profile.upload(bucket, src, escapedUserMetadata, storageClass);
log(listener.getLogger(), "bucket=" + bucket + ", file=" + src.getName() + " region = " + selRegion);
profile.upload(bucket, src, escapedUserMetadata, storageClass, selRegion);
}
}
} catch (IOException e) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/hudson/plugins/s3/S3Profile.java
Expand Up @@ -8,6 +8,9 @@
import org.kohsuke.stapler.DataBoundConstructor;

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.RegionUtils;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.internal.Mimetypes;
Expand Down Expand Up @@ -63,7 +66,7 @@ public void check() throws Exception {



public void upload(String bucketName, FilePath filePath, List<MetadataPair> userMetadata, String storageClass) throws IOException, InterruptedException {
public void upload(String bucketName, FilePath filePath, List<MetadataPair> userMetadata, String storageClass, String selregion) throws IOException, InterruptedException {
if (filePath.isDirectory()) {
throw new IOException(filePath + " is a directory");
}
Expand All @@ -80,6 +83,8 @@ public void upload(String bucketName, FilePath filePath, List<MetadataPair> user
metadata.addUserMetadata(metadataPair.key, metadataPair.value);
}
try {
Region region = RegionUtils.getRegion(Regions.valueOf(selregion).getName());
getClient().setRegion(region);
getClient().putObject(dest.bucketName, dest.objectName, filePath.read(), metadata);
} catch (Exception e) {
throw new IOException("put " + dest + ": " + e);
Expand Down
Expand Up @@ -27,6 +27,13 @@
</j:forEach>
</select>
</f:entry>
<f:entry title="Bucket Region" help="${helpURL}/help-region.html">
<select class="setting-input" name="s3.entry.selectedRegion">
<j:forEach var="regionOpt" items="${e.regions}">
<f:option selected="${regionOpt==e.selectedRegion}">${regionOpt}</f:option>
</j:forEach>
</select>
</f:entry>
<f:entry title="">
<div align="right">
<f:repeatableDeleteButton />
Expand Down

0 comments on commit 4dfe576

Please sign in to comment.