diff --git a/sdks/go/pkg/beam/util/gcsx/gcs.go b/sdks/go/pkg/beam/util/gcsx/gcs.go index 83eeb823f4a2..1dd85924447f 100644 --- a/sdks/go/pkg/beam/util/gcsx/gcs.go +++ b/sdks/go/pkg/beam/util/gcsx/gcs.go @@ -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. diff --git a/sdks/go/pkg/beam/util/gcsx/gcs_test.go b/sdks/go/pkg/beam/util/gcsx/gcs_test.go index 90fb4b59f2fe..463ba3ea1833 100644 --- a/sdks/go/pkg/beam/util/gcsx/gcs_test.go +++ b/sdks/go/pkg/beam/util/gcsx/gcs_test.go @@ -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) + } +}