mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
merge getFlowSetting to getSetting
This commit is contained in:
parent
d78e5932f9
commit
67404a327d
@ -416,68 +416,6 @@ class Flow {
|
|||||||
return this.activeNodes;
|
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.credentials === undefined) {
|
|
||||||
flow.credentials = credentials.get(flow.id) || {};
|
|
||||||
}
|
|
||||||
if (flow.env) {
|
|
||||||
if (!name.startsWith("$parent.")) {
|
|
||||||
if (!flow._env) {
|
|
||||||
const envs = flow.env;
|
|
||||||
const entries = envs.map((env) => {
|
|
||||||
if (env.type === "cred") {
|
|
||||||
const cred = flow.credentials;
|
|
||||||
if (cred.hasOwnProperty(env.name)) {
|
|
||||||
env.value = cred[env.name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [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 value of environment variable defined in group node.
|
* Get value of environment variable defined in group node.
|
||||||
* @param {String} group - group node
|
* @param {String} group - group node
|
||||||
@ -562,9 +500,51 @@ class Flow {
|
|||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
getSetting(key) {
|
getSetting(key) {
|
||||||
const result = this.getFlowSetting(key);
|
const flow = this.flow;
|
||||||
if (result) {
|
if (flow.credentials === undefined) {
|
||||||
return result.val;
|
flow.credentials = credentials.get(flow.id) || {};
|
||||||
|
}
|
||||||
|
if (flow.env) {
|
||||||
|
if (!key.startsWith("$parent.")) {
|
||||||
|
if (!flow._env) {
|
||||||
|
const envs = flow.env;
|
||||||
|
const entries = envs.map((env) => {
|
||||||
|
if (env.type === "cred") {
|
||||||
|
const cred = flow.credentials;
|
||||||
|
if (cred.hasOwnProperty(env.name)) {
|
||||||
|
env.value = cred[env.name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [env.name, env]
|
||||||
|
});
|
||||||
|
flow._env = Object.fromEntries(entries);
|
||||||
|
}
|
||||||
|
const env = flow._env[key];
|
||||||
|
if (env) {
|
||||||
|
let value = env.value;
|
||||||
|
const type = env.type;
|
||||||
|
if ((type !== "env") || (value !== key)) {
|
||||||
|
if (type === "env") {
|
||||||
|
value = value.replace(new RegExp("\\${"+key+"}","g"),"${$parent."+key+"}");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (type === "bool") {
|
||||||
|
const val = ((value === "true") ||
|
||||||
|
(value === true));
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
if (type === "cred") {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
var val = redUtil.evaluateNodeProperty(value, type, null, null, null);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
this.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this.parent.getSetting(key);
|
return this.parent.getSetting(key);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user