Skip to content

Commit 2dfcbfb

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

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
};
@@ -55,6 +55,7 @@ let expected_event_name;
5555
let expected_key;
5656
let expected_eTag;
5757
let expect_test;
58+
let expected_url;
5859

5960
// eslint-disable-next-line max-lines-per-function
6061
mocha.describe('notifications', function() {
@@ -95,6 +96,7 @@ mocha.describe('notifications', function() {
9596
assert.strictEqual(notif.Records[0].Event, "s3:TestEvent", 'wrong event name in notification');
9697
expect_test = false;
9798
} else {
99+
assert.strictEqual(req.url, expected_url);
98100
assert.strictEqual(notif.Records[0].s3.bucket.name, expected_bucket, 'wrong bucket name in notification');
99101
assert.strictEqual(notif.Records[0].eventName, expected_event_name, 'wrong event name in notification');
100102
assert.strictEqual(notif.Records[0].s3.object.key, expected_key, 'wrong key in notification');
@@ -235,18 +237,47 @@ mocha.describe('notifications', function() {
235237
});
236238
});
237239

240+
mocha.it('override connection', async () => {
241+
await s3.putBucketNotificationConfiguration({
242+
Bucket: bucket,
243+
NotificationConfiguration: {
244+
TopicConfigurations: [{
245+
"Id": "system_test_http_no_event_override",
246+
"TopicArn": http_connect_filename + "?" + JSON.stringify({
247+
request_options_object: {path: "/override"}
248+
}),
249+
}],
250+
},
251+
});
252+
253+
const res = await s3.putObject({
254+
Bucket: bucket,
255+
Key: 'f1',
256+
Body: 'this is the body',
257+
});
258+
259+
await notify_await_result({
260+
bucket_name: bucket,
261+
event_name: 'ObjectCreated:Put',
262+
key: "f1",
263+
etag: res.ETag,
264+
url: "/override"
265+
});
266+
});
267+
238268
});
239269

240270
});
241271

242272
const step_wait = 100;
243-
async function notify_await_result({bucket_name, event_name, etag, key, timeout = undefined}) {
273+
async function notify_await_result({bucket_name, event_name, etag, key, url = "/default", timeout = undefined}) {
244274

245275
//remember expected result here so server could compare it to actual result later
246276
expected_bucket = bucket_name;
247277
expected_event_name = event_name;
248278
expected_eTag = etag;
249279
expected_key = key;
280+
expected_url = url;
250281
server_done = false;
251282

252283
//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)