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

feat: add object retention feature #2277

Merged
merged 16 commits into from
Nov 30, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] committed Oct 25, 2023
commit 862a564fc4350f31dbc1ef5d700aff1c7a224430
Original file line number Diff line number Diff line change
@@ -265,7 +265,7 @@ private Mode(String constant) {
private static final ApiFunction<String, Mode> CONSTRUCTOR = Mode::new;

private static final StringEnumType<Mode> type =
new StringEnumType<>(Mode.class, CONSTRUCTOR);
new StringEnumType<>(Mode.class, CONSTRUCTOR);

public static final Mode UNLOCKED = type.createAndRegister("Unlocked");

Original file line number Diff line number Diff line change
@@ -554,7 +554,7 @@ private Mode(String constant) {
private static final ApiFunction<String, Mode> CONSTRUCTOR = Mode::new;

private static final StringEnumType<Mode> type =
new StringEnumType<>(Mode.class, CONSTRUCTOR);
new StringEnumType<>(Mode.class, CONSTRUCTOR);

public static final Mode ENABLED = type.createAndRegister("Enabled");

Original file line number Diff line number Diff line change
@@ -1416,7 +1416,8 @@ private EnableObjectRetention(boolean val) {

@Override
public Mapper<UpdateBucketRequest.Builder> updateBucket() {
return CrossTransportUtils.throwHttpJsonOnly(Storage.BucketTargetOption.class, "enableObjectRetention(boolean)");
return CrossTransportUtils.throwHttpJsonOnly(
Storage.BucketTargetOption.class, "enableObjectRetention(boolean)");
}
}

@@ -1655,7 +1656,8 @@ private OverrideUnlockedRetention(boolean val) {

@Override
public Mapper<UpdateObjectRequest.Builder> updateObject() {
return CrossTransportUtils.throwHttpJsonOnly(Storage.BlobTargetOption.class, "overrideUnlockedRetention(boolean)");
return CrossTransportUtils.throwHttpJsonOnly(
Storage.BlobTargetOption.class, "overrideUnlockedRetention(boolean)");
}
}

Original file line number Diff line number Diff line change
@@ -428,7 +428,7 @@ public void testObjectRetention() {

// Create a bucket with object retention enabled
storage.create(
BucketInfo.newBuilder(bucketName).build(), BucketTargetOption.enableObjectRetention(true));
BucketInfo.newBuilder(bucketName).build(), BucketTargetOption.enableObjectRetention(true));

try {
Bucket remoteBucket = storage.get(bucketName);
@@ -439,44 +439,44 @@ public void testObjectRetention() {

// Create an object with a retention policy configured
storage.create(
BlobInfo.newBuilder(bucketName, "retentionObject")
.setRetention(
BlobInfo.Retention.newBuilder()
.setMode(BlobInfo.Retention.Mode.UNLOCKED)
.setRetainUntilTime(now.plusDays(2))
.build())
.build());
BlobInfo.newBuilder(bucketName, "retentionObject")
.setRetention(
BlobInfo.Retention.newBuilder()
.setMode(BlobInfo.Retention.Mode.UNLOCKED)
.setRetainUntilTime(now.plusDays(2))
.build())
.build());

Blob remoteBlob = storage.get(bucketName, "retentionObject");
assertNotNull(remoteBlob.getRetention());
assertEquals(BlobInfo.Retention.Mode.UNLOCKED, remoteBlob.getRetention().getMode());

// Reduce the retainUntilTime of an object's retention policy
remoteBlob
.toBuilder()
.setRetention(
BlobInfo.Retention.newBuilder()
.setMode(BlobInfo.Retention.Mode.UNLOCKED)
.setRetainUntilTime(now.plusHours(1))
.build())
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));
.toBuilder()
.setRetention(
BlobInfo.Retention.newBuilder()
.setMode(BlobInfo.Retention.Mode.UNLOCKED)
.setRetainUntilTime(now.plusHours(1))
.build())
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));

remoteBlob = storage.get(bucketName, "retentionObject");
assertEquals(
now.plusHours(1).toInstant().truncatedTo(ChronoUnit.SECONDS),
remoteBlob
.getRetention()
.getRetainUntilTime()
.toInstant()
.truncatedTo(ChronoUnit.SECONDS));
now.plusHours(1).toInstant().truncatedTo(ChronoUnit.SECONDS),
remoteBlob
.getRetention()
.getRetainUntilTime()
.toInstant()
.truncatedTo(ChronoUnit.SECONDS));

// Remove an unlocked retention policy
remoteBlob
.toBuilder()
.setRetention(null)
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));
.toBuilder()
.setRetention(null)
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));

remoteBlob = storage.get(bucketName, "retentionObject");
assertNull(remoteBlob.getRetention());