-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat: add object retention feature #2277
Conversation
google-cloud-storage/src/main/java/com/google/cloud/storage/BlobInfo.java
Outdated
Show resolved
Hide resolved
google-cloud-storage/src/main/java/com/google/cloud/storage/BlobInfo.java
Outdated
Show resolved
Hide resolved
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember, do we usually do toBuilder()
for the nested model classes or only the top level ones?
google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
Outdated
Show resolved
Hide resolved
google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
Show resolved
Hide resolved
google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
Outdated
Show resolved
Hide resolved
google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
Outdated
Show resolved
Hide resolved
google-cloud-storage/src/main/java/com/google/cloud/storage/UnifiedOpts.java
Show resolved
Hide resolved
google-cloud-storage/src/main/java/com/google/cloud/storage/UnifiedOpts.java
Show resolved
Hide resolved
// Create a bucket with object retention enabled | ||
storage.create( | ||
BucketInfo.newBuilder(bucketName).build(), BucketTargetOption.enableObjectRetention(true)); | ||
|
||
try { | ||
Bucket remoteBucket = storage.get(bucketName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If interested, you could use the TemporaryBucket helper to create and automatically cleanup the bucket. Example of this
java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBucketTest.java
Lines 123 to 124 in cf944ae
try (TemporaryBucket tempB = | |
TemporaryBucket.newBuilder().setBucketInfo(bucketInfo).setStorage(storage).build()) { |
@@ -238,6 +246,11 @@ private StorageObject blobInfoEncode(BlobInfo from) { | |||
from.getRetentionExpirationTimeOffsetDateTime(), | |||
dateTimeCodec::encode, | |||
to::setRetentionExpirationTime); | |||
if (from.getRetention() == null) { | |||
to.setRetention(Data.nullOf(StorageObject.Retention.class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the conclusion on detecting if a user set retention to null vs. it not being modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't work, due to the modified fields not being passed along to the final patch call. I talked to ben and we agreed to just do it this way, there's precedent for it in the logging encoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying, is this value mutable once set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only certain cases work (i.e. going from Unlocked to Locked, reducing the retainUntilTime on an unlocked policy, and setting to null), and you have to pass in overrideUnlockedRetention
for any of those cases to work, but yes
No longer blocking, but tests can't pass yet so not approving
The current failure is just because the test project isn't allowlisted yet, it should be soon |
Adds the object retention feature and tests