Skip to content

Commit ca836b2

Browse files
committed
clean up tokens for wf/assign
1 parent 3c8e389 commit ca836b2

7 files changed

Lines changed: 51 additions & 58 deletions

File tree

OpenFlow/src/Messages/Message.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export class Message {
231231
} catch (error) {
232232
}
233233
}
234+
var sendthis: any = msg.data;
234235
try {
235236
if (NoderedUtil.IsNullEmpty(msg.jwt) && !NoderedUtil.IsNullEmpty(msg.data.jwt)) {
236237
msg.jwt = msg.data.jwt;
@@ -242,6 +243,10 @@ export class Message {
242243
var tuser = Crypt.verityToken(msg.jwt);
243244
msg.user = tuser;
244245
}
246+
if (typeof sendthis === "object") {
247+
sendthis.__jwt = msg.jwt;
248+
sendthis.__user = msg.user;
249+
}
245250
} catch (error) {
246251
cli._logger.error(error);
247252
}
@@ -1593,14 +1598,16 @@ export class Message {
15931598

15941599
var _data = Base.assign<Base>(msg as any);
15951600
_data.addRight(msg.targetid, "targetid", [-1]);
1601+
_data.addRight(cli.user._id, cli.user.name, [-1]);
1602+
_data.addRight(tuser._id, tuser.name, [-1]);
15961603
_data._type = "instance";
15971604
_data.name = msg.name;
15981605

15991606
var res2 = await Config.db.InsertOne(_data, "workflow_instances", 1, true, msg.jwt);
16001607
msg.newinstanceid = res2._id;
16011608

16021609
if (msg.initialrun) {
1603-
var message = { _id: res2._id };
1610+
var message = { _id: res2._id, __jwt: msg.jwt, __user: tuser };
16041611
amqpwrapper.Instance().sendWithReplyTo("", msg.queue, msg.resultqueue, message, Config.amqp_default_expiration, msg.correlationId);
16051612
// cli.consumers[0].sendToQueueWithReply(msg.queue, msg.resultqueue, msg.correlationId, message, (60 * (60 * 1000))); // 1 hour
16061613
}

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openflow-nodered",
3-
"version": "1.0.54",
3+
"version": "1.0.55",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

OpenFlowNodeRED/src/nodered/nodes/amqp_nodes.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,17 @@ export class amqp_consumer_node {
112112
}
113113
async OnMessage(msg: any, ack: any) {
114114
try {
115-
var result: any = {};
116-
result.amqpacknowledgment = ack;
117-
var data: any = null;
118-
try {
119-
// data = JSON.parse(msg.content.toString());
120-
data = msg.data;
121-
} catch (error) {
122-
115+
var data: any = msg.data;
116+
data.amqpacknowledgment = ack;
117+
if (!NoderedUtil.IsNullUndefinded(data.__user)) {
118+
data.user = data.__user;
119+
delete data.__user;
123120
}
124-
try {
125-
data.payload = JSON.parse(data.payload);
126-
} catch (error) {
121+
if (!NoderedUtil.IsNullUndefinded(data.__jwt)) {
122+
data.jwt = data.__jwt;
123+
delete data.__jwt;
127124
}
128-
result.payload = data.payload;
129-
result.jwt = data.jwt;
130-
this.node.send(result);
125+
this.node.send(data);
131126
ack();
132127
} catch (error) {
133128
NoderedUtil.HandleError(this, error);

OpenFlowNodeRED/src/nodered/nodes/workflow.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
paletteLabel: 'assign',
197197
icon: "font-awesome/fa-user-plus",
198198
defaults: {
199-
name: { value: "", required: true },
199+
name: { value: "" },
200200
queue: { value: "", required: true },
201201
targetid: { value: "" },
202202
workflowid: { value: "" },

OpenFlowNodeRED/src/nodered/nodes/workflow_nodes.ts

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class workflow_in_node {
5252
this.OnMessage(msg, ack);
5353
});
5454
await this.init();
55-
this.node.status({ fill: "green", shape: "dot", text: "Connected" });
55+
this.node.status({ fill: "green", shape: "dot", text: "Connected " + this.localqueue });
5656
} catch (error) {
5757
NoderedUtil.HandleError(this, error);
5858
}
@@ -142,9 +142,13 @@ export class workflow_in_node {
142142
data.payload = JSON.parse(data.payload);
143143
} catch (error) {
144144
}
145-
if (data.payload != null && data.payload.jwt != null && data.jwt == null) {
146-
data.jwt = data.payload.jwt;
147-
delete data.payload.jwt;
145+
if (data.payload != null && data.payload.__jwt != null && data.__jwt == null) {
146+
if (!NoderedUtil.IsNullUndefinded(data.payload.__user)) {
147+
data.user = data.payload.__user;
148+
delete data.payload.__user;
149+
}
150+
data.jwt = data.payload.__jwt;
151+
delete data.payload.__jwt;
148152
}
149153
while (data.payload != null && data.payload.payload != null) {
150154
data.payload = data.payload.payload;
@@ -181,28 +185,13 @@ export class workflow_in_node {
181185
orgmsg.payload = { message: orgmsg.payload };
182186
orgmsg.payload = Object.assign(orgmsg.payload, data.payload);
183187
}
188+
orgmsg.jwt = data.jwt;
189+
orgmsg.user = data.user;
184190
data = orgmsg;
185191
}
186192
data.jwt = jwt;
187-
// data = Object.assign(res[0], { payload: data });
188-
// Logger.instanse.info("workflow in activated id " + data._id);
189-
// result.name = res[0].name;
190-
// result._id = res[0]._id;
191-
// result._created = res[0]._created;
192-
// result._createdby = res[0]._createdby;
193-
// result._createdbyid = res[0]._createdbyid;
194-
// result._modified = res[0]._modified;
195-
// result._modifiedby = res[0]._modifiedby;
196-
// result._modifiedbyid = res[0]._modifiedbyid;
197-
// if (data.payload === null || data.payload === undefined) {
198-
// result.payload = res[0].payload;
199-
// } else {
200-
// result.payload = Object.assign(res[0].payload, data.payload);
201-
// }
202-
// result.workflow = this.workflow._id;
203193
} else {
204194
this.node.status({ fill: "blue", shape: "dot", text: "Processing new instance " });
205-
// if (this.localqueue !== null && this.localqueue !== undefined && this.localqueue !== "") { this.localqueue = Config.queue_prefix + this.localqueue; }
206195
var jwt = data.jwt;
207196

208197
var who = WebSocketClient.instance.user;
@@ -238,18 +227,13 @@ export class workflow_in_node {
238227
data = Object.assign(res2, data);
239228
data.jwt = jwt;
240229
}
241-
// var result: any = {};
242-
// result.amqpacknowledgment = ack;
243-
// result.payload = data.payload;
244-
// result.values = data.values;
245-
// result.jwt = data.jwt;
246230
data.amqpacknowledgment = ack;
247231
data._replyTo = msg.replyto;
248232
data._correlationId = msg.correlationId;
249233

250234
this.node.send(data);
251235
// this.node.send(result);
252-
this.node.status({ fill: "green", shape: "dot", text: "Connected" });
236+
this.node.status({ fill: "green", shape: "dot", text: "Connected " + this.localqueue });
253237
} catch (error) {
254238
NoderedUtil.HandleError(this, error);
255239
try {
@@ -299,8 +283,11 @@ export class workflow_out_node {
299283
msg.state = this.config.state;
300284
msg.form = this.config.form;
301285
if (msg._id !== null && msg._id !== undefined && msg._id !== "") {
286+
let msgcopy = Object.assign({}, msg);
287+
delete msgcopy.jwt;
288+
delete msgcopy.user;
302289
// Logger.instanse.info("Updating workflow instance with id " + msg._id + " (" + msg.name + " with state " + msg.state);
303-
var res2 = await NoderedUtil.UpdateOne("workflow_instances", null, msg, 1, false, msg.jwt);
290+
var res2 = await NoderedUtil.UpdateOne("workflow_instances", null, msgcopy, 1, false, msg.jwt);
304291
}
305292
} catch (error) {
306293
NoderedUtil.HandleError(this, error);
@@ -474,10 +461,12 @@ export class assign_workflow_node {
474461
try {
475462
this.node.status({ fill: "blue", shape: "dot", text: "Connecting..." });
476463
// if (this.localqueue !== null && this.localqueue !== undefined && this.localqueue !== "") { this.localqueue = Config.queue_prefix + this.localqueue; }
464+
465+
this.localqueue = this.config.queue;
477466
this.localqueue = await NoderedUtil.RegisterQueue(WebSocketClient.instance, this.localqueue, (msg: QueueMessage, ack: any) => {
478467
this.OnMessage(msg, ack);
479468
});
480-
this.node.status({ fill: "green", shape: "dot", text: "Connected" });
469+
this.node.status({ fill: "green", shape: "dot", text: "Connected " + this.localqueue });
481470

482471

483472

@@ -501,16 +490,15 @@ export class assign_workflow_node {
501490
try {
502491
var result: any = {};
503492
var data: any = msg.data;
504-
try {
505-
data = JSON.parse(msg.data);
506-
} catch (error) {
507-
493+
if (data.state == "idle") return;
494+
if (!NoderedUtil.IsNullUndefinded(data.__user)) {
495+
data.user = data.__user;
496+
delete data.__user;
508497
}
509-
try {
510-
data.payload = JSON.parse(data.payload);
511-
} catch (error) {
498+
if (!NoderedUtil.IsNullUndefinded(data.__jwt)) {
499+
data.jwt = data.__jwt;
500+
delete data.__jwt;
512501
}
513-
if (data.state == "idle") return;
514502
// delete data.jwt;
515503
var _id = data._id;
516504
if (_id === null || _id === undefined || _id === "") {
@@ -538,14 +526,17 @@ export class assign_workflow_node {
538526
res[0].state = state;
539527
result = res[0].msg;
540528
result.payload = data.payload;
529+
result.jwt = data.jwt;
530+
result.user = data.user;
541531
this.node.send([null, result]);
542532
if (ack !== null && ack !== undefined) ack();
543533
await NoderedUtil.UpdateOne("workflow_instances", null, res[0], 1, false, null);
544534
return;
545535
}
546536
}
547537
result.payload = data.payload;
548-
// result.jwt = data.jwt;
538+
result.jwt = data.jwt;
539+
result.user = data.user;
549540
this.node.send([null, result]);
550541
if (ack !== null && ack !== undefined) ack();
551542
} catch (error) {
@@ -603,7 +594,7 @@ export class assign_workflow_node {
603594
msg.newinstanceid = await NoderedUtil.CreateWorkflowInstance(targetid, workflowid, null, this.localqueue, res3._id, msg.payload, initialrun, jwt);;
604595

605596
this.node.send(msg);
606-
this.node.status({ fill: "green", shape: "dot", text: "Connected" });
597+
this.node.status({ fill: "green", shape: "dot", text: "Connected " + this.localqueue });
607598
} catch (error) {
608599
NoderedUtil.HandleError(this, error);
609600
}

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.54
1+
1.0.55

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openiap",
3-
"version": "1.0.54",
3+
"version": "1.0.55",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)