Skip to content

Commit c36719b

Browse files
authored
bucket notifications - adapt to xml conversion (#8745)
Signed-off-by: Amit Prinz Setter <alphaprinz@gmail.com>
1 parent 3fc59d6 commit c36719b

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

src/endpoint/s3/ops/s3_get_bucket_notification.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,25 @@ const _ = require('lodash');
88
*/
99
async function get_bucket_notification(req) {
1010

11-
let result = await req.object_sdk.get_bucket_notification({
11+
const result = await req.object_sdk.get_bucket_notification({
1212
bucket_name: req.params.bucket,
1313
});
1414

15-
result = _.cloneDeep(result);
16-
17-
const TopicConfiguration = [];
18-
19-
//adapt to aws cli structure
20-
if (result && result.length > 0) {
21-
for (const conf of result) {
22-
conf.Event = conf.event;
23-
conf.Topic = conf.topic;
24-
conf.Id = conf.id;
25-
delete conf.event;
26-
delete conf.topic;
27-
delete conf.id;
28-
29-
TopicConfiguration.push({TopicConfiguration: conf});
30-
}
31-
}
32-
33-
const reply = result && result.length > 0 ?
34-
{
35-
//return result inside TopicConfiguration tag
36-
NotificationConfiguration:
37-
TopicConfiguration
38-
} :
39-
//if there's no notification, return empty NotificationConfiguration tag
40-
{ NotificationConfiguration: {} };
41-
42-
return reply;
15+
//adapt to structure that xml_utils.encode_xml() will then
16+
//encode into aws compliant reply
17+
return {
18+
NotificationConfiguration: [_.map(result, t => ({
19+
TopicConfiguration: [
20+
{
21+
Id: t.id,
22+
Topic: t.topic,
23+
},
24+
_.map(t.event, e => ({
25+
Event: e
26+
}))
27+
]
28+
}))]
29+
};
4330
}
4431

4532
module.exports = {

0 commit comments

Comments
 (0)