mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
add support of environtment variable for tab & group
This commit is contained in:
@@ -396,6 +396,17 @@ class Flow {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a group node instance
|
||||
* @param {String} id
|
||||
* @return {Node} group node
|
||||
*/
|
||||
getGroupNode(id) {
|
||||
const groups = this.global.groups;
|
||||
return groups[id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the nodes instantiated within this flow
|
||||
* @return {[type]} [description]
|
||||
@@ -404,6 +415,57 @@ class Flow {
|
||||
return this.activeNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a flow setting value deined in this flow.
|
||||
* @param {String} key
|
||||
* @return {Object} result containinig val property or null
|
||||
*/
|
||||
getFlowSetting(name) {
|
||||
const flow = this.flow;
|
||||
if (flow.env) {
|
||||
if (!name.startsWith("$parent.")) {
|
||||
if (!flow._env) {
|
||||
const envs = flow.env;
|
||||
const entries = envs.map((env) => [env.name, env]);
|
||||
flow._env = Object.fromEntries(entries);
|
||||
}
|
||||
const env = flow._env[name];
|
||||
if (env) {
|
||||
let value = env.value;
|
||||
const type = env.type;
|
||||
if ((type !== "env") || (value !== name)) {
|
||||
if (type === "env") {
|
||||
value = value.replace(new RegExp("\\${"+name+"}","g"),"${$parent."+name+"}");
|
||||
}
|
||||
try {
|
||||
if (type === "bool") {
|
||||
const val = ((value === "true") ||
|
||||
(value === true));
|
||||
return {
|
||||
val: val
|
||||
};
|
||||
}
|
||||
if (type === "cred") {
|
||||
return {
|
||||
val: value
|
||||
};
|
||||
}
|
||||
var val = redUtil.evaluateNodeProperty(value, type, null, null, null);
|
||||
return {
|
||||
val: val
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
this.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a flow setting value. This currently automatically defers to the parent
|
||||
* flow which, as defined in ./index.js returns `process.env[key]`.
|
||||
@@ -412,6 +474,10 @@ class Flow {
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
getSetting(key) {
|
||||
const result = this.getFlowSetting(key);
|
||||
if (result) {
|
||||
return result.val;
|
||||
}
|
||||
return this.parent.getSetting(key);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user