* Bucket Get CORS - Get bucket cors configuration * @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)
| 17 | * @return {undefined} |
| 18 | */ |
| 19 | function bucketGetCors(authInfo, request, log, callback) { |
| 20 | const bucketName = request.bucketName; |
| 21 | const metadataValParams = { |
| 22 | authInfo, |
| 23 | bucketName, |
| 24 | requestType: REQUEST_TYPE, |
| 25 | request, |
| 26 | }; |
| 27 | |
| 28 | return standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => { |
| 29 | const corsHeaders = collectCorsHeaders(request.headers.origin, request.method, bucket); |
| 30 | if (err) { |
| 31 | monitoring.promMetrics('GET', bucketName, err.code, METRICS_ACTION); |
| 32 | return callback(err, null, corsHeaders); |
| 33 | } |
| 34 | |
| 35 | const cors = bucket.getCors(); |
| 36 | if (!cors) { |
| 37 | log.debug('cors configuration does not exist', { method: REQUEST_TYPE }); |
| 38 | monitoring.promMetrics('GET', bucketName, 404, METRICS_ACTION); |
| 39 | return callback(errors.NoSuchCORSConfiguration, null, corsHeaders); |
| 40 | } |
| 41 | log.trace('converting cors configuration to xml'); |
| 42 | const xml = convertToXml(cors); |
| 43 | |
| 44 | pushMetric(METRICS_ACTION, log, { authInfo, bucket: bucketName }); |
| 45 | monitoring.promMetrics('GET', bucketName, '200', METRICS_ACTION); |
| 46 | return callback(null, xml, corsHeaders); |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | module.exports = bucketGetCors; |
no test coverage detected