@5minds/node-red-contrib-processcube 1.5.2-feature-4db23e-m33j5ixt → 1.5.2-feature-059ba7-m35qmr4f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/processcube-engine-config.js +146 -153
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@5minds/node-red-contrib-processcube",
|
3
|
-
"version": "1.5.2-feature-
|
3
|
+
"version": "1.5.2-feature-059ba7-m35qmr4f",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "Node-RED nodes for ProcessCube",
|
6
6
|
"scripts": {
|
@@ -57,7 +57,7 @@
|
|
57
57
|
"examples": "examples"
|
58
58
|
},
|
59
59
|
"dependencies": {
|
60
|
-
"@5minds/processcube_engine_client": "
|
60
|
+
"@5minds/processcube_engine_client": "5.1.0-hotfix-a73235-m346kg1n",
|
61
61
|
"jwt-decode": "^4.0.0",
|
62
62
|
"openid-client": "^5.5.0"
|
63
63
|
},
|
@@ -12,52 +12,8 @@ module.exports = function (RED) {
|
|
12
12
|
this.url = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
|
13
13
|
this.identity = null;
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
const UPDATE_INTERVAL = 10000;
|
18
|
-
let previousClientId, previousClientSecret;
|
19
|
-
|
20
|
-
const updateCredentials = async () => {
|
21
|
-
try {
|
22
|
-
const newClientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
|
23
|
-
const newClientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
|
24
|
-
|
25
|
-
if (newClientId !== previousClientId || newClientSecret !== previousClientSecret) {
|
26
|
-
if (this.engineClient) this.engineClient.dispose();
|
27
|
-
|
28
|
-
this.credentials.clientId = newClientId;
|
29
|
-
this.credentials.clientSecret = newClientSecret;
|
30
|
-
|
31
|
-
this.engineClient = new engine_client.EngineClient(this.url);
|
32
|
-
|
33
|
-
if (this.credentials.clientId && this.credentials.clientSecret) {
|
34
|
-
const authorityUrl = await this.engineClient.applicationInfo.getAuthorityAddress();
|
35
|
-
startRefreshingIdentityCycle(
|
36
|
-
this.credentials.clientId,
|
37
|
-
this.credentials.clientSecret,
|
38
|
-
authorityUrl,
|
39
|
-
node
|
40
|
-
).catch(console.error);
|
41
|
-
}
|
42
|
-
|
43
|
-
previousClientId = newClientId;
|
44
|
-
previousClientSecret = newClientSecret;
|
45
|
-
}
|
46
|
-
|
47
|
-
retries = 5;
|
48
|
-
setTimeout(updateCredentials, UPDATE_INTERVAL);
|
49
|
-
} catch (error) {
|
50
|
-
if (retries === 0) return console.error('Credential update failed permanently:', error);
|
51
|
-
console.error('Credential update error, retrying:', { error, retries });
|
52
|
-
retries--;
|
53
|
-
setTimeout(updateCredentials, 2000);
|
54
|
-
}
|
55
|
-
};
|
56
|
-
|
57
|
-
await updateCredentials();
|
58
|
-
}
|
59
|
-
|
60
|
-
console.log('luis888', this.credentials.clientId);
|
15
|
+
this.credentials.clientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
|
16
|
+
this.credentials.clientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
|
61
17
|
|
62
18
|
this.registerOnIdentityChanged = function (callback) {
|
63
19
|
identityChangedCallbacks.push(callback);
|
@@ -80,6 +36,46 @@ module.exports = function (RED) {
|
|
80
36
|
}
|
81
37
|
};
|
82
38
|
|
39
|
+
async function getFreshIdentity(url) {
|
40
|
+
console.log('luis777');
|
41
|
+
if (
|
42
|
+
!RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node) ||
|
43
|
+
!RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node)
|
44
|
+
)
|
45
|
+
return null;
|
46
|
+
const res = await fetch(url + '/atlas_engine/api/v1/authority', {
|
47
|
+
method: 'GET',
|
48
|
+
headers: {
|
49
|
+
Authorization: `Bearer ZHVtbXlfdG9rZW4=`,
|
50
|
+
'Content-Type': 'application/json',
|
51
|
+
},
|
52
|
+
});
|
53
|
+
|
54
|
+
const issuer = await oidc.Issuer.discover(await res.json());
|
55
|
+
|
56
|
+
const client = new issuer.Client({
|
57
|
+
client_id: RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node),
|
58
|
+
client_secret: RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node),
|
59
|
+
});
|
60
|
+
|
61
|
+
const tokenSet = await client.grant({
|
62
|
+
grant_type: 'client_credentials',
|
63
|
+
scope: 'engine_etw engine_read engine_write',
|
64
|
+
});
|
65
|
+
|
66
|
+
const accessToken = tokenSet.access_token;
|
67
|
+
const decodedToken = jwt.jwtDecode(accessToken);
|
68
|
+
|
69
|
+
const freshIdentity = {
|
70
|
+
token: tokenSet.access_token,
|
71
|
+
userId: decodedToken.sub,
|
72
|
+
};
|
73
|
+
|
74
|
+
configNode.setIdentity(freshIdentity);
|
75
|
+
|
76
|
+
return freshIdentity;
|
77
|
+
}
|
78
|
+
|
83
79
|
node.on('close', async () => {
|
84
80
|
if (this.engineClient) {
|
85
81
|
this.engineClient.dispose();
|
@@ -87,32 +83,29 @@ module.exports = function (RED) {
|
|
87
83
|
}
|
88
84
|
});
|
89
85
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
// } else {
|
114
|
-
// this.engineClient = new engine_client.EngineClient(this.url);
|
115
|
-
// }
|
86
|
+
if (this.credentials.clientId && this.credentials.clientSecret) {
|
87
|
+
this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url));
|
88
|
+
|
89
|
+
// this.engineClient.applicationInfo
|
90
|
+
// .getAuthorityAddress()
|
91
|
+
// .then((authorityUrl) => {
|
92
|
+
// startRefreshingIdentityCycle(
|
93
|
+
// this.credentials.clientId,
|
94
|
+
// this.credentials.clientSecret,
|
95
|
+
// authorityUrl,
|
96
|
+
// node
|
97
|
+
// ).catch((reason) => {
|
98
|
+
// console.error(reason);
|
99
|
+
// node.error(reason);
|
100
|
+
// });
|
101
|
+
// })
|
102
|
+
// .catch((reason) => {
|
103
|
+
// console.error(reason);
|
104
|
+
// node.error(reason);
|
105
|
+
// });
|
106
|
+
} else {
|
107
|
+
this.engineClient = new engine_client.EngineClient(this.url);
|
108
|
+
}
|
116
109
|
}
|
117
110
|
RED.nodes.registerType('processcube-engine-config', ProcessCubeEngineNode, {
|
118
111
|
credentials: {
|
@@ -122,84 +115,84 @@ module.exports = function (RED) {
|
|
122
115
|
});
|
123
116
|
};
|
124
117
|
|
125
|
-
async function getFreshTokenSet(clientId, clientSecret, authorityUrl) {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
function getIdentityForExternalTaskWorkers(tokenSet) {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
async function getExpiresInForExternalTaskWorkers(tokenSet) {
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
/**
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
async function startRefreshingIdentityCycle(clientId, clientSecret, authorityUrl, configNode) {
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
}
|
118
|
+
// async function getFreshTokenSet(clientId, clientSecret, authorityUrl) {
|
119
|
+
// const issuer = await oidc.Issuer.discover(authorityUrl);
|
120
|
+
|
121
|
+
// const client = new issuer.Client({
|
122
|
+
// client_id: clientId,
|
123
|
+
// client_secret: clientSecret,
|
124
|
+
// });
|
125
|
+
|
126
|
+
// const tokenSet = await client.grant({
|
127
|
+
// grant_type: 'client_credentials',
|
128
|
+
// scope: 'engine_etw engine_read engine_write',
|
129
|
+
// });
|
130
|
+
|
131
|
+
// return tokenSet;
|
132
|
+
// }
|
133
|
+
|
134
|
+
// function getIdentityForExternalTaskWorkers(tokenSet) {
|
135
|
+
// const accessToken = tokenSet.access_token;
|
136
|
+
// const decodedToken = jwt.jwtDecode(accessToken);
|
137
|
+
|
138
|
+
// return {
|
139
|
+
// token: tokenSet.access_token,
|
140
|
+
// userId: decodedToken.sub,
|
141
|
+
// };
|
142
|
+
// }
|
143
|
+
|
144
|
+
// async function getExpiresInForExternalTaskWorkers(tokenSet) {
|
145
|
+
// let expiresIn = tokenSet.expires_in;
|
146
|
+
|
147
|
+
// if (!expiresIn && tokenSet.expires_at) {
|
148
|
+
// expiresIn = Math.floor(tokenSet.expires_at - Date.now() / 1000);
|
149
|
+
// }
|
150
|
+
|
151
|
+
// if (expiresIn === undefined) {
|
152
|
+
// throw new Error('Could not determine the time until the access token for external task workers expires');
|
153
|
+
// }
|
154
|
+
|
155
|
+
// return expiresIn;
|
156
|
+
// }
|
157
|
+
|
158
|
+
// /**
|
159
|
+
// * Start refreshing the identity in regular intervals.
|
160
|
+
// * @param {TokenSet | null} tokenSet The token set to refresh the identity for
|
161
|
+
// * @returns {Promise<void>} A promise that resolves when the timer for refreshing the identity is initialized
|
162
|
+
// * */
|
163
|
+
// async function startRefreshingIdentityCycle(clientId, clientSecret, authorityUrl, configNode) {
|
164
|
+
// let retries = 5;
|
165
|
+
|
166
|
+
// const refresh = async () => {
|
167
|
+
// try {
|
168
|
+
// const newTokenSet = await getFreshTokenSet(clientId, clientSecret, authorityUrl);
|
169
|
+
// const expiresIn = await getExpiresInForExternalTaskWorkers(newTokenSet);
|
170
|
+
// const delay = expiresIn * DELAY_FACTOR * 1000;
|
171
|
+
|
172
|
+
// freshIdentity = getIdentityForExternalTaskWorkers(newTokenSet);
|
173
|
+
|
174
|
+
// configNode.setIdentity(freshIdentity);
|
175
|
+
|
176
|
+
// retries = 5;
|
177
|
+
// setTimeout(refresh, delay);
|
178
|
+
// } catch (error) {
|
179
|
+
// if (retries === 0) {
|
180
|
+
// console.error(
|
181
|
+
// 'Could not refresh identity for external task worker processes. Stopping all external task workers.',
|
182
|
+
// { error }
|
183
|
+
// );
|
184
|
+
// return;
|
185
|
+
// }
|
186
|
+
// console.error('Could not refresh identity for external task worker processes.', {
|
187
|
+
// error,
|
188
|
+
// retryCount: retries,
|
189
|
+
// });
|
190
|
+
// retries--;
|
191
|
+
|
192
|
+
// const delay = 2 * 1000;
|
193
|
+
// setTimeout(refresh, delay);
|
194
|
+
// }
|
195
|
+
// };
|
196
|
+
|
197
|
+
// await refresh();
|
198
|
+
// }
|