Skip to content

Commit 391fe76

Browse files
committed
bucket notifications - facilitate notif conf to override connection
Signed-off-by: Amit Prinz Setter <[email protected]>
1 parent af53218 commit 391fe76

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/test/unit_tests/test_notifications.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const http_connect_path = path.join(tmp_connect, http_connect_filename);
3636
//content of connect file, will be written to a file in before()
3737
const http_connect = {
3838
agent_request_object: {"host": "localhost", "port": 9998, "timeout": 1500},
39-
request_options_object: {"auth": "amit:passw", "timeout": 1500},
39+
request_options_object: {"auth": "amit:passw", "timeout": 1500, "path": "/default"},
4040
notification_protocol: 'http',
4141
name: 'http_notif'
4242
};
@@ -54,6 +54,7 @@ let expected_bucket;
5454
let expected_event_name;
5555
let expected_key;
5656
let expected_eTag;
57+
let expected_url;
5758

5859
// eslint-disable-next-line max-lines-per-function
5960
mocha.describe('notifications', function() {
@@ -91,6 +92,7 @@ mocha.describe('notifications', function() {
9192
const notif = JSON.parse(input.toString());
9293

9394
if (notif !== "test notification") {
95+
assert.strictEqual(req.url, expected_url);
9496
assert.strictEqual(notif.Records[0].s3.bucket.name, expected_bucket, 'wrong bucket name in notification');
9597
assert.strictEqual(notif.Records[0].eventName, expected_event_name, 'wrong event name in notification');
9698
assert.strictEqual(notif.Records[0].s3.object.key, expected_key, 'wrong key in notification');
@@ -224,18 +226,47 @@ mocha.describe('notifications', function() {
224226
});
225227
});
226228

229+
mocha.it('override connection', async () => {
230+
await s3.putBucketNotificationConfiguration({
231+
Bucket: bucket,
232+
NotificationConfiguration: {
233+
TopicConfigurations: [{
234+
"Id": "system_test_http_no_event_override",
235+
"TopicArn": http_connect_filename + "?" + JSON.stringify({
236+
request_options_object: {path: "/override"}
237+
}),
238+
}],
239+
},
240+
});
241+
242+
const res = await s3.putObject({
243+
Bucket: bucket,
244+
Key: 'f1',
245+
Body: 'this is the body',
246+
});
247+
248+
await notify_await_result({
249+
bucket_name: bucket,
250+
event_name: 'ObjectCreated:Put',
251+
key: "f1",
252+
etag: res.ETag,
253+
path: "/override"
254+
});
255+
});
256+
227257
});
228258

229259
});
230260

231261
const step_wait = 100;
232-
async function notify_await_result({bucket_name, event_name, etag, key, timeout = undefined}) {
262+
async function notify_await_result({bucket_name, event_name, etag, key, url = "/default", timeout = undefined}) {
233263

234264
//remember expected result here so server could compare it to actual result later
235265
expected_bucket = bucket_name;
236266
expected_event_name = event_name;
237267
expected_eTag = etag;
238268
expected_key = key;
269+
expected_url = url;
239270
server_done = false;
240271

241272
//busy-sync wait for server

src/util/notifications_util.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,24 @@ class Notificator {
186186
}
187187
}
188188

189-
async parse_connect_file(connect_filename, decrypt = false) {
189+
async parse_connect_file(connect_filename_with_overrides, decrypt = false) {
190190
let connect;
191+
const filename_parts = connect_filename_with_overrides.split('?');
192+
const connect_filename_no_overrides = filename_parts[0];
193+
const overrides_str = filename_parts[1];
194+
191195
if (this.nc_config_fs) {
192-
connect = await this.nc_config_fs.get_connection_by_name(connect_filename);
196+
connect = await this.nc_config_fs.get_connection_by_name(connect_filename_no_overrides);
193197
} else {
194-
const filepath = path.join(this.connect_files_dir, connect_filename);
198+
const filepath = path.join(this.connect_files_dir, connect_filename_no_overrides);
195199
const connect_str = fs.readFileSync(filepath, 'utf-8');
196200
connect = JSON.parse(connect_str);
197201
}
202+
if (overrides_str) {
203+
const overrides_obj = JSON.parse(overrides_str);
204+
_.merge(connect, overrides_obj);
205+
dbg.log2("effective connect =", connect);
206+
}
198207

199208
//if connect file is encrypted (and decryption is requested),
200209
//decrypt the auth field

0 commit comments

Comments
 (0)