Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added versioning for S3 buckets #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.amazonaws.services.s3.model.BucketNotificationConfiguration;
import com.amazonaws.services.s3.model.BucketPolicy;
import com.amazonaws.services.s3.model.BucketTaggingConfiguration;
import com.amazonaws.services.s3.model.BucketVersioningConfiguration;
import com.amazonaws.services.s3.model.BucketWebsiteConfiguration;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.CreateBucketRequest;
Expand All @@ -42,6 +43,7 @@
import com.amazonaws.services.s3.model.SetBucketLoggingConfigurationRequest;
import com.amazonaws.services.s3.model.SetBucketNotificationConfigurationRequest;
import com.amazonaws.services.s3.model.SetBucketPolicyRequest;
import com.amazonaws.services.s3.model.SetBucketVersioningConfigurationRequest;
import com.amazonaws.services.s3.model.TopicConfiguration;
import com.amazonaws.util.IOUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -175,6 +177,7 @@ public void brokerBucketFromEcsPush(AmazonS3 s3Client, AWSKMS kmsClient, S3Bucke
taskProperties.getS3().getDefaultEncryption() : bucket.getEncryptionOption());
configuration.setSnsNotifications(bucket.getSnsNotifications());
configuration.setLambdaNotifications(bucket.getLambdaNotifications());
configuration.setVersioning(bucket.getVersioning());

if (S3EncryptionOption.KMS.equals(configuration.getEncryptionOption()) && kmsKeyId != null) {
String kmsKeyArn = kmsClient.describeKey(new DescribeKeyRequest().withKeyId(kmsKeyId)).getKeyMetadata().getArn();
Expand Down Expand Up @@ -297,6 +300,19 @@ private void brokerBucket(AmazonS3 client, S3InjectConfiguration configuration,
configuration.getAppName(),
new BucketLoggingConfiguration()));
}

if(configuration.getVersioning()) {
buildLogger.addLogEntry("S3 Versioning enabled");
BucketVersioningConfiguration bucketVersioningConfiguration =
new BucketVersioningConfiguration().withStatus("Enabled");

SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest =
new SetBucketVersioningConfigurationRequest(bucketName,bucketVersioningConfiguration);

client.setBucketVersioningConfiguration(setBucketVersioningConfigurationRequest);
} else {
buildLogger.addLogEntry("S3 Versioning not enabled");
}
updateNotificationConfiguration(configuration, client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class S3Bucket {
private String name;
private String policyName;
private S3EncryptionOption encryptionOption;
private Boolean versioning = false;
private List<S3EventConfiguration> snsNotifications;
private List<S3EventConfiguration> lambdaNotifications;

Expand Down Expand Up @@ -49,6 +50,10 @@ public void setEncryptionOption(S3EncryptionOption encryptionOption) {
this.encryptionOption = encryptionOption;
}

public Boolean getVersioning() { return versioning; }

public void setVersioning(Boolean versioning) { this.versioning = versioning; }

public List<S3EventConfiguration> getSnsNotifications() {
return snsNotifications;
}
Expand Down Expand Up @@ -83,6 +88,11 @@ public S3Bucket withEncryptionOption(
return this;
}

public S3Bucket withVersioning(final Boolean versioning) {
this.versioning = versioning;
return this;
}

public S3Bucket withLambdaNotifications(final List<S3EventConfiguration> lambdaNotifications) {
this.lambdaNotifications = lambdaNotifications;
return this;
Expand All @@ -99,6 +109,7 @@ public String toString() {
"name='" + name + '\'' +
", policyName='" + policyName + '\'' +
", encryptionOption=" + encryptionOption + '\'' +
", versioning=" + versioning + '\'' +
", lambdaNotifications=" + lambdaNotifications + '\'' +
", snsNotifications=" + snsNotifications +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class S3InjectConfiguration implements KmsAppDefinition {
private String kmsKeyArn;
private String kmsKeyName;
private List<HermanTag> tags;
private Boolean versioning = false;

// Index and Error files used for website buckets
private String indexFile = "index.html";
Expand Down Expand Up @@ -157,6 +158,10 @@ public void setSnsNotifications(
this.snsNotifications = snsNotifications;
}

public Boolean getVersioning() { return versioning; }

public void setVersioning(Boolean versioning) { this.versioning = versioning; }

public S3InjectConfiguration withAppName(final String appName) {
this.appName = appName;
return this;
Expand Down Expand Up @@ -224,6 +229,11 @@ public S3InjectConfiguration withSnsNotifications(final List<S3EventConfiguratio
return this;
}

public S3InjectConfiguration withVersioning(final Boolean versioning) {
this.versioning = versioning;
return this;
}

@Override
public String toString() {
return "S3InjectConfiguration{" +
Expand All @@ -241,6 +251,7 @@ public String toString() {
", tags=" + tags +
", indexFile='" + indexFile + '\'' +
", errorFile='" + errorFile + '\'' +
", versioning='" + versioning + '\'' +
'}';
}
}