Skip to content

Commit

Permalink
Merge pull request #8763 from alphaprinz/notif_backports
Browse files Browse the repository at this point in the history
Notif backports
  • Loading branch information
nimrod-becker authored Feb 5, 2025
2 parents 1521003 + 8f672bc commit 5642958
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
51 changes: 16 additions & 35 deletions src/endpoint/s3/ops/s3_get_bucket_notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,25 @@ const _ = require('lodash');
*/
async function get_bucket_notification(req) {

let result = await req.object_sdk.get_bucket_notification({
const result = await req.object_sdk.get_bucket_notification({
bucket_name: req.params.bucket,
});

result = _.cloneDeep(result);

const TopicConfiguration = [];

//adapt to aws cli structure
if (result && result.length > 0) {
for (const conf of result) {
conf.Event = conf.event;
conf.Topic = conf.topic;
conf.Id = conf.id;
delete conf.event;
delete conf.topic;
delete conf.id;

TopicConfiguration.push({TopicConfiguration: conf});
}
}

if (result && result.length > 0) {
for (const conf of result) {
TopicConfiguration.push({TopicConfiguration: conf});
}
}

const reply = result && result.length > 0 ?
{
//return result inside TopicConfiguration tag
NotificationConfiguration:
TopicConfiguration
} :
//if there's no notification, return empty NotificationConfiguration tag
{ NotificationConfiguration: {} };

return reply;
//adapt to structure that xml_utils.encode_xml() will then
//encode into aws compliant reply
return {
NotificationConfiguration: [_.map(result, t => ({
TopicConfiguration: [
{
Id: t.id,
Topic: t.topic,
},
_.map(t.event, e => ({
Event: e
}))
]
}))]
};
}

module.exports = {
Expand Down
13 changes: 12 additions & 1 deletion src/endpoint/s3/ops/s3_put_bucket_notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ async function put_bucket_notification(req) {
//if test notification fails, fail the put op
const err = await notif_util.test_notifications(topic_configuration,
req.object_sdk.nsfs_config_root);

if (err) {
let message = "Test notification failed: " + (err.message || err.code);
//if there's an aggregated error, it will probably have more details in its message
if (err.name === 'AggregateError' && err.errors && err.errors[0]) {
const aggregated = err.errors[0];
message += "," + aggregated.message;
}
//for some reason in scale we are not allowed to show the config directory name in user's output
if (req.object_sdk.nsfs_config_root) {
message = message.replaceAll(req.object_sdk.nsfs_config_root, "");
}
throw new S3Error({
code: 'InvalidArgument',
message: JSON.stringify(err.message),
message,
http_code: 400,
detail: err.toString()
});
Expand Down
4 changes: 2 additions & 2 deletions src/util/notifications_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ async function test_notifications(notifs, nc_config_dir) {
connect = await notificator.parse_connect_file(notif.topic[0]);
connection = get_connection(connect);
await connection.connect();
await connection.promise_notify({notif: "test notification"}, async (notif_cb, err_cb) => {
await connection.promise_notify({notif: "test notification"}, async (notif_cb, err_cb, err) => {
failure = true;
notif_failure = err_cb;
notif_failure = err;
});
if (failure) {
if (notif_failure) {
Expand Down

0 comments on commit 5642958

Please sign in to comment.