From cad8b14df169c5d26e90fe33f43e01bcb506e8e8 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Tue, 30 Apr 2024 17:16:50 +0200 Subject: [PATCH 1/7] ARSN-410: update bucketInfo and md --- documentation/BucketInfoModelVersion.md | 14 ++++++++++- lib/models/BucketInfo.ts | 32 +++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/documentation/BucketInfoModelVersion.md b/documentation/BucketInfoModelVersion.md index 356b0ebe3..ed0dd61fe 100644 --- a/documentation/BucketInfoModelVersion.md +++ b/documentation/BucketInfoModelVersion.md @@ -245,4 +245,16 @@ For capacity-enabled buckets, contains the following data: ### Usage -Used to store bucket tagging \ No newline at end of file +Used to store bucket tagging + +## Model version 17 + +### Properties Added + +```javascript +this._quotaMax = quotaMax || 0; +``` + +### Usage + +Used to store bucket quota \ No newline at end of file diff --git a/lib/models/BucketInfo.ts b/lib/models/BucketInfo.ts index bd33481cf..8ee81985e 100644 --- a/lib/models/BucketInfo.ts +++ b/lib/models/BucketInfo.ts @@ -101,6 +101,7 @@ export default class BucketInfo { _azureInfo: any | null; _ingestion: { status: 'enabled' | 'disabled' } | null; _capabilities?: Capabilities; + _quotaMax: number | 0; /** * Represents all bucket information. @@ -157,6 +158,7 @@ export default class BucketInfo { * @param [notificationConfiguration] - bucket notification configuration * @param [tags] - bucket tag set * @param [capabilities] - capabilities for the bucket + * @param quotaMax - bucket quota */ constructor( name: string, @@ -185,6 +187,7 @@ export default class BucketInfo { notificationConfiguration?: any, tags?: Array | [], capabilities?: Capabilities, + quotaMax?: number | 0, ) { assert.strictEqual(typeof name, 'string'); assert.strictEqual(typeof owner, 'string'); @@ -285,6 +288,10 @@ export default class BucketInfo { tags = [] as BucketTag[]; } assert.strictEqual(areTagsValid(tags), true); + if (quotaMax) { + assert.strictEqual(typeof quotaMax, 'number'); + assert(quotaMax >= 0, 'Quota cannot be negative'); + } // IF UPDATING PROPERTIES, INCREMENT MODELVERSION NUMBER ABOVE this._acl = aclInstance; @@ -313,6 +320,7 @@ export default class BucketInfo { this._notificationConfiguration = notificationConfiguration || null; this._tags = tags; this._capabilities = capabilities || undefined; + this._quotaMax = quotaMax || 0; return this; } @@ -348,6 +356,7 @@ export default class BucketInfo { notificationConfiguration: this._notificationConfiguration, tags: this._tags, capabilities: this._capabilities, + quotaMax: this._quotaMax, }; const final = this._websiteConfiguration ? { @@ -374,7 +383,7 @@ export default class BucketInfo { obj.bucketPolicy, obj.uid, obj.readLocationConstraint, obj.isNFS, obj.ingestion, obj.azureInfo, obj.objectLockEnabled, obj.objectLockConfiguration, obj.notificationConfiguration, obj.tags, - obj.capabilities); + obj.capabilities, obj.quotaMax); } /** @@ -401,7 +410,8 @@ export default class BucketInfo { data._bucketPolicy, data._uid, data._readLocationConstraint, data._isNFS, data._ingestion, data._azureInfo, data._objectLockEnabled, data._objectLockConfiguration, - data._notificationConfiguration, data._tags, data._capabilities); + data._notificationConfiguration, data._tags, data._capabilities, + data._quotaMax); } /** @@ -939,4 +949,22 @@ export default class BucketInfo { this._capabilities = capabilities; return this; } + + /** + * Get the bucket quota information + * @return quotaMax + */ + getQuota() { + return this._quotaMax; + } + + /** + * Set bucket quota + * @param quota - quota to be set + * @return - bucket quota info + */ + setQuota(quota: number) { + this._quotaMax = quota || 0; + return this; + } } From 0c53d134394fdb2e1815184c80ac1823149cbc02 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Tue, 30 Apr 2024 17:17:18 +0200 Subject: [PATCH 2/7] ARSN-410: update bucketInfo test --- tests/unit/models/BucketInfo.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/models/BucketInfo.spec.js b/tests/unit/models/BucketInfo.spec.js index bb314aff0..807b6ab4b 100644 --- a/tests/unit/models/BucketInfo.spec.js +++ b/tests/unit/models/BucketInfo.spec.js @@ -228,6 +228,8 @@ const testBucketCapabilities = { }, }; +const testBucketQuota = 100000; + // create a dummy bucket to test getters and setters Object.keys(acl).forEach( aclObj => describe(`different acl configurations : ${aclObj}`, () => { @@ -252,6 +254,7 @@ Object.keys(acl).forEach( testNotificationConfiguration, testBucketTagging, testBucketCapabilities, + testBucketQuota, ); describe('serialize/deSerialize on BucketInfo class', () => { @@ -290,6 +293,7 @@ Object.keys(acl).forEach( notificationConfiguration: dummyBucket._notificationConfiguration, tags: dummyBucket._tags, capabilities: dummyBucket._capabilities, + quotaMax: dummyBucket._quotaMax, }; assert.strictEqual(serialized, JSON.stringify(bucketInfos)); done(); @@ -339,6 +343,7 @@ Object.keys(acl).forEach( dummyBucket._notificationConfiguration, _tags: dummyBucket._tags, _capabilities: dummyBucket._capabilities, + _quotaMax: dummyBucket._quotaMax, }; const fromObj = BucketInfo.fromObj(dataObj); assert(fromObj instanceof BucketInfo); @@ -694,6 +699,17 @@ Object.keys(acl).forEach( assert.deepStrictEqual( dummyBucket.getCapabilities(), testCapabilities); }); + it('setQuota should set bucket quota', () => { + const testQuota = testBucketQuota; + dummyBucket.setQuota(testQuota); + assert.deepStrictEqual( + dummyBucket.getQuota(), testQuota); + }); + it('setQuota should set bucket quota', () => { + dummyBucket.setQuota(); + assert.deepStrictEqual( + dummyBucket.getQuota(), 0); + }); }); }), ); From 31a4de5372fe5bbdadcdc9ca69d09774c63ed5dd Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Tue, 30 Apr 2024 17:17:46 +0200 Subject: [PATCH 3/7] ARSN-410: add getbucketQuota in metaDataWrapper --- lib/storage/metadata/MetadataWrapper.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/storage/metadata/MetadataWrapper.js b/lib/storage/metadata/MetadataWrapper.js index b6942d7dc..446c0fd14 100644 --- a/lib/storage/metadata/MetadataWrapper.js +++ b/lib/storage/metadata/MetadataWrapper.js @@ -226,6 +226,19 @@ class MetadataWrapper { }); } + getBucketQuota(bucketName, log, cb) { + log.debug('getting bucket quota from metadata'); + this.client.getBucketAttributes(bucketName, log, (err, data) => { + if (err) { + log.debug('error from metadata', { implName: this.implName, + error: err }); + return cb(err); + } + const bucketInfo = BucketInfo.fromObj(data); + return cb(err, { quota: bucketInfo.getQuota() }); + }); + } + deleteBucket(bucketName, log, cb) { log.debug('deleting bucket from metadata'); this.client.deleteBucket(bucketName, log, err => { From 0475c8520acf805afac5905315fd113b7094abb4 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Tue, 30 Apr 2024 17:18:12 +0200 Subject: [PATCH 4/7] ARSN-410: update routes for bucket get/put/delete quota --- lib/s3routes/routes/routeDELETE.ts | 2 ++ lib/s3routes/routes/routeGET.ts | 2 ++ lib/s3routes/routes/routePUT.ts | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/lib/s3routes/routes/routeDELETE.ts b/lib/s3routes/routes/routeDELETE.ts index cd647cafd..f7370faf5 100644 --- a/lib/s3routes/routes/routeDELETE.ts +++ b/lib/s3routes/routes/routeDELETE.ts @@ -43,6 +43,8 @@ export default function routeDELETE( return call('bucketDeleteEncryption'); } else if (query?.tagging !== undefined) { return call('bucketDeleteTagging'); + } else if (query?.quota !== undefined) { + return call('bucketDeleteQuota'); } call('bucketDelete'); } else { diff --git a/lib/s3routes/routes/routeGET.ts b/lib/s3routes/routes/routeGET.ts index 9a93b385b..a166b6511 100644 --- a/lib/s3routes/routes/routeGET.ts +++ b/lib/s3routes/routes/routeGET.ts @@ -60,6 +60,8 @@ export default function routerGET( call('bucketGetEncryption'); } else if (query.search !== undefined) { call('metadataSearch') + } else if (query.quota !== undefined) { + call('bucketGetQuota'); } else { // GET bucket call('bucketGet'); diff --git a/lib/s3routes/routes/routePUT.ts b/lib/s3routes/routes/routePUT.ts index 3d3d6a410..ab62edd73 100644 --- a/lib/s3routes/routes/routePUT.ts +++ b/lib/s3routes/routes/routePUT.ts @@ -105,6 +105,13 @@ export default function routePUT( return routesUtils.responseNoBody(err, corsHeaders, response, 200, log); }); + } else if (query.quota !== undefined) { + api.callApiMethod('bucketUpdateQuota', request, response, + log, (err, resHeaders) => { + routesUtils.statsReport500(err, statsClient); + return routesUtils.responseNoBody(err, resHeaders, response, + 200, log); + }); } else { // PUT bucket return api.callApiMethod('bucketPut', request, response, log, From 1858654f344ccaa42d9da7977ee9b044508d9a08 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Tue, 30 Apr 2024 17:18:54 +0200 Subject: [PATCH 5/7] ARSN-410: new no such quota error --- lib/errors/arsenalErrors.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/errors/arsenalErrors.ts b/lib/errors/arsenalErrors.ts index 391191bf2..b514802ce 100644 --- a/lib/errors/arsenalErrors.ts +++ b/lib/errors/arsenalErrors.ts @@ -1042,3 +1042,10 @@ export const AuthMethodNotImplemented: ErrorFormat = { description: 'AuthMethodNotImplemented', code: 501, }; + +// --------------------- quotaErros --------------------- + +export const NoSuchQuota: ErrorFormat = { + code: 404, + description: 'The specified resource does not have a quota.', +}; From af07bb3df4687f02af6b120edf618d4a2a7b259f Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Tue, 30 Apr 2024 17:19:20 +0200 Subject: [PATCH 6/7] ARSN-410: adding api methods in actionMonitoringMapS3 --- lib/policyEvaluator/utils/actionMaps.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/policyEvaluator/utils/actionMaps.ts b/lib/policyEvaluator/utils/actionMaps.ts index 0b59fa34d..36977710d 100644 --- a/lib/policyEvaluator/utils/actionMaps.ts +++ b/lib/policyEvaluator/utils/actionMaps.ts @@ -158,6 +158,9 @@ const actionMonitoringMapS3 = { objectPutTagging: 'PutObjectTagging', objectRestore: 'RestoreObject', serviceGet: 'ListBuckets', + bucketGetQuota: 'GetBucketQuota', + bucketUpdateQuota: 'UpdateBucketQuota', + bucketDeleteQuota: 'DeleteBucketQuota', }; const actionMapAccountQuotas = { From c464a70b9056ce0e8cc6343f2af6ef7947c7cea4 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Tue, 30 Apr 2024 17:19:42 +0200 Subject: [PATCH 7/7] ARSN-410: bump project version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eab0a14d6..13cd85475 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "engines": { "node": ">=16" }, - "version": "8.1.128", + "version": "8.1.129", "description": "Common utilities for the S3 project components", "main": "build/index.js", "repository": {