Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#31605][Go SDK] Disable SoftDeletePolicy when creating a default bucket #31748

Merged
merged 5 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading