Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(storage): add projectNumber field to bucketAttrs. (#4805)
* feat(storage): add projectNumber field to bucketAttrs.

* Added check to integration Test.

* Added check to integration Test.

* added check in creating/deleting with attributes

Co-authored-by: Brenna N Epp <brennae@google.com>
  • Loading branch information
anrajitha and BrennaEpp committed Sep 28, 2021
1 parent a0f768b commit 07343af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions storage/bucket.go
Expand Up @@ -337,6 +337,10 @@ 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.
// This field is read-only.
ProjectNumber uint64
}

// BucketPolicyOnly is an alias for UniformBucketLevelAccess.
Expand Down Expand Up @@ -597,6 +601,7 @@ func newBucket(b *raw.Bucket) (*BucketAttrs, error) {
PublicAccessPrevention: toPublicAccessPrevention(b.IamConfiguration),
Etag: b.Etag,
LocationType: b.LocationType,
ProjectNumber: b.ProjectNumber,
}, nil
}

Expand Down
10 changes: 6 additions & 4 deletions storage/bucket_test.go
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions storage/integration_test.go
Expand Up @@ -265,6 +265,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)

// Test Create and Delete with attributes.
Expand Down Expand Up @@ -331,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)
}

Expand Down

0 comments on commit 07343af

Please sign in to comment.