diff --git a/storage/bucket.go b/storage/bucket.go index 478482645fab..ec34c9af4c6b 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -455,6 +455,10 @@ type LifecycleCondition struct { // the specified date in UTC. CreatedBefore time.Time + // DaysSinceNoncurrentTime is the days elapsed since the noncurrent timestamp + // of the object. This condition is relevant only for versioned objects. + DaysSinceNoncurrentTime int64 + // Liveness specifies the object's liveness. Relevant only for versioned objects Liveness Liveness @@ -464,6 +468,10 @@ type LifecycleCondition struct { // Values include "STANDARD", "NEARLINE", "COLDLINE" and "ARCHIVE". MatchesStorageClasses []string + // NoncurrentTimeBefore is the noncurrent timestamp of the object. This + // condition is relevant only for versioned objects. + NoncurrentTimeBefore time.Time + // NumNewerVersions is the condition matching objects with a number of newer versions. // // If the value is N, this condition is satisfied when there are at least N @@ -946,9 +954,10 @@ func toRawLifecycle(l Lifecycle) *raw.BucketLifecycle { StorageClass: r.Action.StorageClass, }, Condition: &raw.BucketLifecycleRuleCondition{ - Age: r.Condition.AgeInDays, - MatchesStorageClass: r.Condition.MatchesStorageClasses, - NumNewerVersions: r.Condition.NumNewerVersions, + Age: r.Condition.AgeInDays, + DaysSinceNoncurrentTime: r.Condition.DaysSinceNoncurrentTime, + MatchesStorageClass: r.Condition.MatchesStorageClasses, + NumNewerVersions: r.Condition.NumNewerVersions, }, } @@ -964,6 +973,9 @@ func toRawLifecycle(l Lifecycle) *raw.BucketLifecycle { if !r.Condition.CreatedBefore.IsZero() { rr.Condition.CreatedBefore = r.Condition.CreatedBefore.Format(rfc3339Date) } + if !r.Condition.NoncurrentTimeBefore.IsZero() { + rr.Condition.NoncurrentTimeBefore = r.Condition.NoncurrentTimeBefore.Format(rfc3339Date) + } rl.Rule = append(rl.Rule, rr) } return &rl @@ -981,9 +993,10 @@ func toLifecycle(rl *raw.BucketLifecycle) Lifecycle { StorageClass: rr.Action.StorageClass, }, Condition: LifecycleCondition{ - AgeInDays: rr.Condition.Age, - MatchesStorageClasses: rr.Condition.MatchesStorageClass, - NumNewerVersions: rr.Condition.NumNewerVersions, + AgeInDays: rr.Condition.Age, + DaysSinceNoncurrentTime: rr.Condition.DaysSinceNoncurrentTime, + MatchesStorageClasses: rr.Condition.MatchesStorageClass, + NumNewerVersions: rr.Condition.NumNewerVersions, }, } @@ -998,6 +1011,9 @@ func toLifecycle(rl *raw.BucketLifecycle) Lifecycle { if rr.Condition.CreatedBefore != "" { r.Condition.CreatedBefore, _ = time.Parse(rfc3339Date, rr.Condition.CreatedBefore) } + if rr.Condition.NoncurrentTimeBefore != "" { + r.Condition.NoncurrentTimeBefore, _ = time.Parse(rfc3339Date, rr.Condition.NoncurrentTimeBefore) + } l.Rules = append(l.Rules, r) } return l diff --git a/storage/bucket_test.go b/storage/bucket_test.go index e1bddda3eef3..7293a35046b3 100644 --- a/storage/bucket_test.go +++ b/storage/bucket_test.go @@ -76,11 +76,11 @@ func TestBucketAttrsToRawBucket(t *testing.T) { Type: DeleteAction, }, Condition: LifecycleCondition{ - AgeInDays: 30, - Liveness: Live, - CreatedBefore: time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC), - MatchesStorageClasses: []string{"NEARLINE"}, - NumNewerVersions: 10, + DaysSinceNoncurrentTime: 30, + Liveness: Live, + NoncurrentTimeBefore: time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC), + MatchesStorageClasses: []string{"NEARLINE"}, + NumNewerVersions: 10, }, }, { Action: LifecycleAction{ @@ -142,11 +142,11 @@ func TestBucketAttrsToRawBucket(t *testing.T) { Type: DeleteAction, }, Condition: &raw.BucketLifecycleRuleCondition{ - Age: 30, - IsLive: googleapi.Bool(true), - CreatedBefore: "2017-01-02", - MatchesStorageClass: []string{"NEARLINE"}, - NumNewerVersions: 10, + DaysSinceNoncurrentTime: 30, + IsLive: googleapi.Bool(true), + NoncurrentTimeBefore: "2017-01-02", + MatchesStorageClass: []string{"NEARLINE"}, + NumNewerVersions: 10, }, }, { Action: &raw.BucketLifecycleRuleAction{