Skip to content

Commit

Permalink
feat(storage): support AbortIncompleteMultipartUpload LifecycleAction (
Browse files Browse the repository at this point in the history
…#5812)

Adds a new LifecycleAction value.

Fixes #5795

Co-authored-by: Sameena Shaffeeullah <samazisha@gmail.com>
Co-authored-by: Chris Cotter <cjcotter@google.com>
  • Loading branch information
3 people committed Jun 8, 2022
1 parent 495775e commit fdec929
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
12 changes: 9 additions & 3 deletions storage/bucket.go
Expand Up @@ -645,6 +645,13 @@ const (
// SetStorageClassAction changes the storage class of live and/or archived
// objects.
SetStorageClassAction = "SetStorageClass"

// AbortIncompleteMPUAction is a lifecycle action that aborts an incomplete
// multipart upload when the multipart upload meets the conditions specified
// in the lifecycle rule. The AgeInDays condition is the only allowed
// condition for this action. AgeInDays is measured from the time the
// multipart upload was created.
AbortIncompleteMPUAction = "AbortIncompleteMultipartUpload"
)

// LifecycleRule is a lifecycle configuration rule.
Expand All @@ -665,9 +672,8 @@ type LifecycleRule struct {
type LifecycleAction struct {
// Type is the type of action to take on matching objects.
//
// Acceptable values are "Delete" to delete matching objects and
// "SetStorageClass" to set the storage class defined in StorageClass on
// matching objects.
// Acceptable values are storage.DeleteAction, storage.SetStorageClassAction,
// and storage.AbortIncompleteMPUAction.
Type string

// StorageClass is the storage class to set on matching objects if the Action
Expand Down
22 changes: 22 additions & 0 deletions storage/bucket_test.go
Expand Up @@ -103,6 +103,13 @@ func TestBucketAttrsToRawBucket(t *testing.T) {
Condition: LifecycleCondition{
Liveness: Archived,
},
}, {
Action: LifecycleAction{
Type: AbortIncompleteMPUAction,
},
Condition: LifecycleCondition{
AgeInDays: 20,
},
}},
},
}
Expand Down Expand Up @@ -184,6 +191,13 @@ func TestBucketAttrsToRawBucket(t *testing.T) {
Condition: &raw.BucketLifecycleRuleCondition{
IsLive: googleapi.Bool(false),
},
}, {
Action: &raw.BucketLifecycleRuleAction{
Type: AbortIncompleteMPUAction,
},
Condition: &raw.BucketLifecycleRuleCondition{
Age: 20,
},
}},
},
}
Expand Down Expand Up @@ -329,6 +343,10 @@ func TestBucketAttrsToUpdateToRawBucket(t *testing.T) {
Action: LifecycleAction{Type: "Delete"},
Condition: LifecycleCondition{AgeInDays: 30},
},
{
Action: LifecycleAction{Type: AbortIncompleteMPUAction},
Condition: LifecycleCondition{AgeInDays: 13},
},
},
},
Logging: &BucketLogging{LogBucket: "lb", LogObjectPrefix: "p"},
Expand Down Expand Up @@ -368,6 +386,10 @@ func TestBucketAttrsToUpdateToRawBucket(t *testing.T) {
Action: &raw.BucketLifecycleRuleAction{Type: "Delete"},
Condition: &raw.BucketLifecycleRuleCondition{Age: 30},
},
{
Action: &raw.BucketLifecycleRuleAction{Type: AbortIncompleteMPUAction},
Condition: &raw.BucketLifecycleRuleCondition{Age: 13},
},
},
},
Logging: &raw.BucketLogging{LogBucket: "lb", LogObjectPrefix: "p"},
Expand Down
43 changes: 43 additions & 0 deletions storage/integration_test.go
Expand Up @@ -410,6 +410,49 @@ func TestIntegration_BucketCreateDelete(t *testing.T) {
}
}

func TestIntegration_BucketLifecycle(t *testing.T) {
ctx := context.Background()
client := testConfig(ctx, t)
defer client.Close()
h := testHelper{t}

wantLifecycle := Lifecycle{
Rules: []LifecycleRule{
{
Action: LifecycleAction{Type: AbortIncompleteMPUAction},
Condition: LifecycleCondition{AgeInDays: 30},
},
},
}

bucket := client.Bucket(uidSpace.New())

// Create bucket with lifecycle rules
bucket.Create(ctx, testutil.ProjID(), &BucketAttrs{
Lifecycle: wantLifecycle,
})
defer h.mustDeleteBucket(bucket)

attrs := h.mustBucketAttrs(bucket)
if !testutil.Equal(attrs.Lifecycle, wantLifecycle) {
t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle)
}

// Remove lifecycle rules
ua := BucketAttrsToUpdate{Lifecycle: &Lifecycle{}}
attrs = h.mustUpdateBucket(bucket, ua, attrs.MetaGeneration)
if !testutil.Equal(attrs.Lifecycle, Lifecycle{}) {
t.Fatalf("got %v, want %v", attrs.Lifecycle, Lifecycle{})
}

// Update bucket with a lifecycle rule
ua = BucketAttrsToUpdate{Lifecycle: &wantLifecycle}
attrs = h.mustUpdateBucket(bucket, ua, attrs.MetaGeneration)
if !testutil.Equal(attrs.Lifecycle, wantLifecycle) {
t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle)
}
}

func TestIntegration_BucketUpdate(t *testing.T) {
ctx := context.Background()
client := testConfig(ctx, t)
Expand Down

0 comments on commit fdec929

Please sign in to comment.