-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathbucketGetLocation.js
More file actions
68 lines (58 loc) · 2.56 KB
/
bucketGetLocation.js
File metadata and controls
68 lines (58 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const { errors, s3middleware } = require('arsenal');
const bucketShield = require('./apiUtils/bucket/bucketShield');
const { isBucketAuthorized } =
require('./apiUtils/authorization/permissionChecks');
const metadata = require('../metadata/wrapper');
const { pushMetric } = require('../utapi/utilities');
const escapeForXml = s3middleware.escapeForXml;
const collectCorsHeaders = require('../utilities/collectCorsHeaders');
const requestType = 'bucketGetLocation';
/**
* 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 {undefined}
*/
function bucketGetLocation(authInfo, request, log, callback) {
const bucketName = request.bucketName;
const canonicalID = authInfo.getCanonicalID();
return metadata.getBucket(bucketName, log, (err, bucket) => {
if (err) {
log.debug('metadata getbucket failed', { error: err });
return callback(err);
}
if (bucketShield(bucket, requestType)) {
return callback(errors.NoSuchBucket);
}
log.trace('found bucket in metadata');
const corsHeaders = collectCorsHeaders(request.headers.origin,
request.method, bucket);
if (!isBucketAuthorized(bucket, requestType, canonicalID, authInfo,
request.actionImplicitDenies, log, request)) {
log.debug('access denied for account on bucket', {
requestType,
method: 'bucketGetLocation',
});
return callback(errors.AccessDenied, null, corsHeaders);
}
let locationConstraint = bucket.getLocationConstraint();
if (!locationConstraint || locationConstraint === 'us-east-1') {
// AWS returns empty string if no region has been
// provided or for us-east-1
// Note: AWS JS SDK sends a request with locationConstraint us-east-1
// if no locationConstraint provided.
locationConstraint = '';
}
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/">` +
`${escapeForXml(locationConstraint)}</LocationConstraint>`;
pushMetric('getBucketLocation', log, {
authInfo,
bucket: bucketName,
});
return callback(null, xml, corsHeaders);
});
}
module.exports = bucketGetLocation;