This is an automated email from the ASF dual-hosted git repository.

lostluck pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 366db73bf19 Disable SoftDeletePolicy when creating a default bucket 
(#31748)
366db73bf19 is described below

commit 366db73bf198090660a4c6a604ea4925b8ca694d
Author: ljj <[email protected]>
AuthorDate: Tue Jul 2 12:17:59 2024 -0700

    Disable SoftDeletePolicy when creating a default bucket (#31748)
---
 sdks/go/pkg/beam/util/gcsx/gcs.go      | 15 +++++++++++++--
 sdks/go/pkg/beam/util/gcsx/gcs_test.go | 10 ++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/sdks/go/pkg/beam/util/gcsx/gcs.go 
b/sdks/go/pkg/beam/util/gcsx/gcs.go
index 83eeb823f4a..1dd85924447 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 90fb4b59f2f..463ba3ea183 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)
+       }
+}

Reply via email to