* Bucket Get Location - Get bucket locationConstraint 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
(authInfo, request, log, callback)
| 17 | * @return {undefined} |
| 18 | */ |
| 19 | function bucketGetLocation(authInfo, request, log, callback) { |
| 20 | const bucketName = request.bucketName; |
| 21 | const metadataValParams = { |
| 22 | authInfo, |
| 23 | bucketName, |
| 24 | requestType: request.apiMethod || 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 | let locationConstraint = bucket.getLocationConstraint(); |
| 36 | if (!locationConstraint || locationConstraint === 'us-east-1') { |
| 37 | // AWS returns empty string if no region has been |
| 38 | // provided or for us-east-1 |
| 39 | // Note: AWS JS SDK sends a request with locationConstraint us-east-1 |
| 40 | // if no locationConstraint provided. |
| 41 | locationConstraint = ''; |
| 42 | } |
| 43 | const xml = `<?xml version="1.0" encoding="UTF-8"?> |
| 44 | <LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/">` + |
| 45 | `${escapeForXml(locationConstraint)}</LocationConstraint>`; |
| 46 | pushMetric(METRICS_ACTION, log, { authInfo, bucket: bucketName }); |
| 47 | monitoring.promMetrics('GET', bucketName, '200', METRICS_ACTION); |
| 48 | return callback(null, xml, corsHeaders); |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | module.exports = bucketGetLocation; |
no test coverage detected