From 3f4667bea9422ddbf51fe6f41c1d3dbdcf7a12a5 Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Fri, 3 May 2024 14:44:57 +0000 Subject: [PATCH 1/3] feat: add ability to enable hierarchical namespace on buckets --- src/bucket.ts | 3 +++ src/storage.ts | 4 ++++ system-test/storage.ts | 40 ++++++++++++++++++++++++++++++++++++++++ test/index.ts | 15 +++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/src/bucket.ts b/src/bucket.ts index d4321e072..7ea33e957 100644 --- a/src/bucket.ts +++ b/src/bucket.ts @@ -308,6 +308,9 @@ export interface BucketMetadata extends BaseMetadata { encryption?: { defaultKmsKeyName?: string; } | null; + hierarchicalNamespace?: { + enabled?: boolean; + }; iamConfiguration?: { publicAccessPrevention?: string; uniformBucketLevelAccess?: { diff --git a/src/storage.ts b/src/storage.ts index f13c37acc..46868de61 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -124,6 +124,9 @@ export interface CreateBucketRequest { customPlacementConfig?: CustomPlacementConfig; dra?: boolean; enableObjectRetention?: boolean; + hierarchicalNamespace?: { + enabled?: boolean; + }; location?: string; multiRegional?: boolean; nearline?: boolean; @@ -868,6 +871,7 @@ export class Storage extends Service { * @property {boolean} [dra=false] Specify the storage class as Durable Reduced * Availability. * @property {boolean} [enableObjectRetention=false] Specifiy whether or not object retention should be enabled on this bucket. + * @property {object} [hierarchicalNamespace.enabled=false] Specify whether or not to enable hierarchical namespace on this bucket. * @property {string} [location] Specify the bucket's location. If specifying * a dual-region, the `customPlacementConfig` property should be set in conjunction. * For more information, see {@link https://cloud.google.com/storage/docs/locations| Bucket Locations}. diff --git a/system-test/storage.ts b/system-test/storage.ts index 5bee90e5e..fe19ecc64 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -1512,6 +1512,46 @@ describe('storage', function () { }); }); + describe.only('bucket hierarchical namespace', async () => { + let bucket: Bucket; + + beforeEach(() => { + bucket = storage.bucket(generateName()); + }); + + afterEach(async () => { + try { + await bucket.delete(); + } catch { + //Ignore errors + } + }); + + it('should create a bucket without hierarchical namespace enabled (implicit)', async () => { + await storage.createBucket(bucket.name); + const [metadata] = await bucket.getMetadata(); + assert.strictEqual(metadata.hierarchicalNamespace, undefined); + }); + + it('should create a bucket without hierarchical namespace enabled (explicit)', async () => { + await storage.createBucket(bucket.name, { + hierarchicalNamespace: {enabled: false}, + }); + const [metadata] = await bucket.getMetadata(); + assert(metadata.hierarchicalNamespace); + assert.strictEqual(metadata.hierarchicalNamespace.enabled, false); + }); + + it('should create a bucket with hierarchical namespace enabled', async () => { + await storage.createBucket(bucket.name, { + hierarchicalNamespace: {enabled: true}, + }); + const [metadata] = await bucket.getMetadata(); + assert(metadata.hierarchicalNamespace); + assert.strictEqual(metadata.hierarchicalNamespace.enabled, true); + }); + }); + describe('bucket retention policies', () => { describe('bucket', () => { it('should create a bucket with a retention policy', async () => { diff --git a/test/index.ts b/test/index.ts index e09814ad6..72637a466 100644 --- a/test/index.ts +++ b/test/index.ts @@ -923,6 +923,21 @@ describe('Storage', () => { storage.createBucket(BUCKET_NAME, {enableObjectRetention: true}, done); }); + it('should allow enabling hierarchical namespace', done => { + storage.request = ( + reqOpts: DecorateRequestOptions, + callback: Function + ) => { + assert.strictEqual(reqOpts.json.hierarchicalNamespace.enabled, true); + callback(); + }; + storage.createBucket( + BUCKET_NAME, + {hierarchicalNamespace: {enabled: true}}, + done + ); + }); + describe('storage classes', () => { it('should expand metadata.archive', done => { storage.request = (reqOpts: DecorateRequestOptions) => { From ab7572643360332659592c50ac39206dbf5fc0e7 Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Fri, 3 May 2024 14:59:58 +0000 Subject: [PATCH 2/3] specify uniform bucket level access in hierarchical namespace test --- src/storage.ts | 7 +++++++ system-test/storage.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/storage.ts b/src/storage.ts index 46868de61..a7027bc83 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -127,6 +127,13 @@ export interface CreateBucketRequest { hierarchicalNamespace?: { enabled?: boolean; }; + iamConfiguration?: { + publicAccessPrevention?: string; + uniformBucketLevelAccess?: { + enabled?: boolean; + lockedTime?: string; + }; + }; location?: string; multiRegional?: boolean; nearline?: boolean; diff --git a/system-test/storage.ts b/system-test/storage.ts index fe19ecc64..64140333d 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -1538,13 +1538,17 @@ describe('storage', function () { hierarchicalNamespace: {enabled: false}, }); const [metadata] = await bucket.getMetadata(); - assert(metadata.hierarchicalNamespace); - assert.strictEqual(metadata.hierarchicalNamespace.enabled, false); + assert.strictEqual(metadata.hierarchicalNamespace, undefined); }); it('should create a bucket with hierarchical namespace enabled', async () => { await storage.createBucket(bucket.name, { hierarchicalNamespace: {enabled: true}, + iamConfiguration: { + uniformBucketLevelAccess: { + enabled: true, + }, + }, }); const [metadata] = await bucket.getMetadata(); assert(metadata.hierarchicalNamespace); From aac327830850ffd8b7682d62b3c82be687ee5dfc Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Fri, 3 May 2024 15:04:56 +0000 Subject: [PATCH 3/3] remove describe.only --- system-test/storage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-test/storage.ts b/system-test/storage.ts index 64140333d..cd184f4bc 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -1512,7 +1512,7 @@ describe('storage', function () { }); }); - describe.only('bucket hierarchical namespace', async () => { + describe('bucket hierarchical namespace', async () => { let bucket: Bucket; beforeEach(() => {