mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3278 from node-red-hitachi/fix-env-var-access
fix env var access using $parent for groups
This commit is contained in:
commit
30e750dfe5
@ -439,8 +439,6 @@ class Flow {
|
||||
}
|
||||
}
|
||||
return [env.name, env];
|
||||
|
||||
return [env.name, env];
|
||||
});
|
||||
group._env = Object.fromEntries(entries);
|
||||
}
|
||||
@ -457,24 +455,24 @@ class Flow {
|
||||
const val
|
||||
= ((value === "true") ||
|
||||
(value === true));
|
||||
return {
|
||||
return [{
|
||||
val: val
|
||||
};
|
||||
}, null];
|
||||
}
|
||||
if (type === "cred") {
|
||||
return {
|
||||
return [{
|
||||
val: value
|
||||
};
|
||||
}, null];
|
||||
}
|
||||
try {
|
||||
var val = redUtil.evaluateNodeProperty(value, type, node, null, null);
|
||||
return {
|
||||
return [{
|
||||
val: val
|
||||
};
|
||||
}, null];
|
||||
}
|
||||
catch (e) {
|
||||
this.error(e);
|
||||
return null;
|
||||
return [null, null];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -488,7 +486,7 @@ class Flow {
|
||||
return this.getGroupEnvSetting(node, parent, name);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return [null, name];
|
||||
}
|
||||
|
||||
|
||||
@ -545,6 +543,9 @@ class Flow {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
key = key.substring(8);
|
||||
}
|
||||
}
|
||||
return this.parent.getSetting(key);
|
||||
}
|
||||
|
@ -373,10 +373,11 @@ class Subflow extends Flow {
|
||||
const node = this.subflowInstance;
|
||||
if (node.g) {
|
||||
const group = this.getGroupNode(node.g);
|
||||
const result = this.getGroupEnvSetting(node, group, name);
|
||||
const [result, newName] = this.getGroupEnvSetting(node, group, name);
|
||||
if (result) {
|
||||
return result.val;
|
||||
}
|
||||
name = newName;
|
||||
}
|
||||
|
||||
|
||||
|
@ -526,10 +526,11 @@ function getSetting(node, name, flow_) {
|
||||
if (flow) {
|
||||
if (node && node.g) {
|
||||
const group = flow.getGroupNode(node.g);
|
||||
const result = flow.getGroupEnvSetting(node, group, name);
|
||||
const [result, newName] = flow.getGroupEnvSetting(node, group, name);
|
||||
if (result) {
|
||||
return result.val;
|
||||
}
|
||||
name = newName;
|
||||
}
|
||||
return flow.getSetting(name);
|
||||
}
|
||||
|
@ -1275,6 +1275,52 @@ describe('Flow', function() {
|
||||
}
|
||||
|
||||
});
|
||||
it("can access environment variable property using $parent", function (done) {
|
||||
try {
|
||||
after(function() {
|
||||
delete process.env.V0;
|
||||
delete process.env.V1;
|
||||
})
|
||||
process.env.V0 = "gv0";
|
||||
process.env.V1 = "gv1";
|
||||
var config = flowUtils.parseConfig([
|
||||
{id:"t1",type:"tab",env:[
|
||||
{"name": "V0", value: "v0", type: "str"}
|
||||
]},
|
||||
{id:"g1",type:"group",z:"t1",env:[
|
||||
{"name": "V0", value: "v1", type: "str"},
|
||||
{"name": "V1", value: "v2", type: "str"}
|
||||
]},
|
||||
{id:"g2",type:"group",z:"t1",g:"g1",env:[
|
||||
{"name": "V1", value: "v3", type: "str"}
|
||||
]},
|
||||
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"${$parent.V0}",wires:[]},
|
||||
{id:"2",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"${$parent.V0}",wires:[]},
|
||||
{id:"3",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"${$parent.V1}",wires:[]},
|
||||
{id:"4",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${$parent.V1}",wires:[]},
|
||||
{id:"5",x:10,y:10,z:"t1",type:"test",foo:"${$parent.V1}",wires:[]},
|
||||
]);
|
||||
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
|
||||
flow.start();
|
||||
|
||||
var activeNodes = flow.getActiveNodes();
|
||||
|
||||
activeNodes["1"].foo.should.equal("gv0");
|
||||
activeNodes["2"].foo.should.equal("v0");
|
||||
activeNodes["3"].foo.should.equal("gv1");
|
||||
activeNodes["4"].foo.should.equal("v2");
|
||||
activeNodes["5"].foo.should.equal("gv1");
|
||||
|
||||
flow.stop().then(function() {
|
||||
done();
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e.stack);
|
||||
done(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user