-
Notifications
You must be signed in to change notification settings - Fork 246
Improvement/cldsrv 516 setup bucket apis for quotas #5552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bert-e
merged 7 commits into
development/8.8
from
improvement/CLDSRV-516-setup-bucket-apis-for-quotas
May 3, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fd7faa
CLDSRV-516: bump arsenal version
benzekrimaha f244118
CLDSRV-516: introduce quota APIs in router
benzekrimaha d2a31dc
CLDSRV-516: specify the signature version of old auth tests
benzekrimaha 63e502d
CLDSRV-516: implement UpdateBucketQuota API
benzekrimaha 1e03d53
CLDSRV-516: implement BucketGetQuota API
benzekrimaha b4fa81e
CLDSRV-516: implement BucketDeleteQuota API
benzekrimaha b369a47
CLDSRV-516: add tests
benzekrimaha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const { waterfall } = require('async'); | ||
const collectCorsHeaders = require('../utilities/collectCorsHeaders'); | ||
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils'); | ||
const metadata = require('../metadata/wrapper'); | ||
const { pushMetric } = require('../utapi/utilities'); | ||
const monitoring = require('../utilities/monitoringHandler'); | ||
|
||
const requestType = 'bucketDeleteQuota'; | ||
|
||
/** | ||
* Bucket Update Quota - Update bucket quota | ||
* @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info | ||
* @param {object} request - http request object | ||
* @param {object} log - Werelogs logger | ||
* @param {function} callback - callback to server | ||
* @return {undefined} | ||
*/ | ||
function bucketDeleteQuota(authInfo, request, log, callback) { | ||
log.debug('processing request', { method: 'bucketDeleteQuota' }); | ||
|
||
const { bucketName } = request; | ||
const metadataValParams = { | ||
authInfo, | ||
bucketName, | ||
requestType: request.apiMethods || requestType, | ||
request, | ||
}; | ||
return waterfall([ | ||
next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, | ||
(err, bucket) => next(err, bucket)), | ||
(bucket, next) => { | ||
bucket.setQuota(0); | ||
metadata.updateBucket(bucket.getName(), bucket, log, err => | ||
next(err, bucket)); | ||
}, | ||
], (err, bucket) => { | ||
const corsHeaders = collectCorsHeaders(request.headers.origin, | ||
request.method, bucket); | ||
if (err) { | ||
log.debug('error processing request', { | ||
error: err, | ||
method: 'bucketDeleteQuota' | ||
}); | ||
monitoring.promMetrics('DELETE', bucketName, err.code, | ||
'bucketDeleteQuota'); | ||
return callback(err, err.code, corsHeaders); | ||
} | ||
monitoring.promMetrics( | ||
'DELETE', bucketName, '204', 'bucketDeleteQuota'); | ||
pushMetric('bucketDeleteQuota', log, { | ||
authInfo, | ||
bucket: bucketName, | ||
}); | ||
return callback(null, 204, corsHeaders); | ||
}); | ||
} | ||
|
||
module.exports = bucketDeleteQuota; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const { errors } = require('arsenal'); | ||
const { pushMetric } = require('../utapi/utilities'); | ||
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils'); | ||
const collectCorsHeaders = require('../utilities/collectCorsHeaders'); | ||
|
||
/** | ||
* bucketGetQuota - Get the bucket quota | ||
* @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info | ||
* @param {object} request - http request object | ||
* @param {object} log - Werelogs logger | ||
* @param {function} callback - callback to server | ||
* @return {undefined} | ||
*/ | ||
function bucketGetQuota(authInfo, request, log, callback) { | ||
log.debug('processing request', { method: 'bucketGetQuota' }); | ||
const { bucketName, headers, method } = request; | ||
const metadataValParams = { | ||
authInfo, | ||
bucketName, | ||
requestType: request.apiMethods || 'bucketGetQuota', | ||
request, | ||
}; | ||
const xml = []; | ||
|
||
return standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => { | ||
const corsHeaders = collectCorsHeaders(headers.origin, method, bucket); | ||
if (err) { | ||
log.debug('error processing request', { | ||
error: err, | ||
method: 'bucketGetQuota', | ||
}); | ||
return callback(err, null, corsHeaders); | ||
} | ||
xml.push( | ||
'<?xml version="1.0" encoding="UTF-8"?>', | ||
'<GetBucketQuota>', | ||
'<Name>', bucket.getName(), '</Name>', | ||
); | ||
const bucketQuota = bucket.getQuota(); | ||
if (!bucketQuota) { | ||
log.debug('bucket has no quota', { | ||
method: 'bucketGetQuota', | ||
}); | ||
return callback(errors.NoSuchQuota, null, | ||
corsHeaders); | ||
} | ||
xml.push('<Quota>', bucketQuota, '</Quota>', | ||
'</GetBucketQuota>'); | ||
|
||
pushMetric('getBucketQuota', log, { | ||
authInfo, | ||
bucket: bucketName, | ||
}); | ||
return callback(null, xml.join(''), corsHeaders); | ||
}); | ||
} | ||
|
||
module.exports = bucketGetQuota; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const { waterfall } = require('async'); | ||
const { errors } = require('arsenal'); | ||
const collectCorsHeaders = require('../utilities/collectCorsHeaders'); | ||
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils'); | ||
const metadata = require('../metadata/wrapper'); | ||
const { pushMetric } = require('../utapi/utilities'); | ||
const monitoring = require('../utilities/monitoringHandler'); | ||
const { parseString } = require('xml2js'); | ||
|
||
function validateBucketQuotaProperty(requestBody, next) { | ||
const quota = requestBody.quota; | ||
const quotaValue = parseInt(quota, 10); | ||
if (Number.isNaN(quotaValue)) { | ||
return next(errors.InvalidArgument.customizeDescription('Quota Value should be a number')); | ||
} | ||
if (quotaValue <= 0) { | ||
return next(errors.InvalidArgument.customizeDescription('Quota value must be a positive number')); | ||
} | ||
return next(null, quotaValue); | ||
} | ||
|
||
function parseRequestBody(requestBody, next) { | ||
try { | ||
const jsonData = JSON.parse(requestBody); | ||
if (typeof jsonData !== 'object') { | ||
throw new Error('Invalid JSON'); | ||
} | ||
return next(null, jsonData); | ||
} catch (jsonError) { | ||
return parseString(requestBody, (xmlError, xmlData) => { | ||
if (xmlError) { | ||
return next(errors.InvalidArgument.customizeDescription('Request body must be a JSON object')); | ||
} | ||
return next(null, xmlData); | ||
}); | ||
} | ||
} | ||
|
||
function bucketUpdateQuota(authInfo, request, log, callback) { | ||
log.debug('processing request', { method: 'bucketUpdateQuota' }); | ||
|
||
const { bucketName } = request; | ||
const metadataValParams = { | ||
authInfo, | ||
bucketName, | ||
requestType: request.apiMethods || 'bucketUpdateQuota', | ||
request, | ||
}; | ||
let bucket = null; | ||
williamlardier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return waterfall([ | ||
next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, | ||
(err, b) => { | ||
bucket = b; | ||
return next(err, bucket); | ||
}), | ||
(bucket, next) => parseRequestBody(request.post, (err, requestBody) => next(err, bucket, requestBody)), | ||
(bucket, requestBody, next) => validateBucketQuotaProperty(requestBody, (err, quotaValue) => | ||
next(err, bucket, quotaValue)), | ||
(bucket, quotaValue, next) => { | ||
bucket.setQuota(quotaValue); | ||
return metadata.updateBucket(bucket.getName(), bucket, log, next); | ||
}, | ||
], (err, bucket) => { | ||
const corsHeaders = collectCorsHeaders(request.headers.origin, | ||
request.method, bucket); | ||
if (err) { | ||
log.debug('error processing request', { | ||
error: err, | ||
method: 'bucketUpdateQuota' | ||
}); | ||
monitoring.promMetrics('PUT', bucketName, err.code, | ||
'updateBucketQuota'); | ||
return callback(err, err.code, corsHeaders); | ||
} | ||
monitoring.promMetrics( | ||
'PUT', bucketName, '200', 'updateBucketQuota'); | ||
pushMetric('updateBucketQuota', log, { | ||
authInfo, | ||
bucket: bucketName, | ||
}); | ||
return callback(null, corsHeaders); | ||
}); | ||
} | ||
|
||
module.exports = bucketUpdateQuota; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/functional/aws-node-sdk/test/bucket/deleteBucketQuota.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const AWS = require('aws-sdk'); | ||
const S3 = AWS.S3; | ||
const assert = require('assert'); | ||
const getConfig = require('../support/config'); | ||
const sendRequest = require('../quota/tooling').sendRequest; | ||
|
||
const bucket = 'deletequotatestbucket'; | ||
const nonExistantBucket = 'deletequotatestnonexistantbucket'; | ||
|
||
describe('Test delete bucket quota', () => { | ||
let s3; | ||
|
||
before(() => { | ||
const config = getConfig('default', { signatureVersion: 'v4' }); | ||
s3 = new S3(config); | ||
AWS.config.update(config); | ||
}); | ||
|
||
beforeEach(done => s3.createBucket({ Bucket: bucket }, done)); | ||
|
||
afterEach(done => s3.deleteBucket({ Bucket: bucket }, done)); | ||
|
||
it('should delete the bucket quota', async () => { | ||
try { | ||
await sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`); | ||
assert.ok(true); | ||
} catch (err) { | ||
assert.fail(`Expected no error, but got ${err}`); | ||
} | ||
}); | ||
|
||
it('should return no such bucket error', async () => { | ||
try { | ||
await sendRequest('DELETE', '127.0.0.1:8000', `/${nonExistantBucket}/?quota=true`); | ||
} catch (err) { | ||
assert.strictEqual(err.Error.Code[0], 'NoSuchBucket'); | ||
williamlardier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
tests/functional/aws-node-sdk/test/bucket/getBucketQuota.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const AWS = require('aws-sdk'); | ||
const S3 = AWS.S3; | ||
const assert = require('assert'); | ||
const getConfig = require('../support/config'); | ||
const sendRequest = require('../quota/tooling').sendRequest; | ||
|
||
const bucket = 'getquotatestbucket'; | ||
const quota = { quota: 1000 }; | ||
|
||
describe('Test get bucket quota', () => { | ||
let s3; | ||
|
||
before(() => { | ||
const config = getConfig('default', { signatureVersion: 'v4' }); | ||
s3 = new S3(config); | ||
AWS.config.update(config); | ||
}); | ||
|
||
beforeEach(done => s3.createBucket({ Bucket: bucket }, done)); | ||
|
||
afterEach(done => s3.deleteBucket({ Bucket: bucket }, done)); | ||
|
||
it('should return the quota', async () => { | ||
try { | ||
await sendRequest('PUT', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(quota)); | ||
const data = await sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`); | ||
assert.strictEqual(data.GetBucketQuota.Name[0], bucket); | ||
assert.strictEqual(data.GetBucketQuota.Quota[0], '1000'); | ||
} catch (err) { | ||
assert.fail(`Expected no error, but got ${err}`); | ||
} | ||
}); | ||
|
||
it('should return no such bucket error', async () => { | ||
try { | ||
await sendRequest('GET', '127.0.0.1:8000', '/test/?quota=true'); | ||
} catch (err) { | ||
assert.strictEqual(err.Error.Code[0], 'NoSuchBucket'); | ||
} | ||
}); | ||
|
||
it('should return no such bucket quota', async () => { | ||
try { | ||
await sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`); | ||
try { | ||
await sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`); | ||
assert.fail('Expected NoSuchQuota error'); | ||
} catch (err) { | ||
assert.strictEqual(err.Error.Code[0], 'NoSuchQuota'); | ||
} | ||
} catch (err) { | ||
assert.fail(`Expected no error, but got ${err}`); | ||
} | ||
}); | ||
|
||
it('should return no such bucket error', async () => { | ||
try { | ||
await sendRequest('GET', '127.0.0.1:8000', '/test/?quota=true'); | ||
} catch (err) { | ||
assert.strictEqual(err.Error.Code[0], 'NoSuchBucket'); | ||
} | ||
}); | ||
|
||
it('should return no such bucket quota', async () => { | ||
try { | ||
await sendRequest('DELETE', '127.0.0.1:8000', `/${bucket}/?quota=true`); | ||
try { | ||
await sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`); | ||
assert.fail('Expected NoSuchQuota error'); | ||
} catch (err) { | ||
assert.strictEqual(err.Error.Code[0], 'NoSuchQuota'); | ||
} | ||
} catch (err) { | ||
assert.fail(`Expected no error, but got ${err}`); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.