Skip to content

Commit ad20e2f

Browse files
committed
use id instead of name for nodered
1 parent c78abff commit ad20e2f

11 files changed

Lines changed: 97 additions & 47 deletions

OpenFlow/src/Messages/DeleteNoderedInstanceMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class DeleteNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
66
public name: string;
7+
public _id: string;
78

89
static assign(o: any): DeleteNoderedInstanceMessage {
910
if (typeof o === "string" || o instanceof String) {

OpenFlow/src/Messages/EnsureNoderedInstanceMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class EnsureNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
66
public name: string;
7+
public _id: string;
78

89
static assign(o: any): EnsureNoderedInstanceMessage {
910
if (typeof o === "string" || o instanceof String) {

OpenFlow/src/Messages/GetNoderedInstanceLogMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class GetNoderedInstanceLogMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
66
public name: string;
7+
public _id: string;
78
public result: string;
89

910
static assign(o: any): GetNoderedInstanceLogMessage {

OpenFlow/src/Messages/GetNoderedInstanceMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class GetNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
66
public name: string;
7+
public _id: string;
78
public result: any;
89

910
static assign(o: any): GetNoderedInstanceMessage {

OpenFlow/src/Messages/Message.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,25 @@ export class Message {
712712
this.Send(cli);
713713
}
714714

715-
private async GetInstanceName(cli: WebSocketClient, name: string): Promise<string> {
716-
var username = cli.user.username;
717-
username = username.split("@").join("").split(".").join("");
718-
if (name !== null && name !== undefined && name !== "" && name != username) {
719-
var exists = await User.FindByUsername(name, cli.jwt);
720-
if (exists == null) {
721-
throw new Error("Unknown name " + name);
715+
private async GetInstanceName(cli: WebSocketClient, _id: string, name: string): Promise<string> {
716+
if (_id !== null && _id !== undefined && _id !== "" && _id != cli.user._id) {
717+
var res = await Config.db.query<User>({ _id: _id }, null, 1, 0, null, "users", cli.jwt);
718+
if (res.length == 0) {
719+
throw new Error("Unknown userid " + _id);
722720
}
721+
name = res[0].username;
722+
// if (name !== null && name !== undefined && name !== "" && name != username) {
723+
// }
724+
// var exists = await User.FindByUsername(name, cli.jwt);
725+
} else {
726+
name = cli.user.username;
723727
}
728+
// if (name !== null && name !== undefined && name !== "" && name != username) {
729+
// var exists = await User.FindByUsername(name, cli.jwt);
730+
// if (exists == null) {
731+
// throw new Error("Unknown name " + name);
732+
// }
733+
// }
724734
name = name.split("@").join("").split(".").join("");
725735
name = name.toLowerCase();
726736
return name;
@@ -732,7 +742,7 @@ export class Message {
732742
try {
733743
cli._logger.debug("[" + cli.user.username + "] EnsureNoderedInstance");
734744
msg = EnsureNoderedInstanceMessage.assign(this.data);
735-
var name = await this.GetInstanceName(cli, msg.name);
745+
var name = await this.GetInstanceName(cli, msg._id, msg.name);
736746
var namespace = Config.namespace;
737747
var hostname = Config.nodered_domain_schema.replace("$nodered_id$", name);
738748
var queue_prefix: string = "";
@@ -887,7 +897,7 @@ export class Message {
887897
try {
888898
cli._logger.debug("[" + cli.user.username + "] DeleteNoderedInstance");
889899
msg = DeleteNoderedInstanceMessage.assign(this.data);
890-
var name = await this.GetInstanceName(cli, msg.name);
900+
var name = await this.GetInstanceName(cli, msg._id, msg.name);
891901
var namespace = Config.namespace;
892902
var hostname = Config.nodered_domain_schema.replace("$nodered_id$", name);
893903

@@ -954,7 +964,7 @@ export class Message {
954964
try {
955965
cli._logger.debug("[" + cli.user.username + "] RestartNoderedInstance");
956966
msg = RestartNoderedInstanceMessage.assign(this.data);
957-
var name = await this.GetInstanceName(cli, msg.name);
967+
var name = await this.GetInstanceName(cli, msg._id, msg.name);
958968
var namespace = Config.namespace;
959969
// var hostname = Config.nodered_domain_schema.replace("$nodered_id$", name);
960970

@@ -986,7 +996,7 @@ export class Message {
986996
try {
987997
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance");
988998
msg = GetNoderedInstanceMessage.assign(this.data);
989-
var name = await this.GetInstanceName(cli, msg.name);
999+
var name = await this.GetInstanceName(cli, msg._id, msg.name);
9901000
var namespace = Config.namespace;
9911001
// var hostname = Config.nodered_domain_schema.replace("$nodered_id$", name);
9921002

@@ -1029,7 +1039,7 @@ export class Message {
10291039
try {
10301040
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance");
10311041
msg = GetNoderedInstanceLogMessage.assign(this.data);
1032-
var name = await this.GetInstanceName(cli, msg.name);
1042+
var name = await this.GetInstanceName(cli, msg._id, msg.name);
10331043
var namespace = Config.namespace;
10341044

10351045
var list = await KubeUtil.instance().CoreV1Api.listNamespacedPod(namespace);

OpenFlow/src/Messages/RestartNoderedInstanceMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class RestartNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
66
public name: string;
7+
public _id: string;
78

89
static assign(o: any): RestartNoderedInstanceMessage {
910
if (typeof o === "string" || o instanceof String) {

OpenFlow/src/public/CommonControllers.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,40 +243,40 @@ module openflow {
243243
}
244244
return msg;
245245
}
246-
async GetNoderedInstance(name: string): Promise<any> {
247-
var q: GetNoderedInstanceMessage = new GetNoderedInstanceMessage(); q.name = name;
246+
async GetNoderedInstance(_id: string, name: string): Promise<any> {
247+
var q: GetNoderedInstanceMessage = new GetNoderedInstanceMessage(); q.name = name; q._id = _id;
248248
var msg: Message = new Message(); msg.command = "getnoderedinstance"; msg.data = JSON.stringify(q);
249249
q = await this.WebSocketClient.Send<GetNoderedInstanceMessage>(msg);
250250
return q.result;
251251
}
252-
async GetNoderedInstanceLog(name: string): Promise<string> {
253-
var q: GetNoderedInstanceLogMessage = new GetNoderedInstanceLogMessage(); q.name = name;
252+
async GetNoderedInstanceLog(_id: string, name: string): Promise<string> {
253+
var q: GetNoderedInstanceLogMessage = new GetNoderedInstanceLogMessage(); q.name = name; q._id = _id;
254254
var msg: Message = new Message(); msg.command = "getnoderedinstancelog"; msg.data = JSON.stringify(q);
255255
q = await this.WebSocketClient.Send<GetNoderedInstanceLogMessage>(msg);
256256
return q.result;
257257
}
258-
async EnsureNoderedInstance(name: string): Promise<void> {
259-
var q: EnsureNoderedInstanceMessage = new EnsureNoderedInstanceMessage(); q.name = name;
258+
async EnsureNoderedInstance(_id: string, name: string): Promise<void> {
259+
var q: EnsureNoderedInstanceMessage = new EnsureNoderedInstanceMessage(); q.name = name; q._id = _id;
260260
var msg: Message = new Message(); msg.command = "ensurenoderedinstance"; msg.data = JSON.stringify(q);
261261
q = await this.WebSocketClient.Send<EnsureNoderedInstanceMessage>(msg);
262262
}
263-
async DeleteNoderedInstance(name: string): Promise<void> {
264-
var q: DeleteNoderedInstanceMessage = new DeleteNoderedInstanceMessage(); q.name = name;
263+
async DeleteNoderedInstance(_id: string, name: string): Promise<void> {
264+
var q: DeleteNoderedInstanceMessage = new DeleteNoderedInstanceMessage(); q.name = name; q._id = _id;
265265
var msg: Message = new Message(); msg.command = "deletenoderedinstance"; msg.data = JSON.stringify(q);
266266
q = await this.WebSocketClient.Send<DeleteNoderedInstanceMessage>(msg);
267267
}
268-
async RestartNoderedInstance(name: string): Promise<void> {
269-
var q: RestartNoderedInstanceMessage = new RestartNoderedInstanceMessage(); q.name = name;
268+
async RestartNoderedInstance(_id: string, name: string): Promise<void> {
269+
var q: RestartNoderedInstanceMessage = new RestartNoderedInstanceMessage(); q.name = name; q._id = _id;
270270
var msg: Message = new Message(); msg.command = "restartnoderedinstance"; msg.data = JSON.stringify(q);
271271
q = await this.WebSocketClient.Send<RestartNoderedInstanceMessage>(msg);
272272
}
273-
async StartNoderedInstance(name: string): Promise<void> {
274-
var q: StartNoderedInstanceMessage = new StartNoderedInstanceMessage(); q.name = name;
273+
async StartNoderedInstance(_id: string, name: string): Promise<void> {
274+
var q: StartNoderedInstanceMessage = new StartNoderedInstanceMessage(); q.name = name; q._id = _id;
275275
var msg: Message = new Message(); msg.command = "startnoderedinstance"; msg.data = JSON.stringify(q);
276276
q = await this.WebSocketClient.Send<StartNoderedInstanceMessage>(msg);
277277
}
278-
async StopNoderedInstance(name: string): Promise<void> {
279-
var q: StopNoderedInstanceMessage = new StopNoderedInstanceMessage(); q.name = name;
278+
async StopNoderedInstance(_id: string, name: string): Promise<void> {
279+
var q: StopNoderedInstanceMessage = new StopNoderedInstanceMessage(); q.name = name; q._id = _id;
280280
var msg: Message = new Message(); msg.command = "stopnoderedinstance"; msg.data = JSON.stringify(q);
281281
q = await this.WebSocketClient.Send<StopNoderedInstanceMessage>(msg);
282282
}

OpenFlow/src/public/Controllers.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,49 +1091,49 @@ module openflow {
10911091
});
10921092
}
10931093

1094-
async EnsureNoderedInstance(name: string) {
1094+
async EnsureNoderedInstance(_id: string, name: string) {
10951095
try {
1096-
await this.api.EnsureNoderedInstance(name);
1096+
await this.api.EnsureNoderedInstance(_id, name);
10971097
this.messages += "EnsureNoderedInstance completed" + "\n";
10981098
} catch (error) {
10991099
this.messages += error + "\n";
11001100
console.error(error);
11011101
}
11021102
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11031103
}
1104-
async DeleteNoderedInstance(name: string) {
1104+
async DeleteNoderedInstance(_id: string, name: string) {
11051105
try {
1106-
await this.api.DeleteNoderedInstance(name);
1106+
await this.api.DeleteNoderedInstance(_id, name);
11071107
this.messages += "DeleteNoderedInstance completed" + "\n";
11081108
} catch (error) {
11091109
this.messages += error + "\n";
11101110
console.error(error);
11111111
}
11121112
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11131113
}
1114-
async RestartNoderedInstance(name: string) {
1114+
async RestartNoderedInstance(_id: string, name: string) {
11151115
try {
1116-
await this.api.RestartNoderedInstance(name);
1116+
await this.api.RestartNoderedInstance(_id, name);
11171117
this.messages += "RestartNoderedInstance completed" + "\n";
11181118
} catch (error) {
11191119
this.messages += error + "\n";
11201120
console.error(error);
11211121
}
11221122
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11231123
}
1124-
async StartNoderedInstance(name: string) {
1124+
async StartNoderedInstance(_id: string, name: string) {
11251125
try {
1126-
await this.api.StartNoderedInstance(name);
1126+
await this.api.StartNoderedInstance(_id, name);
11271127
this.messages += "StartNoderedInstance completed" + "\n";
11281128
} catch (error) {
11291129
this.messages += error + "\n";
11301130
console.error(error);
11311131
}
11321132
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11331133
}
1134-
async StopNoderedInstance(name: string) {
1134+
async StopNoderedInstance(_id: string, name: string) {
11351135
try {
1136-
await this.api.StopNoderedInstance(name);
1136+
await this.api.StopNoderedInstance(_id, name);
11371137
this.messages += "StopNoderedInstance completed" + "\n";
11381138
} catch (error) {
11391139
this.messages += error + "\n";
@@ -2365,6 +2365,7 @@ module openflow {
23652365
public instancestatus: string = "";
23662366
public instancelog: string = "";
23672367
public name: string = "";
2368+
public userid: string = "";
23682369
constructor(
23692370
public $scope: ng.IScope,
23702371
public $location: ng.ILocationService,
@@ -2375,9 +2376,17 @@ module openflow {
23752376
console.debug("NoderedCtrl");
23762377
WebSocketClient.onSignedin(async (user: TokenUser) => {
23772378
await api.RegisterQueue();
2378-
this.name = $routeParams.id;
2379-
if (this.name == null || this.name == undefined || this.name == "") {
2379+
this.userid = $routeParams.id;
2380+
if (this.userid == null || this.userid == undefined || this.userid == "") {
23802381
this.name = WebSocketClient.user.username;
2382+
this.userid = WebSocketClient.user._id;
2383+
} else {
2384+
var users = await this.api.Query("users", { _id: this.userid }, null, null, 1);
2385+
if (users.length == 0) {
2386+
this.instancestatus = "Unknown id!";
2387+
return;
2388+
}
2389+
this.name = users[0].username;
23812390
}
23822391
this.name = this.name.split("@").join("").split(".").join("");
23832392
this.name = this.name.toLowerCase();
@@ -2390,7 +2399,7 @@ module openflow {
23902399
try {
23912400
this.instancestatus = "fetching status";
23922401

2393-
this.instance = await this.api.GetNoderedInstance(this.name);
2402+
this.instance = await this.api.GetNoderedInstance(this.userid, this.name);
23942403
console.debug("GetNoderedInstance:");
23952404
if (this.instance !== null && this.instance !== undefined) {
23962405
if (this.instance.metadata.deletionTimestamp !== undefined) {
@@ -2414,7 +2423,7 @@ module openflow {
24142423
try {
24152424
this.instancestatus = "fetching log";
24162425
console.debug("GetNoderedInstanceLog:");
2417-
this.instancelog = await this.api.GetNoderedInstanceLog(this.name);
2426+
this.instancelog = await this.api.GetNoderedInstanceLog(this.userid, this.name);
24182427
this.instancelog = this.instancelog.split("\n").reverse().join("\n");
24192428
this.messages += "GetNoderedInstanceLog completed\n";
24202429
this.instancestatus = "";
@@ -2427,7 +2436,7 @@ module openflow {
24272436
}
24282437
async EnsureNoderedInstance() {
24292438
try {
2430-
await this.api.EnsureNoderedInstance(this.name);
2439+
await this.api.EnsureNoderedInstance(this.userid, this.name);
24312440
this.messages += "EnsureNoderedInstance completed" + "\n";
24322441
} catch (error) {
24332442
this.messages += error + "\n";
@@ -2438,7 +2447,7 @@ module openflow {
24382447
}
24392448
async DeleteNoderedInstance() {
24402449
try {
2441-
await this.api.DeleteNoderedInstance(this.name);
2450+
await this.api.DeleteNoderedInstance(this.userid, this.name);
24422451
this.messages += "DeleteNoderedInstance completed" + "\n";
24432452
} catch (error) {
24442453
this.messages += error + "\n";
@@ -2449,7 +2458,7 @@ module openflow {
24492458
}
24502459
async RestartNoderedInstance() {
24512460
try {
2452-
await this.api.RestartNoderedInstance(this.name);
2461+
await this.api.RestartNoderedInstance(this.userid, this.name);
24532462
this.messages += "RestartNoderedInstance completed" + "\n";
24542463
} catch (error) {
24552464
this.messages += error + "\n";
@@ -2460,7 +2469,7 @@ module openflow {
24602469
}
24612470
async StartNoderedInstance() {
24622471
try {
2463-
await this.api.StartNoderedInstance(this.name);
2472+
await this.api.StartNoderedInstance(this.userid, this.name);
24642473
this.messages += "StartNoderedInstance completed" + "\n";
24652474
} catch (error) {
24662475
this.messages += error + "\n";
@@ -2471,7 +2480,7 @@ module openflow {
24712480
}
24722481
async StopNoderedInstance() {
24732482
try {
2474-
await this.api.StopNoderedInstance(this.name);
2483+
await this.api.StopNoderedInstance(this.userid, this.name);
24752484
this.messages += "StopNoderedInstance completed" + "\n";
24762485
} catch (error) {
24772486
this.messages += error + "\n";
@@ -2606,8 +2615,18 @@ module openflow {
26062615
name = name.toLowerCase();
26072616
var noderedurl = "https://" + this.WebSocketClient.nodered_domain_schema.replace("$nodered_id$", name);
26082617
window.open(noderedurl);
2609-
26102618
}
2619+
ManageNodered(model: any) {
2620+
this.$location.path("/Nodered/" + model._id);
2621+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
2622+
}
2623+
async Impersonate(model: openflow.TokenUser): Promise<any> {
2624+
this.loading = true;
2625+
var result = await this.api.SigninWithToken(this.WebSocketClient.jwt, null, model._id);
2626+
this.loading = false;
2627+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
2628+
}
2629+
26112630
// async DeleteOne(model: any): Promise<any> {
26122631
// this.loading = true;
26132632
// await this.api.Delete(this.collection, model);

OpenFlow/src/public/Message.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ module openflow {
196196
public error: string;
197197
public jwt: any;
198198
public name: string;
199+
public _id: string;
199200
public result: any;
200201
static assign(o: any): GetNoderedInstanceMessage {
201202
if (typeof o === "string" || o instanceof String) {
@@ -208,6 +209,7 @@ module openflow {
208209
public error: string;
209210
public jwt: any;
210211
public name: string;
212+
public _id: string;
211213
public result: string;
212214
static assign(o: any): GetNoderedInstanceMessage {
213215
if (typeof o === "string" || o instanceof String) {
@@ -220,6 +222,7 @@ module openflow {
220222
public error: string;
221223
public jwt: any;
222224
public name: string;
225+
public _id: string;
223226
static assign(o: any): EnsureNoderedInstanceMessage {
224227
if (typeof o === "string" || o instanceof String) {
225228
return Object.assign(new EnsureNoderedInstanceMessage(), JSON.parse(o.toString()));
@@ -231,6 +234,7 @@ module openflow {
231234
public error: string;
232235
public jwt: any;
233236
public name: string;
237+
public _id: string;
234238
static assign(o: any): DeleteNoderedInstanceMessage {
235239
if (typeof o === "string" || o instanceof String) {
236240
return Object.assign(new DeleteNoderedInstanceMessage(), JSON.parse(o.toString()));
@@ -242,6 +246,7 @@ module openflow {
242246
public error: string;
243247
public jwt: any;
244248
public name: string;
249+
public _id: string;
245250
static assign(o: any): RestartNoderedInstanceMessage {
246251
if (typeof o === "string" || o instanceof String) {
247252
return Object.assign(new RestartNoderedInstanceMessage(), JSON.parse(o.toString()));
@@ -253,6 +258,7 @@ module openflow {
253258
public error: string;
254259
public jwt: any;
255260
public name: string;
261+
public _id: string;
256262
static assign(o: any): StartNoderedInstanceMessage {
257263
if (typeof o === "string" || o instanceof String) {
258264
return Object.assign(new StartNoderedInstanceMessage(), JSON.parse(o.toString()));
@@ -264,6 +270,7 @@ module openflow {
264270
public error: string;
265271
public jwt: any;
266272
public name: string;
273+
public _id: string;
267274
static assign(o: any): StopNoderedInstanceMessage {
268275
if (typeof o === "string" || o instanceof String) {
269276
return Object.assign(new StopNoderedInstanceMessage(), JSON.parse(o.toString()));

0 commit comments

Comments
 (0)