mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Evaluate all env vars as part of async flow start
This commit is contained in:
@@ -119,7 +119,7 @@ class Subflow extends Flow {
|
||||
this.templateCredentials = credentials.get(subflowDef.id) || {};
|
||||
this.instanceCredentials = credentials.get(id) || {};
|
||||
|
||||
var env = [];
|
||||
var env = {};
|
||||
if (this.subflowDef.env) {
|
||||
this.subflowDef.env.forEach(e => {
|
||||
env[e.name] = e;
|
||||
@@ -145,7 +145,7 @@ class Subflow extends Flow {
|
||||
}
|
||||
});
|
||||
}
|
||||
this.env = env;
|
||||
this.env = Object.values(env);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +156,7 @@ class Subflow extends Flow {
|
||||
* @param {[type]} diff [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
start(diff) {
|
||||
async start(diff) {
|
||||
var self = this;
|
||||
// Create a subflow node to accept inbound messages and route appropriately
|
||||
var Node = require("../nodes/Node");
|
||||
@@ -310,7 +310,7 @@ class Subflow extends Flow {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.start(diff);
|
||||
return super.start(diff);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,68 +335,35 @@ class Subflow extends Flow {
|
||||
}
|
||||
/**
|
||||
* Get environment variable of subflow
|
||||
* @param {String} name name of env var
|
||||
* @param {String} key name of env var
|
||||
* @return {Object} val value of env var
|
||||
*/
|
||||
getSetting(name) {
|
||||
if (!/^\$parent\./.test(name)) {
|
||||
var env = this.env;
|
||||
if (env && env.hasOwnProperty(name)) {
|
||||
var val = env[name];
|
||||
// If this is an env type property we need to be careful not
|
||||
// to get into lookup loops.
|
||||
// 1. if the value to lookup is the same as this one, go straight to parent
|
||||
// 2. otherwise, check if it is a compound env var ("foo $(bar)")
|
||||
// and if so, substitute any instances of `name` with $parent.name
|
||||
// See https://github.com/node-red/node-red/issues/2099
|
||||
if (val.type !== 'env' || val.value !== name) {
|
||||
let value = val.value;
|
||||
var type = val.type;
|
||||
if (type === 'env') {
|
||||
value = value.replace(new RegExp("\\${"+name+"}","g"),"${$parent."+name+"}");
|
||||
}
|
||||
try {
|
||||
return evaluateInputValue(value, type, this.node);
|
||||
}
|
||||
catch (e) {
|
||||
this.error(e);
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
// This _is_ an env property pointing at itself - go to parent
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// name starts $parent. ... so delegate to parent automatically
|
||||
name = name.substring(8);
|
||||
}
|
||||
getSetting(key) {
|
||||
const node = this.subflowInstance;
|
||||
if (node) {
|
||||
if (name === "NR_NODE_NAME") {
|
||||
if (key === "NR_NODE_NAME") {
|
||||
return node.name;
|
||||
}
|
||||
if (name === "NR_NODE_ID") {
|
||||
if (key === "NR_NODE_ID") {
|
||||
return node.id;
|
||||
}
|
||||
if (name === "NR_NODE_PATH") {
|
||||
if (key === "NR_NODE_PATH") {
|
||||
return node._path;
|
||||
}
|
||||
}
|
||||
if (node.g) {
|
||||
const group = this.getGroupNode(node.g);
|
||||
const [result, newName] = this.getGroupEnvSetting(node, group, name);
|
||||
if (result) {
|
||||
return result.val;
|
||||
if (!key.startsWith("$parent.")) {
|
||||
if (this._env.hasOwnProperty(key)) {
|
||||
return this._env[key]
|
||||
}
|
||||
name = newName;
|
||||
} else {
|
||||
key = key.substring(8);
|
||||
}
|
||||
|
||||
var parent = this.parent;
|
||||
if (parent) {
|
||||
var val = parent.getSetting(name);
|
||||
return val;
|
||||
// Push the request up to the parent.
|
||||
// Unlike a Flow, the parent of a Subflow could be a Group
|
||||
if (node.g) {
|
||||
return this.parent.getGroupNode(node.g).getSetting(key)
|
||||
}
|
||||
return undefined;
|
||||
return this.parent.getSetting(key)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user