mirror of https://github.com/node-red/node-red.git
Merge pull request #5016 from node-red/5009-fix-env-context-access
Allow env var access to contextpull/3402/merge
commit
479b7e756d
|
@ -719,6 +719,14 @@ class Flow {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getContext(scope) {
|
||||||
|
if (scope === 'flow') {
|
||||||
|
return this.context
|
||||||
|
} else if (scope === 'global') {
|
||||||
|
return context.get('global')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dump() {
|
dump() {
|
||||||
console.log("==================")
|
console.log("==================")
|
||||||
console.log(this.TYPE, this.id);
|
console.log(this.TYPE, this.id);
|
||||||
|
|
|
@ -49,6 +49,14 @@ class Group {
|
||||||
}
|
}
|
||||||
return this.parent.getSetting(key);
|
return this.parent.getSetting(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error(msg) {
|
||||||
|
this.parent.error(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
getContext(scope) {
|
||||||
|
return this.parent.getContext(scope);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -100,7 +100,24 @@ async function evaluateEnvProperties(flow, env, credentials) {
|
||||||
}
|
}
|
||||||
} else if (type ==='jsonata') {
|
} else if (type ==='jsonata') {
|
||||||
pendingEvaluations.push(new Promise((resolve, _) => {
|
pendingEvaluations.push(new Promise((resolve, _) => {
|
||||||
redUtil.evaluateNodeProperty(value, 'jsonata', {_flow: flow}, null, (err, result) => {
|
redUtil.evaluateNodeProperty(value, 'jsonata',{
|
||||||
|
// Fake a node object to provide access to _flow and context
|
||||||
|
_flow: flow,
|
||||||
|
context: () => {
|
||||||
|
return {
|
||||||
|
flow: {
|
||||||
|
get: (value, store, callback) => {
|
||||||
|
return flow.getContext('flow').get(value, store, callback)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
get: (value, store, callback) => {
|
||||||
|
return flow.getContext('global').get(value, store, callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, null, (err, result) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (typeof result === 'object') {
|
if (typeof result === 'object') {
|
||||||
result = { value: result, __clone__: true}
|
result = { value: result, __clone__: true}
|
||||||
|
|
Loading…
Reference in New Issue