* bucketGetRateLimit - Get the bucket rate limit config * @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}
(authInfo, request, log, callback)
| 13 | * @return {undefined} |
| 14 | */ |
| 15 | function bucketGetRateLimit(authInfo, request, log, callback) { |
| 16 | log.debug('processing request', { method: 'bucketGetRateLimit' }); |
| 17 | |
| 18 | if (!isRateLimitServiceUser(authInfo)) { |
| 19 | return callback(errors.AccessDenied); |
| 20 | } |
| 21 | |
| 22 | const { bucketName, headers, method } = request; |
| 23 | const metadataValParams = { |
| 24 | authInfo, |
| 25 | bucketName, |
| 26 | requestType: request.apiMethods || 'bucketGetRateLimit', |
| 27 | request, |
| 28 | }; |
| 29 | |
| 30 | return standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => { |
| 31 | const corsHeaders = collectCorsHeaders(headers.origin, method, bucket); |
| 32 | if (err) { |
| 33 | log.debug('error processing request', { |
| 34 | error: err, |
| 35 | method: 'bucketGetRateLimit', |
| 36 | }); |
| 37 | return callback(err, null, corsHeaders); |
| 38 | } |
| 39 | |
| 40 | const rateLimitConfig = bucket.getRateLimitConfiguration(); |
| 41 | if (!rateLimitConfig) { |
| 42 | log.debug('error processing request', { |
| 43 | error: errors.NoSuchRateLimitConfig, |
| 44 | method: 'bucketGetRateLimit', |
| 45 | }); |
| 46 | return callback(errors.NoSuchRateLimitConfig, null, |
| 47 | corsHeaders); |
| 48 | } |
| 49 | |
| 50 | return callback(null, JSON.stringify(rateLimitConfig.getData()), corsHeaders); |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | module.exports = bucketGetRateLimit; |
no test coverage detected