Skip to content

Commit 594e9d6

Browse files
committed
CLDSRV-754: add GetBucketLogging and PutBucketLogging endpoints
1 parent 990a9b1 commit 594e9d6

File tree

5 files changed

+687
-0
lines changed

5 files changed

+687
-0
lines changed

lib/api/api.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ const { tagConditionKeyAuth } = require('./apiUtils/authorization/tagConditionKe
7575
const { isRequesterASessionUser } = require('./apiUtils/authorization/permissionChecks');
7676
const checkHttpHeadersSize = require('./apiUtils/object/checkHttpHeadersSize');
7777
const { validateMethodChecksumNoChunking } = require('./apiUtils/integrity/validateChecksums');
78+
const bucketPutLogging = require('./bucketPutLogging');
79+
const bucketGetLogging = require('./bucketGetLogging');
7880

7981
const monitoringMap = policies.actionMaps.actionMonitoringMapS3;
8082

@@ -380,6 +382,8 @@ const api = {
380382
serviceGet,
381383
websiteGet: website,
382384
websiteHead: website,
385+
bucketPutLogging,
386+
bucketGetLogging,
383387
};
384388

385389
module.exports = api;

lib/api/bucketGetLogging.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils');
2+
const { checkExpectedBucketOwner } = require('./apiUtils/authorization/bucketOwner');
3+
const monitoring = require('../utilities/monitoringHandler');
4+
const { waterfall } = require('async');
5+
6+
const BucketLoggingStatusNotFoundBody = '<?xml version="1.0" encoding="UTF-8"?>\n' +
7+
'<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01" />';
8+
9+
function bucketGetLogging(authInfo, request, log, callback) {
10+
log.debug('processing request', { method: 'bucketGetLogging' });
11+
12+
const bucketName = request.bucketName;
13+
const metadataValParams = {
14+
authInfo,
15+
bucketName,
16+
requestType: request.apiMethods || 'bucketGetLogging',
17+
request,
18+
};
19+
20+
return waterfall([
21+
next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => {
22+
if (err) {
23+
return next(err);
24+
}
25+
26+
return next(null, bucket);
27+
}),
28+
(bucket, next) => checkExpectedBucketOwner(request.headers, bucket, log, err => {
29+
if (err) {
30+
return next(err);
31+
}
32+
33+
return next(null, bucket);
34+
}),
35+
(bucket, next) => {
36+
const bucketLoggingStatus = bucket.getBucketLoggingStatus();
37+
if (!bucketLoggingStatus) {
38+
return next(null, BucketLoggingStatusNotFoundBody);
39+
}
40+
41+
return next(null, bucketLoggingStatus.toXML());
42+
}
43+
], (err, body) => {
44+
if (err) {
45+
log.trace('error processing request', { error: err, method: 'bucketGetLogging' });
46+
monitoring.promMetrics('GET', bucketName, err.code, 'bucketGetLogging');
47+
return callback(err);
48+
}
49+
50+
monitoring.promMetrics('GET', bucketName, '200', 'bucketGetLogging');
51+
return callback(null, body);
52+
});
53+
}
54+
55+
module.exports = bucketGetLogging;

lib/api/bucketPutLogging.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const { waterfall } = require('async');
2+
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils');
3+
const { checkExpectedBucketOwner } = require('./apiUtils/authorization/bucketOwner');
4+
const BucketLoggingStatus = require('arsenal').models.BucketLoggingStatus;
5+
const metadata = require('../metadata/wrapper');
6+
const monitoring = require('../utilities/monitoringHandler');
7+
8+
function bucketPutLogging(authInfo, request, log, callback) {
9+
log.debug('processing request', { method: 'bucketPutLogging' });
10+
11+
const bucketName = request.bucketName;
12+
const parsed = BucketLoggingStatus.fromXML(request.post);
13+
if (parsed.error) {
14+
log.trace('error processing request', { error: parsed.error, method: 'bucketPutLogging' });
15+
monitoring.promMetrics('PUT', bucketName, parsed.error.arsenalError, 'bucketPutLogging');
16+
return callback(parsed.error.arsenalError);
17+
}
18+
19+
const metadataValParams = {
20+
authInfo,
21+
bucketName,
22+
requestType: request.apiMethods || 'bucketPutLogging',
23+
request,
24+
};
25+
26+
return waterfall([
27+
next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => {
28+
if (err) {
29+
return next(err);
30+
}
31+
32+
return next(null, bucket);
33+
}),
34+
(bucket, next) => checkExpectedBucketOwner(request.headers, bucket, log, err => {
35+
if (err) {
36+
return next(err);
37+
}
38+
39+
return next(null, bucket);
40+
}),
41+
(bucket, next) => {
42+
bucket.setBucketLoggingStatus(parsed.res);
43+
return metadata.updateBucket(bucket.getName(), bucket, log, err => {
44+
if (err) {
45+
return next(err);
46+
}
47+
48+
return next();
49+
});
50+
},
51+
], err => {
52+
if (err) {
53+
log.trace('error processing request', { error: err, method: 'bucketPutLogging' });
54+
monitoring.promMetrics('PUT', bucketName, err.code, 'bucketPutLogging');
55+
return callback(err);
56+
}
57+
58+
monitoring.promMetrics('PUT', bucketName, '200', 'bucketPutLogging');
59+
return callback();
60+
});
61+
}
62+
63+
module.exports = bucketPutLogging;

0 commit comments

Comments
 (0)