Merge pull request #3356 from node-red-hitachi/node-prop-env-var

Add support for accessing node id & name as environment variable
This commit is contained in:
Nick O'Leary
2022-01-26 11:11:02 +00:00
committed by GitHub
5 changed files with 273 additions and 1 deletions

View File

@@ -424,6 +424,17 @@ class Flow {
*/
getGroupEnvSetting(node, group, name) {
if (group) {
if (name === "NR_GROUP_NAME") {
return [{
val: group.name
}, null];
}
if (name === "NR_GROUP_ID") {
return [{
val: group.id
}, null];
}
if (group.credentials === undefined) {
group.credentials = credentials.get(group.id) || {};
}
@@ -498,7 +509,13 @@ class Flow {
* @return {[type]} [description]
*/
getSetting(key) {
const flow = this.flow;
const flow = this.flow;
if (key === "NR_FLOW_NAME") {
return flow.label;
}
if (key === "NR_FLOW_ID") {
return flow.id;
}
if (flow.credentials === undefined) {
flow.credentials = credentials.get(flow.id) || {};
}

View File

@@ -371,6 +371,14 @@ class Subflow extends Flow {
name = name.substring(8);
}
const node = this.subflowInstance;
if (node) {
if (name === "NR_NODE_NAME") {
return node.name;
}
if (name === "NR_NODE_ID") {
return node.id;
}
}
if (node.g) {
const group = this.getGroupNode(node.g);
const [result, newName] = this.getGroupEnvSetting(node, group, name);

View File

@@ -522,6 +522,14 @@ function setObjectProperty(msg,prop,value,createMissing) {
* @return {String} value of env var
*/
function getSetting(node, name, flow_) {
if (node) {
if (name === "NR_NODE_NAME") {
return node.name;
}
if (name === "NR_NODE_ID") {
return node.id;
}
}
var flow = (flow_ ? flow_ : (node ? node._flow : null));
if (flow) {
if (node && node.g) {