-
Notifications
You must be signed in to change notification settings - Fork 0
/
processcube-engine-config.js
45 lines (40 loc) · 1.67 KB
/
processcube-engine-config.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
const engine_client = require('@5minds/processcube_engine_client');
const jwt = require('jwt-decode');
const oidc = require('openid-client');
module.exports = function (RED) {
function ProcessCubeEngineNode(n) {
RED.nodes.createNode(this, n);
const node = this;
node.url = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
node.credentials.clientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
node.credentials.clientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
try {
if (node.credentials.clientId && node.credentials.clientSecret) {
node.log('Create Client with secrets');
node.engineClient = new engine_client.EngineClient(node.url, {
clientId: node.credentials.clientId,
clientSecret: node.credentials.clientSecret,
scope: 'engine_etw engine_read engine_write',
});
} else {
node.log('Create Client without secrets');
node.engineClient = new engine_client.EngineClient(node.url);
}
} catch (error) {
node.error(JSON.stringify(error));
}
node.on('close', async () => {
node.log('close');
if (node.engineClient) {
node.engineClient.dispose();
node.engineClient = null;
}
});
}
RED.nodes.registerType('processcube-engine-config', ProcessCubeEngineNode, {
credentials: {
clientId: { type: 'text' },
clientSecret: { type: 'password' },
},
});
};