Skip to content

Commit

Permalink
Disable SoftDeletePolicy when creating a default bucket (apache#31748)
Browse files Browse the repository at this point in the history
  • Loading branch information
mls3odp authored and acrites committed Jul 17, 2024
1 parent 61daa01 commit d1b4f19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 13 additions & 2 deletions sdks/go/pkg/beam/util/gcsx/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ func Upload(ctx context.Context, client *storage.Client, project, bucket, object

}

// CreateBucket creates a bucket in GCS.
// Get BucketAttrs with RetentionDuration of SoftDeletePolicy set to zero for disabling SoftDeletePolicy.
func getDisableSoftDeletePolicyBucketAttrs() *storage.BucketAttrs {
attrs := &storage.BucketAttrs{
SoftDeletePolicy: &storage.SoftDeletePolicy{
RetentionDuration: 0,
},
}
return attrs
}

// CreateBucket creates a bucket in GCS with RetentionDuration of zero to disable SoftDeletePolicy.
func CreateBucket(ctx context.Context, client *storage.Client, project, bucket string) error {
return client.Bucket(bucket).Create(ctx, project, nil)
disableSoftDeletePolicyBucketAttrs := getDisableSoftDeletePolicyBucketAttrs()
return client.Bucket(bucket).Create(ctx, project, disableSoftDeletePolicyBucketAttrs)
}

// BucketExists returns true iff the given bucket exists.
Expand Down
10 changes: 10 additions & 0 deletions sdks/go/pkg/beam/util/gcsx/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ func TestJoin(t *testing.T) {
}
}
}

func TestGetDisableSoftDeletePolicyBucketAttrs(t *testing.T) {
attrs := getDisableSoftDeletePolicyBucketAttrs()
if attrs == nil {
t.Errorf("Fail to getDisableSoftDeletePolicyBucketAttrs.")
}
if attrs != nil && attrs.SoftDeletePolicy.RetentionDuration != 0 {
t.Errorf("attrs has RetentionDuration %v which is not correct", attrs.SoftDeletePolicy.RetentionDuration)
}
}

0 comments on commit d1b4f19

Please sign in to comment.