Skip to content

Commit

Permalink
Merge pull request #18 from ohnosequences/18/storage-class
Browse files Browse the repository at this point in the history
Support storage class setting
  • Loading branch information
laughedelic authored Sep 19, 2017
2 parents cdf68b0 + 59dd005 commit f8ad976
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
35 changes: 31 additions & 4 deletions src/main/java/ohnosequences/ivy/S3Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.StorageClass;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3ObjectSummary;
Expand Down Expand Up @@ -64,16 +65,41 @@ public class S3Repository extends AbstractRepository {

private CannedAccessControlList acl;

public S3Repository(AWSCredentialsProvider provider, boolean overwrite, Region region) {
this(provider, overwrite, region, CannedAccessControlList.PublicRead, false);
private StorageClass storageClass;


public S3Repository(
AWSCredentialsProvider provider,
boolean overwrite,
Region region
) {
this(
provider,
overwrite,
region,
CannedAccessControlList.PublicRead,
false,
StorageClass.Standard
);
}

public S3Repository(AWSCredentialsProvider provider, boolean overwrite, Region region, CannedAccessControlList acl, boolean serverSideEncryption) {
s3Client = AmazonS3Client.builder().standard().withCredentials(provider).withRegion(region.toString()).build();
public S3Repository(
AWSCredentialsProvider provider,
boolean overwrite,
Region region,
CannedAccessControlList acl,
boolean serverSideEncryption,
StorageClass storageClass
) {
s3Client = AmazonS3Client.builder().standard()
.withCredentials(provider)
.withRegion(region.toString())
.build();
this.overwrite = overwrite;
this.region = region;
this.acl = acl;
this.serverSideEncryption = serverSideEncryption;
this.storageClass = storageClass;
}

public void get(String source, File destination) {
Expand Down Expand Up @@ -164,6 +190,7 @@ protected void put(File source, String destination, boolean overwrite) {

PutObjectRequest request =
new PutObjectRequest(bucket, key, source)
.withStorageClass(storageClass)
.withCannedAcl(acl);

if (serverSideEncryption) {
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/ohnosequences/ivy/S3Resolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.StorageClass;
import org.apache.ivy.plugins.resolver.RepositoryResolver;
import com.amazonaws.regions.Region;

Expand All @@ -33,9 +34,24 @@ public S3Resolver(String name, AWSCredentialsProvider credentialsProvider, boole
setRepository(new S3Repository(credentialsProvider, overwrite, region));
}

public S3Resolver(String name, AWSCredentialsProvider credentialsProvider, boolean overwrite, Region region, CannedAccessControlList acl, boolean serverSideEncryption) {
public S3Resolver(
String name,
AWSCredentialsProvider credentialsProvider,
boolean overwrite,
Region region,
CannedAccessControlList acl,
boolean serverSideEncryption,
StorageClass storageClass
) {
setName(name);
setRepository(new S3Repository(credentialsProvider, overwrite, region, acl,serverSideEncryption));
setRepository(new S3Repository(
credentialsProvider,
overwrite,
region,
acl,
serverSideEncryption,
storageClass
));
}

public String getTypeName() {
Expand Down

0 comments on commit f8ad976

Please sign in to comment.