diff --git a/storage/bucket.go b/storage/bucket.go index c3ba89942fd..9539bd6dba2 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -725,12 +725,20 @@ type LifecycleCondition struct { // Liveness specifies the object's liveness. Relevant only for versioned objects Liveness Liveness + // MatchesPrefix is the condition matching an object if any of the + // matches_prefix strings are an exact prefix of the object's name. + MatchesPrefix []string + // MatchesStorageClasses is the condition matching the object's storage // class. // // Values include "STANDARD", "NEARLINE", "COLDLINE" and "ARCHIVE". MatchesStorageClasses []string + // MatchesSuffix is the condition matching an object if any of the + // matches_suffix strings are an exact suffix of the object's name. + MatchesSuffix []string + // NoncurrentTimeBefore is the noncurrent timestamp of the object. This // condition is satisfied when an object's noncurrent timestamp is before // midnight of the specified date in UTC. @@ -1510,7 +1518,9 @@ func toRawLifecycle(l Lifecycle) *raw.BucketLifecycle { Age: r.Condition.AgeInDays, DaysSinceCustomTime: r.Condition.DaysSinceCustomTime, DaysSinceNoncurrentTime: r.Condition.DaysSinceNoncurrentTime, + MatchesPrefix: r.Condition.MatchesPrefix, MatchesStorageClass: r.Condition.MatchesStorageClasses, + MatchesSuffix: r.Condition.MatchesSuffix, NumNewerVersions: r.Condition.NumNewerVersions, }, } @@ -1555,7 +1565,9 @@ func toProtoLifecycle(l Lifecycle) *storagepb.Bucket_Lifecycle { AgeDays: proto.Int32(int32(r.Condition.AgeInDays)), DaysSinceCustomTime: proto.Int32(int32(r.Condition.DaysSinceCustomTime)), DaysSinceNoncurrentTime: proto.Int32(int32(r.Condition.DaysSinceNoncurrentTime)), + MatchesPrefix: r.Condition.MatchesPrefix, MatchesStorageClass: r.Condition.MatchesStorageClasses, + MatchesSuffix: r.Condition.MatchesSuffix, NumNewerVersions: proto.Int32(int32(r.Condition.NumNewerVersions)), }, } @@ -1598,7 +1610,9 @@ func toLifecycle(rl *raw.BucketLifecycle) Lifecycle { AgeInDays: rr.Condition.Age, DaysSinceCustomTime: rr.Condition.DaysSinceCustomTime, DaysSinceNoncurrentTime: rr.Condition.DaysSinceNoncurrentTime, + MatchesPrefix: rr.Condition.MatchesPrefix, MatchesStorageClasses: rr.Condition.MatchesStorageClass, + MatchesSuffix: rr.Condition.MatchesSuffix, NumNewerVersions: rr.Condition.NumNewerVersions, }, } @@ -1640,7 +1654,9 @@ func toLifecycleFromProto(rl *storagepb.Bucket_Lifecycle) Lifecycle { AgeInDays: int64(rr.GetCondition().GetAgeDays()), DaysSinceCustomTime: int64(rr.GetCondition().GetDaysSinceCustomTime()), DaysSinceNoncurrentTime: int64(rr.GetCondition().GetDaysSinceNoncurrentTime()), + MatchesPrefix: rr.GetCondition().GetMatchesPrefix(), MatchesStorageClasses: rr.GetCondition().GetMatchesStorageClass(), + MatchesSuffix: rr.GetCondition().GetMatchesSuffix(), NumNewerVersions: int64(rr.GetCondition().GetNumNewerVersions()), }, } diff --git a/storage/bucket_test.go b/storage/bucket_test.go index 2accecf9797..57051f4e131 100644 --- a/storage/bucket_test.go +++ b/storage/bucket_test.go @@ -96,6 +96,16 @@ func TestBucketAttrsToRawBucket(t *testing.T) { MatchesStorageClasses: []string{"NEARLINE"}, NumNewerVersions: 10, }, + }, { + Action: LifecycleAction{ + Type: DeleteAction, + }, + Condition: LifecycleCondition{ + AgeInDays: 10, + MatchesPrefix: []string{"testPrefix"}, + MatchesSuffix: []string{"testSuffix"}, + NumNewerVersions: 3, + }, }, { Action: LifecycleAction{ Type: DeleteAction, @@ -184,7 +194,19 @@ func TestBucketAttrsToRawBucket(t *testing.T) { MatchesStorageClass: []string{"NEARLINE"}, NumNewerVersions: 10, }, - }, { + }, + { + Action: &raw.BucketLifecycleRuleAction{ + Type: DeleteAction, + }, + Condition: &raw.BucketLifecycleRuleCondition{ + Age: 10, + MatchesPrefix: []string{"testPrefix"}, + MatchesSuffix: []string{"testSuffix"}, + NumNewerVersions: 3, + }, + }, + { Action: &raw.BucketLifecycleRuleAction{ Type: DeleteAction, }, diff --git a/storage/integration_test.go b/storage/integration_test.go index a72d5cc466e..c5ce30dbef5 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -299,6 +299,16 @@ func TestIntegration_BucketCreateDelete(t *testing.T) { MatchesStorageClasses: []string{"NEARLINE"}, NumNewerVersions: 10, }, + }, { + Action: LifecycleAction{ + Type: DeleteAction, + }, + Condition: LifecycleCondition{ + AgeInDays: 10, + MatchesPrefix: []string{"testPrefix"}, + MatchesSuffix: []string{"testSuffix"}, + NumNewerVersions: 3, + }, }}, } @@ -518,8 +528,12 @@ func TestIntegration_BucketUpdate(t *testing.T) { wantLifecycle := Lifecycle{ Rules: []LifecycleRule{ { - Action: LifecycleAction{Type: "Delete"}, - Condition: LifecycleCondition{AgeInDays: 30}, + Action: LifecycleAction{Type: "Delete"}, + Condition: LifecycleCondition{ + AgeInDays: 30, + MatchesPrefix: []string{"testPrefix"}, + MatchesSuffix: []string{"testSuffix"}, + }, }, }, }