From 41797f8cef5457928aa1d1dbaca8b7fd51f825e7 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 22 Sep 2023 13:56:54 +0100 Subject: [PATCH 1/2] Handle credential env var evaluation when no value set --- packages/node_modules/@node-red/runtime/lib/flows/Flow.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js index ce2dab9ef..d9817e42e 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js @@ -161,14 +161,14 @@ class Flow { for (let i = 0; i < configNodes.length; i++) { const node = this.flow.configs[configNodes[i]] if (node.type === 'global-config' && node.env) { - const nodeEnv = await flowUtil.evaluateEnvProperties(this, node.env, credentials.get(node.id)) + const nodeEnv = await flowUtil.evaluateEnvProperties(this, node.env, credentials.get(node.id) || {}) this._env = { ...this._env, ...nodeEnv } } } } if (this.env) { - this._env = { ...this._env, ...await flowUtil.evaluateEnvProperties(this, this.env, credentials.get(this.id)) } + this._env = { ...this._env, ...await flowUtil.evaluateEnvProperties(this, this.env, credentials.get(this.id) || {}) } } // Initialise the group objects. These must be done in the right order From c9320c190d281433c9b078f5dbbae358ac8c5e36 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 25 Sep 2023 18:08:02 +0100 Subject: [PATCH 2/2] Ensure creds object is not undefined when evaling env vars --- packages/node_modules/@node-red/runtime/lib/flows/Flow.js | 4 ++-- packages/node_modules/@node-red/runtime/lib/flows/util.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js index d9817e42e..ce2dab9ef 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js @@ -161,14 +161,14 @@ class Flow { for (let i = 0; i < configNodes.length; i++) { const node = this.flow.configs[configNodes[i]] if (node.type === 'global-config' && node.env) { - const nodeEnv = await flowUtil.evaluateEnvProperties(this, node.env, credentials.get(node.id) || {}) + const nodeEnv = await flowUtil.evaluateEnvProperties(this, node.env, credentials.get(node.id)) this._env = { ...this._env, ...nodeEnv } } } } if (this.env) { - this._env = { ...this._env, ...await flowUtil.evaluateEnvProperties(this, this.env, credentials.get(this.id) || {}) } + this._env = { ...this._env, ...await flowUtil.evaluateEnvProperties(this, this.env, credentials.get(this.id)) } } // Initialise the group objects. These must be done in the right order diff --git a/packages/node_modules/@node-red/runtime/lib/flows/util.js b/packages/node_modules/@node-red/runtime/lib/flows/util.js index 7eefe86c4..46c0c20cb 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/util.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/util.js @@ -80,6 +80,7 @@ function mapEnvVarProperties(obj,prop,flow,config) { } async function evaluateEnvProperties(flow, env, credentials) { + credentials = credentials || {} const pendingEvaluations = [] const evaluatedEnv = {} const envTypes = []