-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLDSRV-516: implement BucketDeleteQuota API
- Loading branch information
1 parent
b3eebc7
commit 5145fce
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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; |