Skip to content

Commit 4e5726f

Browse files
authored
feat: add ability to enable hierarchical namespace on buckets (#2453)
* feat: add ability to enable hierarchical namespace on buckets * specify uniform bucket level access in hierarchical namespace test * remove describe.only
1 parent c267e6b commit 4e5726f

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

src/bucket.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ export interface BucketMetadata extends BaseMetadata {
308308
encryption?: {
309309
defaultKmsKeyName?: string;
310310
} | null;
311+
hierarchicalNamespace?: {
312+
enabled?: boolean;
313+
};
311314
iamConfiguration?: {
312315
publicAccessPrevention?: string;
313316
uniformBucketLevelAccess?: {

src/storage.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ export interface CreateBucketRequest {
124124
customPlacementConfig?: CustomPlacementConfig;
125125
dra?: boolean;
126126
enableObjectRetention?: boolean;
127+
hierarchicalNamespace?: {
128+
enabled?: boolean;
129+
};
130+
iamConfiguration?: {
131+
publicAccessPrevention?: string;
132+
uniformBucketLevelAccess?: {
133+
enabled?: boolean;
134+
lockedTime?: string;
135+
};
136+
};
127137
location?: string;
128138
multiRegional?: boolean;
129139
nearline?: boolean;
@@ -868,6 +878,7 @@ export class Storage extends Service {
868878
* @property {boolean} [dra=false] Specify the storage class as Durable Reduced
869879
* Availability.
870880
* @property {boolean} [enableObjectRetention=false] Specifiy whether or not object retention should be enabled on this bucket.
881+
* @property {object} [hierarchicalNamespace.enabled=false] Specify whether or not to enable hierarchical namespace on this bucket.
871882
* @property {string} [location] Specify the bucket's location. If specifying
872883
* a dual-region, the `customPlacementConfig` property should be set in conjunction.
873884
* For more information, see {@link https://cloud.google.com/storage/docs/locations| Bucket Locations}.

system-test/storage.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,50 @@ describe('storage', function () {
15121512
});
15131513
});
15141514

1515+
describe('bucket hierarchical namespace', async () => {
1516+
let bucket: Bucket;
1517+
1518+
beforeEach(() => {
1519+
bucket = storage.bucket(generateName());
1520+
});
1521+
1522+
afterEach(async () => {
1523+
try {
1524+
await bucket.delete();
1525+
} catch {
1526+
//Ignore errors
1527+
}
1528+
});
1529+
1530+
it('should create a bucket without hierarchical namespace enabled (implicit)', async () => {
1531+
await storage.createBucket(bucket.name);
1532+
const [metadata] = await bucket.getMetadata();
1533+
assert.strictEqual(metadata.hierarchicalNamespace, undefined);
1534+
});
1535+
1536+
it('should create a bucket without hierarchical namespace enabled (explicit)', async () => {
1537+
await storage.createBucket(bucket.name, {
1538+
hierarchicalNamespace: {enabled: false},
1539+
});
1540+
const [metadata] = await bucket.getMetadata();
1541+
assert.strictEqual(metadata.hierarchicalNamespace, undefined);
1542+
});
1543+
1544+
it('should create a bucket with hierarchical namespace enabled', async () => {
1545+
await storage.createBucket(bucket.name, {
1546+
hierarchicalNamespace: {enabled: true},
1547+
iamConfiguration: {
1548+
uniformBucketLevelAccess: {
1549+
enabled: true,
1550+
},
1551+
},
1552+
});
1553+
const [metadata] = await bucket.getMetadata();
1554+
assert(metadata.hierarchicalNamespace);
1555+
assert.strictEqual(metadata.hierarchicalNamespace.enabled, true);
1556+
});
1557+
});
1558+
15151559
describe('bucket retention policies', () => {
15161560
describe('bucket', () => {
15171561
it('should create a bucket with a retention policy', async () => {

test/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,21 @@ describe('Storage', () => {
923923
storage.createBucket(BUCKET_NAME, {enableObjectRetention: true}, done);
924924
});
925925

926+
it('should allow enabling hierarchical namespace', done => {
927+
storage.request = (
928+
reqOpts: DecorateRequestOptions,
929+
callback: Function
930+
) => {
931+
assert.strictEqual(reqOpts.json.hierarchicalNamespace.enabled, true);
932+
callback();
933+
};
934+
storage.createBucket(
935+
BUCKET_NAME,
936+
{hierarchicalNamespace: {enabled: true}},
937+
done
938+
);
939+
});
940+
926941
describe('storage classes', () => {
927942
it('should expand metadata.archive', done => {
928943
storage.request = (reqOpts: DecorateRequestOptions) => {

0 commit comments

Comments
 (0)