From 8792e20620788ff3d001d4595ce81c2e2ba927ab Mon Sep 17 00:00:00 2001 From: anrajitha Date: Fri, 24 Sep 2021 18:58:08 +0530 Subject: [PATCH 1/4] feat(storage): add projectNumber field to bucketAttrs. --- storage/bucket.go | 4 ++++ storage/bucket_test.go | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/storage/bucket.go b/storage/bucket.go index 602c8512856..95ae5175211 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -337,6 +337,9 @@ type BucketAttrs struct { // Typical values are "multi-region", "region" and "dual-region". // This field is read-only. LocationType string + + // The project number of the project the bucket belongs to. + ProjectNumber uint64 } // BucketPolicyOnly is an alias for UniformBucketLevelAccess. @@ -597,6 +600,7 @@ func newBucket(b *raw.Bucket) (*BucketAttrs, error) { PublicAccessPrevention: toPublicAccessPrevention(b.IamConfiguration), Etag: b.Etag, LocationType: b.LocationType, + ProjectNumber: b.ProjectNumber, }, nil } diff --git a/storage/bucket_test.go b/storage/bucket_test.go index 4ff5f5cc5ed..3919853e731 100644 --- a/storage/bucket_test.go +++ b/storage/bucket_test.go @@ -642,10 +642,11 @@ func TestNewBucket(t *testing.T) { Acl: []*raw.BucketAccessControl{ {Bucket: "name", Role: "READER", Email: "joe@example.com", Entity: "allUsers"}, }, - LocationType: "dual-region", - Encryption: &raw.BucketEncryption{DefaultKmsKeyName: "key"}, - Logging: &raw.BucketLogging{LogBucket: "lb", LogObjectPrefix: "p"}, - Website: &raw.BucketWebsite{MainPageSuffix: "mps", NotFoundPage: "404"}, + LocationType: "dual-region", + Encryption: &raw.BucketEncryption{DefaultKmsKeyName: "key"}, + Logging: &raw.BucketLogging{LogBucket: "lb", LogObjectPrefix: "p"}, + Website: &raw.BucketWebsite{MainPageSuffix: "mps", NotFoundPage: "404"}, + ProjectNumber: 123231313, } want := &BucketAttrs{ Name: "name", @@ -695,6 +696,7 @@ func TestNewBucket(t *testing.T) { ACL: []ACLRule{{Entity: "allUsers", Role: RoleReader, Email: "joe@example.com"}}, DefaultObjectACL: nil, LocationType: "dual-region", + ProjectNumber: 123231313, } got, err := newBucket(rb) if err != nil { From 27390e8bd87a467546c8dd328f4adce0d0325223 Mon Sep 17 00:00:00 2001 From: Rajitha Avantsa Date: Mon, 27 Sep 2021 20:43:20 +0530 Subject: [PATCH 2/4] Added check to integration Test. --- storage/bucket.go | 1 + storage/integration_test.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/storage/bucket.go b/storage/bucket.go index 95ae5175211..f2a59f3b3d1 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -339,6 +339,7 @@ type BucketAttrs struct { LocationType string // The project number of the project the bucket belongs to. + // This field is read-only. ProjectNumber uint64 } diff --git a/storage/integration_test.go b/storage/integration_test.go index 0b90c7dee64..ec54b5bd298 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -265,6 +265,9 @@ func TestIntegration_BucketMethods(t *testing.T) { if attrs.LocationType == "" { t.Error("got an empty LocationType") } + if attrs.ProjectNumber == nil || attrs.ProjectNumber == "" { + t.Errorf("got an empty ProjectNumber") + } h.mustDeleteBucket(b) // Test Create and Delete with attributes. From 78199dc0b934d9a46f0b9c514220ecf07b7795a4 Mon Sep 17 00:00:00 2001 From: Rajitha Avantsa Date: Mon, 27 Sep 2021 20:43:20 +0530 Subject: [PATCH 3/4] Added check to integration Test. --- storage/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/integration_test.go b/storage/integration_test.go index ec54b5bd298..77312fa4fe5 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -265,8 +265,8 @@ func TestIntegration_BucketMethods(t *testing.T) { if attrs.LocationType == "" { t.Error("got an empty LocationType") } - if attrs.ProjectNumber == nil || attrs.ProjectNumber == "" { - t.Errorf("got an empty ProjectNumber") + if attrs.ProjectNumber == 0 { + t.Errorf("got a zero ProjectNumber") } h.mustDeleteBucket(b) From fd12019a96f3464b1da6d401fa9e0f54a68b178d Mon Sep 17 00:00:00 2001 From: Rajitha Avantsa Date: Mon, 27 Sep 2021 22:44:55 +0530 Subject: [PATCH 4/4] added check in creating/deleting with attributes --- storage/integration_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/integration_test.go b/storage/integration_test.go index 77312fa4fe5..beb667fe9ab 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -334,6 +334,9 @@ func TestIntegration_BucketMethods(t *testing.T) { if attrs.LocationType == "" { t.Error("got an empty LocationType") } + if attrs.ProjectNumber == 0 { + t.Errorf("got a zero ProjectNumber") + } h.mustDeleteBucket(b) }