Permalink
Browse files

Adds option to allow public access

  • Loading branch information...
1 parent 7216f3f commit d92f2f4d269ba0d58ea658c35ac7976ce84dc48a @jamessanders committed Dec 31, 2012
@@ -22,6 +22,7 @@ public JSyncOptions(String[] args) {
accepts("delete", "delete files at destination that do not exists in the source dir");
accepts("reduced-redundancy", "use reduced redundancy when uploading files to S3");
accepts("rr-storage", "same as --reduced-redundancy");
+ accepts("public", "makes files public");
accepts("verbose", "be verbose");
accepts("help", "show this help");
accepts("backup", "backup any modified or deleted files" ).withRequiredArg().describedAs("path");
@@ -51,6 +52,10 @@ public boolean useReducedRedundancy() {
return (options.has("reduced-redundancy") || options.has("rr-storage"));
}
+ public boolean makePublic() {
+ return options.has("public");
+ }
+
public String getBackupPath() {
return (String) options.valueOf("backup");
}
@@ -50,7 +50,7 @@ public IResource generateResource(String path) {
if (scheme == null || scheme.equals("file")) {
return new FsResource(uri.getPath());
} else if (scheme.equals("s3")) {
- S3ResourceGenerator s3generator = new S3ResourceGenerator(options.getAwsCredentials(), path, options.useReducedRedundancy());
+ S3ResourceGenerator s3generator = new S3ResourceGenerator(options.getAwsCredentials(), path, options.useReducedRedundancy(), options.makePublic());
try {
return s3generator.getResource(path);
} catch (URISyntaxException e) {
@@ -5,6 +5,7 @@
import com.amazonaws.services.s3.model.*;
import org.apache.http.client.utils.URIBuilder;
+
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
@@ -29,6 +30,7 @@
S3ObjectSummary s3ObjectSummary;
ObjectMetadata s3MetaData;
boolean useReducedRedundancy;
+ boolean makePublic;
int offset;
public S3Resource(S3ObjectSummary s3ObjectSummary,
@@ -39,6 +41,7 @@ public S3Resource(S3ObjectSummary s3ObjectSummary,
S3ResourceGenerator s3ResourceGenerator,
AmazonS3Client client,
boolean useReducedRedundacy,
+ boolean makePublic,
int offset) {
try {
this.path = new URI(path);
@@ -53,6 +56,7 @@ public S3Resource(S3ObjectSummary s3ObjectSummary,
this.s3ResourceGenerator = s3ResourceGenerator;
this.s3MetaData = null;
this.useReducedRedundancy = useReducedRedundacy;
+ this.makePublic = makePublic;
this.offset = offset;
}
@@ -133,7 +137,7 @@ public IResource join(String name) {
false,
s3ResourceGenerator,
client,
- useReducedRedundancy, this.offset);
+ useReducedRedundancy, makePublic, this.offset);
} catch (URISyntaxException e) {
e.printStackTrace();
}
@@ -160,6 +164,9 @@ public void run(){
if (useReducedRedundancy) {
request.setStorageClass(StorageClass.ReducedRedundancy.toString());
}
+ if (makePublic) {
+ request = request.withCannedAcl(CannedAccessControlList.PublicRead);
+ }
client.putObject(request);
} catch (AmazonClientException e) {
e.printStackTrace();
@@ -20,8 +20,9 @@
URI uri;
int threadsOpen;
boolean useReducedRedundancy;
+ boolean makePublic;
- public S3ResourceGenerator(AWSCredentials creds, String base, boolean useReducedRedundancy) {
+ public S3ResourceGenerator(AWSCredentials creds, String base, boolean useReducedRedundancy, boolean makePublic) {
URI uri = null;
try {
uri = new URI(base);
@@ -32,7 +33,9 @@ public S3ResourceGenerator(AWSCredentials creds, String base, boolean useReduced
bucket = uri.getHost();
client = new AmazonS3Client(creds);
threadsOpen = 0;
+
this.useReducedRedundancy = useReducedRedundancy;
+ this.makePublic = makePublic;
}
public void incrementThreadCount() {
@@ -113,7 +116,7 @@ else if (!repl.contains("/") && !key.equals(uri.getPath()) && matches) {
builder.setScheme("s3");
builder.setHost(bucket);
builder.setPath(key);
- files.add(new S3Resource(object, bucket, builder.build().toString(), null, false, this, client, useReducedRedundancy, c));
+ files.add(new S3Resource(object, bucket, builder.build().toString(), null, false, this, client, useReducedRedundancy, makePublic, c));
} else if ((files.size() != 0 || subdirs.size() != 0) || theFile != null){
break;
}
@@ -173,9 +176,9 @@ else if (!repl.contains("/") && !key.equals(uri.getPath()) && matches) {
}
if (numberOfChildren > 0) {
- return new S3Resource(theFile, bucket, path, null, true, this, client, useReducedRedundancy, off);
+ return new S3Resource(theFile, bucket, path, null, true, this, client, useReducedRedundancy, makePublic, off);
} else {
- return new S3Resource(theFile, bucket, path, null, false, this, client, useReducedRedundancy, off);
+ return new S3Resource(theFile, bucket, path, null, false, this, client, useReducedRedundancy, makePublic, off);
}
}
}

0 comments on commit d92f2f4

Please sign in to comment.