-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathgetNotificationConfiguration.js
More file actions
27 lines (24 loc) · 1.28 KB
/
getNotificationConfiguration.js
File metadata and controls
27 lines (24 loc) · 1.28 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
const { errorInstances, models } = require('arsenal');
const { NotificationConfiguration } = models;
const { config } = require('../../../Config');
function getNotificationConfiguration(parsedXml) {
const notifConfig = new NotificationConfiguration(parsedXml).getValidatedNotificationConfiguration();
// if notifConfig is empty object, effectively delete notification configuration
if (notifConfig.error || Object.keys(notifConfig).length === 0) {
return notifConfig;
}
if (!config.bucketNotificationDestinations) {
return { error: errorInstances.InvalidArgument.customizeDescription(
'Unable to validate the following destination configurations') };
}
const targets = new Set(config.bucketNotificationDestinations.map(t => t.resource));
const notifConfigTargets = notifConfig.queueConfig.map(t => t.queueArn.split(':')[5]);
if (!notifConfigTargets.every(t => targets.has(t))) {
// TODO: match the error message to AWS's response along with
// the request destination name in the response
const errDesc = 'Unable to validate the destination configuration';
return { error: errorInstances.InvalidArgument.customizeDescription(errDesc) };
}
return notifConfig;
}
module.exports = getNotificationConfiguration;