This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.js
74 lines (65 loc) · 2.02 KB
/
connection.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module.exports = function (RED) {
const Y = require('yaml');
const { Client } = require('@opensearch-project/opensearch');
function OsConnectionNode(n) {
RED.nodes.createNode(this, n);
const node = this;
this.conf = n;
let auth;
switch (this.credentials.cred) {
case '':
auth = null;
break;
case 'basic':
auth = {
username: this.credentials.ident,
password: this.credentials.secret,
};
break;
case 'apikey_b64':
auth = { apiKey: this.credentials.secret };
break;
case 'apikey_obj':
auth = {
apiKey: {
id: this.credentials.ident,
api_key: this.credentials.secret,
},
};
break;
case 'bearer':
auth = { bearer: this.credentials.secret };
break;
default:
node.error('Invalid credential');
}
let params = {};
if (n.nodes) { params.nodes = n.nodes.split(' '); }
if (auth && auth !== '') { params.auth = auth; }
if (n.advConfig) {
try {
const ac = Y.parse(n.advConfig);
if (ac) { params = { ...ac, ...params }; }
} catch (e) {
this.error(e);
}
}
if (!n.verifyservercert) {
if (!params.ssl) {
params.ssl = {};
}
params.ssl.rejectUnauthorized = false;
}
this._conn = new Client(params);
this.client = function (c) {
return this._conn.child(c);
};
}
RED.nodes.registerType('os-connection', OsConnectionNode, {
credentials: {
cred: { type: 'text' },
ident: { type: 'text' },
secret: { type: 'password' },
},
});
};