-
Notifications
You must be signed in to change notification settings - Fork 214
public_acl patch
brettcave edited this page Sep 13, 2010
·
6 revisions
The following patch will add a checkbox to the job configuration screen allowing uploaded resources to have public read access granted (on a per-entry basis).
brett
Index: main/java/com/hyperic/hudson/plugin/Entry.java =================================================================== --- main/java/com/hyperic/hudson/plugin/Entry.java (revision 132) +++ main/java/com/hyperic/hudson/plugin/Entry.java (revision 140) @@ -11,4 +11,9 @@ * <p> */ public String sourceFile; + + /** + * Should the sourceFile get public read access after being uploaded? + */ + public boolean publicObject; } Index: main/java/com/hyperic/hudson/plugin/S3BucketPublisher.java =================================================================== --- main/java/com/hyperic/hudson/plugin/S3BucketPublisher.java (revision 132) +++ main/java/com/hyperic/hudson/plugin/S3BucketPublisher.java (revision 140) @@ -94,6 +94,7 @@ String expanded = Util.replaceMacro(entry.sourceFile, envVars); FilePath ws = build.getProject().getWorkspace(); FilePath[] paths = ws.list(expanded); + boolean isPub = entry.publicObject;
if (paths.length == 0) { // try to do error diagnostics @@ -104,8 +105,13 @@ } String bucket = Util.replaceMacro(entry.bucket, envVars); for (FilePath src : paths) { - log(listener.getLogger(), "bucket=" + bucket + ", file=" + src.getName()); - profile.upload(bucket, src, envVars, listener.getLogger()); + String perms; + if (isPub) + perms = "public"; + else + perms = "default (private)"; + log(listener.getLogger(), "bucket=" + bucket + ", file=" + src.getName() + ", acl=" + perms); + profile.upload(bucket, src, isPub, envVars, listener.getLogger()); } } } catch (IOException e) { Index: main/java/com/hyperic/hudson/plugin/S3Profile.java =================================================================== --- main/java/com/hyperic/hudson/plugin/S3Profile.java (revision 132) +++ main/java/com/hyperic/hudson/plugin/S3Profile.java (revision 140) @@ -12,6 +12,7 @@ import org.apache.commons.lang.StringUtils; import org.jets3t.service.S3Service; import org.jets3t.service.S3ServiceException; +import org.jets3t.service.acl.AccessControlList; import org.jets3t.service.impl.rest.httpclient.RestS3Service; import org.jets3t.service.model.S3Bucket; import org.jets3t.service.model.S3Object; @@ -92,6 +93,7 @@
public void upload(String bucketName, FilePath filePath, + boolean isPub, Map<String, String> envVars, PrintStream logger) throws IOException, InterruptedException { @@ -109,9 +111,11 @@ }
try { - S3Object fileObject = - new S3Object(bucket, file.getName()); - fileObject.setDataInputStream(filePath.read()); + S3Object fileObject = + new S3Object(bucket, file.getName()); + fileObject.setDataInputStream(filePath.read()); + if (isPub) + fileObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ); this.s3.putObject(bucket, fileObject); } catch (Exception e) { throw new IOException("put " + file + ": " + e);
Index: main/resources/com/hyperic/hudson/plugin/S3BucketPublisher/config.jelly =================================================================== --- main/resources/com/hyperic/hudson/plugin/S3BucketPublisher/config.jelly (revision 132) +++ main/resources/com/hyperic/hudson/plugin/S3BucketPublisher/config.jelly (revision 140) @@ -17,6 +17,9 @@ <input class="setting-input" name="s3.entry.sourceFile" type="text" value="${e.sourceFile}" /> </f:entry> + <f:entry title="Set uploaded files public" help="${helpURL}/help-acl.html"> + <f:checkbox name="s3.entry.publicObject" checked="${e.publicObject}" /> + </f:entry> <f:entry title="Destination bucket" help="${helpURL}/help-destination.html"> <input class="setting-input" name="s3.entry.bucket" type="text" value="${e.bucket}" /> Index: main/webapp/help-acl.html =================================================================== --- main/webapp/help-acl.html (revision 0) +++ main/webapp/help-acl.html (revision 140) @@ -0,0 +1,2 @@ +<div>Enabling this option will grant public read access on uploaded files (REST_CANNED_PUBLIC_READ).<br/> +</div>