listDefaultAcls() {
return storage.listDefaultAcls(getName());
}
+ /**
+ * Locks bucket retention policy. Requires a local metageneration value in the request. Review example below.
+ *
+ * Accepts an optional userProject {@link BucketTargetOption} option which defines the project id
+ * to assign operational costs.
+ *
+ *
Warning: Once a retention policy is locked, it can't be unlocked, removed, or shortened.
+ *
+ *
Example of locking a retention policy on a bucket, only if its local metageneration value matches the bucket's
+ * service metageneration otherwise a {@link StorageException} is thrown.
+ *
{@code
+ * String bucketName = "my_unique_bucket";
+ * Bucket bucket = storage.get(bucketName, BucketGetOption.fields(BucketField.METAGENERATION));
+ * storage.lockRetentionPolicy(bucket, BucketTargetOption.metagenerationMatch());
+ * }
+ *
+ * @return a {@code Bucket} object of the locked bucket
+ * @throws StorageException upon failure
+ */
+ public Bucket lockRetentionPolicy(BucketTargetOption... options) {
+ return storage.lockRetentionPolicy(this, options);
+ }
+
/**
* Returns the bucket's {@code Storage} object used to issue requests.
*/
diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
index 6e0b3e2c38e9..e24a5a7a89eb 100644
--- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
+++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
@@ -88,6 +88,10 @@ public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo)
private final StorageClass storageClass;
private final Map labels;
private final String defaultKmsKeyName;
+ private final Boolean defaultEventBasedHold;
+ private final Long retentionEffectiveTime;
+ private final Boolean retentionPolicyIsLocked;
+ private final Long retentionPeriod;
/**
* Base class for bucket's delete rules. Allows to configure automatic deletion of blobs and blobs
@@ -346,7 +350,6 @@ public abstract static class Builder {
* Sets whether a user accessing the bucket or an object it contains should assume the transit costs
* related to the access.
*
- * GcpLaunchStage.Alpha
*/
public abstract Builder setRequesterPays(Boolean requesterPays);
@@ -429,9 +432,23 @@ public abstract static class Builder {
/**
* Sets the default Cloud KMS key name for this bucket.
*/
- @GcpLaunchStage.Beta
public abstract Builder setDefaultKmsKeyName(String defaultKmsKeyName);
+ /**
+ * Sets the default event based hold for this bucket.
+ */
+ public abstract Builder setDefaultEventBasedHold(Boolean defaultEventBasedHold);
+
+ abstract Builder setRetentionEffectiveTime(Long retentionEffectiveTime);
+
+ abstract Builder setRetentionPolicyIsLocked(Boolean retentionPolicyIsLocked);
+
+ /**
+ * If policy is not locked this value can be cleared, increased, and decreased.
+ * If policy is locked the retention period can only be increased.
+ */
+ public abstract Builder setRetentionPeriod(Long retentionPeriod);
+
/**
* Creates a {@code BucketInfo} object.
*/
@@ -459,6 +476,10 @@ static final class BuilderImpl extends Builder {
private List defaultAcl;
private Map labels;
private String defaultKmsKeyName;
+ private Boolean defaultEventBasedHold;
+ private Long retentionEffectiveTime;
+ private Boolean retentionPolicyIsLocked;
+ private Long retentionPeriod;
BuilderImpl(String name) {
this.name = name;
@@ -484,6 +505,10 @@ static final class BuilderImpl extends Builder {
labels = bucketInfo.labels;
requesterPays = bucketInfo.requesterPays;
defaultKmsKeyName = bucketInfo.defaultKmsKeyName;
+ defaultEventBasedHold = bucketInfo.defaultEventBasedHold;
+ retentionEffectiveTime = bucketInfo.retentionEffectiveTime;
+ retentionPolicyIsLocked = bucketInfo.retentionPolicyIsLocked;
+ retentionPeriod = bucketInfo.retentionPeriod;
}
@Override
@@ -516,7 +541,6 @@ public Builder setVersioningEnabled(Boolean enable) {
return this;
}
- /** GcpLaunchStage.Alpha */
@Override
public Builder setRequesterPays(Boolean enable) {
this.requesterPays = firstNonNull(enable, Data.nullOf(Boolean.class));
@@ -595,7 +619,6 @@ public Builder setLabels(Map labels) {
return this;
}
- @GcpLaunchStage.Beta
@Override
public Builder setDefaultKmsKeyName(String defaultKmsKeyName) {
this.defaultKmsKeyName = defaultKmsKeyName != null
@@ -603,6 +626,30 @@ public Builder setDefaultKmsKeyName(String defaultKmsKeyName) {
return this;
}
+ @Override
+ public Builder setDefaultEventBasedHold(Boolean defaultEventBasedHold) {
+ this.defaultEventBasedHold = firstNonNull(defaultEventBasedHold, Data.nullOf(Boolean.class));
+ return this;
+ }
+
+ @Override
+ Builder setRetentionEffectiveTime(Long retentionEffectiveTime) {
+ this.retentionEffectiveTime = firstNonNull(retentionEffectiveTime, Data.nullOf(Long.class));
+ return this;
+ }
+
+ @Override
+ Builder setRetentionPolicyIsLocked(Boolean retentionPolicyIsLocked) {
+ this.retentionPolicyIsLocked = firstNonNull(retentionPolicyIsLocked, Data.nullOf(Boolean.class));
+ return this;
+ }
+
+ @Override
+ public Builder setRetentionPeriod(Long retentionPeriod) {
+ this.retentionPeriod = firstNonNull(retentionPeriod, Data.nullOf(Long.class));
+ return this;
+ }
+
@Override
public BucketInfo build() {
checkNotNull(name);
@@ -630,6 +677,10 @@ public BucketInfo build() {
labels = builder.labels;
requesterPays = builder.requesterPays;
defaultKmsKeyName = builder.defaultKmsKeyName;
+ defaultEventBasedHold = builder.defaultEventBasedHold;
+ retentionEffectiveTime = builder.retentionEffectiveTime;
+ retentionPolicyIsLocked = builder.retentionPolicyIsLocked;
+ retentionPeriod = builder.retentionPeriod;
}
/**
@@ -667,12 +718,10 @@ public Boolean versioningEnabled() {
return Data.isNull(versioningEnabled) ? null : versioningEnabled;
}
-
/**
* Returns {@code true} if a user accessing the bucket or an object it contains should assume the transit costs
* related to the access, {@code false} otherwise.
*
- * GcpLaunchStage.Alpha
*/
public Boolean requesterPays() {
return Data.isNull(requesterPays) ? null : requesterPays;
@@ -785,11 +834,32 @@ public Map getLabels() {
/**
* Returns the default Cloud KMS key to be applied to newly inserted objects in this bucket.
*/
- @GcpLaunchStage.Beta
public String getDefaultKmsKeyName() {
return defaultKmsKeyName;
}
+ /**
+ * Returns the default event based hold value used for inserted objects in this bucket.
+ */
+ public Boolean getDefaultEventBasedHold() { return defaultEventBasedHold; }
+
+ /**
+ * Returns the retention effective time a policy took effect if a retention policy is defined.
+ */
+ public Long getRetentionEffectiveTime() { return retentionEffectiveTime; }
+
+ /**
+ * Returns {@code true} if the bucket retention policy is locked, {@code false} otherwise.
+ */
+ public Boolean retentionPolicyIsLocked() {
+ return Data.isNull(retentionPolicyIsLocked) ? null : retentionPolicyIsLocked;
+ }
+
+ /**
+ * Returns the retention policy retention period.
+ */
+ public Long getRetentionPeriod() { return retentionPeriod; }
+
/**
* Returns a builder for the current bucket.
*/
@@ -888,6 +958,23 @@ public Rule apply(DeleteRule deleteRule) {
if (defaultKmsKeyName != null) {
bucketPb.setEncryption(new Encryption().setDefaultKmsKeyName(defaultKmsKeyName));
}
+ if (defaultEventBasedHold != null) {
+ bucketPb.setDefaultEventBasedHold(defaultEventBasedHold);
+ }
+ if (retentionPeriod != null || retentionEffectiveTime != null || retentionPolicyIsLocked != null) {
+ Bucket.RetentionPolicy retentionPolicy = new Bucket.RetentionPolicy();
+ if (retentionPeriod != null) {
+ retentionPolicy.setRetentionPeriod(retentionPeriod);
+ }
+ if (retentionEffectiveTime != null) {
+ retentionPolicy.setEffectiveTime(new DateTime(retentionEffectiveTime));
+ }
+ if (retentionPolicyIsLocked != null) {
+ retentionPolicy.setIsLocked(retentionPolicyIsLocked);
+ }
+ bucketPb.setRetentionPolicy(retentionPolicy);
+ }
+
return bucketPb;
}
@@ -979,6 +1066,21 @@ public DeleteRule apply(Rule rule) {
if (encryption != null && encryption.getDefaultKmsKeyName() != null && !encryption.getDefaultKmsKeyName().isEmpty()) {
builder.setDefaultKmsKeyName(encryption.getDefaultKmsKeyName());
}
+ if (bucketPb.getDefaultEventBasedHold() != null) {
+ builder.setDefaultEventBasedHold(bucketPb.getDefaultEventBasedHold());
+ }
+ Bucket.RetentionPolicy retentionPolicy = bucketPb.getRetentionPolicy();
+ if (retentionPolicy != null) {
+ if (retentionPolicy.getEffectiveTime() != null) {
+ builder.setRetentionEffectiveTime(retentionPolicy.getEffectiveTime().getValue());
+ }
+ if (retentionPolicy.getIsLocked() != null) {
+ builder.setRetentionPolicyIsLocked(retentionPolicy.getIsLocked());
+ }
+ if (retentionPolicy.getRetentionPeriod() != null) {
+ builder.setRetentionPeriod(retentionPolicy.getRetentionPeriod());
+ }
+ }
return builder.build();
}
}
diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
index 78f9390a67e4..b67fe2645541 100644
--- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
+++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
@@ -93,9 +93,10 @@ enum BucketField implements FieldSelector {
CORS("cors"),
STORAGE_CLASS("storageClass"),
ETAG("etag"),
- @GcpLaunchStage.Beta
ENCRYPTION("encryption"),
- BILLING("billing");
+ BILLING("billing"),
+ DEFAULT_EVENT_BASED_HOLD("defaultEventBasedHold"),
+ RETENTION_POLICY("retentionPolicy");
static final List extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(NAME);
@@ -136,8 +137,10 @@ enum BlobField implements FieldSelector {
SIZE("size"),
STORAGE_CLASS("storageClass"),
TIME_DELETED("timeDeleted"),
- @GcpLaunchStage.Beta
KMS_KEY_NAME("kmsKeyName"),
+ EVENT_BASED_HOLD("eventBasedHold"),
+ TEMPORARY_HOLD("temporaryHold"),
+ RETENTION_EXPIRATION_TIME("retentionExpirationTime"),
UPDATED("updated");
static final List extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(BUCKET, NAME);
@@ -388,7 +391,6 @@ public static BlobTargetOption encryptionKey(String key) {
/**
* Returns an option to set a customer-managed key for server-side encryption of the blob.
*/
- @GcpLaunchStage.Beta
public static BlobTargetOption kmsKeyName(String kmsKeyName) {
return new BlobTargetOption(StorageRpc.Option.KMS_KEY_NAME, kmsKeyName);
}
@@ -550,7 +552,6 @@ public static BlobWriteOption encryptionKey(String key) {
*
* @param kmsKeyName the KMS key resource id
*/
- @GcpLaunchStage.Beta
public static BlobWriteOption kmsKeyName(String kmsKeyName) {
return new BlobWriteOption(Option.KMS_KEY_NAME, kmsKeyName);
}
@@ -1537,6 +1538,27 @@ public static Builder newBuilder() {
*/
Bucket get(String bucket, BucketGetOption... options);
+ /**
+ * Locks bucket retention policy. Requires a local metageneration value in the request. Review example below.
+ *
+ * Accepts an optional userProject {@link BucketTargetOption} option which defines the project id
+ * to assign operational costs.
+ *
+ *
Warning: Once a retention policy is locked, it can't be unlocked, removed, or shortened.
+ *
+ *
Example of locking a retention policy on a bucket, only if its local metageneration value matches the bucket's
+ * service metageneration otherwise a {@link StorageException} is thrown.
+ *
{@code
+ * String bucketName = "my_unique_bucket";
+ * Bucket bucket = storage.get(bucketName, BucketGetOption.fields(BucketField.METAGENERATION));
+ * storage.lockRetentionPolicy(bucket, BucketTargetOption.metagenerationMatch());
+ * }
+ *
+ * @return a {@code Bucket} object of the locked bucket
+ * @throws StorageException upon failure
+ */
+ Bucket lockRetentionPolicy(BucketInfo bucket, BucketTargetOption... options);
+
/**
* Returns the requested blob or {@code null} if not found.
*
diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java
index e49445d13646..787388006571 100644
--- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java
+++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java
@@ -983,6 +983,23 @@ public Boolean apply(String permission) {
}
}
+ @Override
+ public Bucket lockRetentionPolicy(BucketInfo bucketInfo, BucketTargetOption... options) {
+ final com.google.api.services.storage.model.Bucket bucketPb = bucketInfo.toPb();
+ final Map optionsMap = optionMap(bucketInfo, options);
+ try {
+ return Bucket.fromPb(this, runWithRetries(
+ new Callable() {
+ @Override
+ public com.google.api.services.storage.model.Bucket call() {
+ return storageRpc.lockRetentionPolicy(bucketPb, optionsMap);
+ }
+ }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
+ } catch (RetryHelperException e) {
+ throw StorageException.translateAndThrow(e);
+ }
+ }
+
@Override
public ServiceAccount getServiceAccount(final String projectId) {
try {
diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java
index 03db33dae835..39cbc3f99ef2 100644
--- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java
+++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java
@@ -1208,6 +1208,23 @@ public Notification createNotification(String bucket, Notification notification)
}
}
+ @Override
+ public Bucket lockRetentionPolicy(Bucket bucket, Map