-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathbucketGetNotification.js
More file actions
66 lines (62 loc) · 2.36 KB
/
bucketGetNotification.js
File metadata and controls
66 lines (62 loc) · 2.36 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
const { metadataValidateBucket } = require('../metadata/metadataUtils');
const { pushMetric } = require('../utapi/utilities');
const collectCorsHeaders = require('../utilities/collectCorsHeaders');
const { NotificationConfiguration } = require('arsenal').models;
/**
* Format of xml response:
*
* <NotificationConfiguration>
* <QueueConfiguration>
* <Event>array</Event>
* <Filter>
* <S3Key>
* <FilterRule>
* <Name>string</Name>
* <Value>string</Value>
* </FilterRule>
* </S3Key>
* </Filter>
* <Id>string</Id>
* <Queue>string</Queue>
* </QueueConfiguration>
* </NotificationConfiguration>
*/
/**
* bucketGetNotification - Return notification configuration for the bucket
* @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 respond to http request
* @return {undefined}
*/
function bucketGetNotification(authInfo, request, log, callback) {
log.debug('processing request', { method: 'bucketGetNotification' });
const { bucketName, headers, method } = request;
const metadataValParams = {
authInfo,
bucketName,
requestType: 'bucketGetNotification',
request,
};
return metadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => {
const corsHeaders = collectCorsHeaders(headers.origin, method, bucket);
if (err) {
log.debug('error processing request', {
error: err,
method: 'bucketGetNotification',
});
return callback(err, null, corsHeaders);
}
const bucketNotifConfig = bucket.getNotificationConfiguration();
const notifXml = NotificationConfiguration.getConfigXML(bucketNotifConfig);
// TODO: implement Utapi metric support
// bucketPolicy needs to be JSON stringified on return for proper
// parsing on return to caller function
pushMetric('getBucketNotification', log, {
authInfo,
bucket: bucketName,
});
return callback(null, notifXml, corsHeaders);
});
}
module.exports = bucketGetNotification;