Skip to content

Commit

Permalink
Merge pull request #4526 from node-red/4508
Browse files Browse the repository at this point in the history
Ensure global-config credential env vars are merged on deploy
  • Loading branch information
knolleary committed Jan 16, 2024
2 parents 4168bbb + 58e2fcb commit a5725c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Expand Up @@ -71,7 +71,7 @@ RED.envVar = (function() {
};
if (item.name.trim() !== "") {
new_env.push(item);
if ((item.type === "cred") && (item.value !== "__PWRD__")) {
if (item.type === "cred") {
credentials.map[item.name] = item.value;
credentials.map["has_"+item.name] = (item.value !== "");
item.value = "__PWRD__";
Expand Down
25 changes: 21 additions & 4 deletions packages/node_modules/@node-red/runtime/lib/nodes/credentials.js
Expand Up @@ -384,10 +384,27 @@ var api = module.exports = {
}
}
} else if (nodeType === "global-config") {
if (JSON.stringify(savedCredentials.map) !== JSON.stringify(newCreds.map)) {
savedCredentials.map = newCreds.map;
dirty = true;
}
const existingCredentialKeys = Object.keys(savedCredentials?.map || [])
const newCredentialKeys = Object.keys(newCreds?.map || [])
existingCredentialKeys.forEach(key => {
if (!newCreds.map?.[key]) {
// This key doesn't exist in the new credentials list - remove
delete savedCredentials.map[key]
delete savedCredentials.map[`has_${key}`]
dirty = true
}
})
newCredentialKeys.forEach(key => {
if (!/^has_/.test(key)) {
if (!savedCredentials.map?.[key] || newCreds.map[key] !== '__PWRD__') {
// This key either doesn't exist in current saved, or the
// value has been changed
savedCredentials.map[key] = newCreds.map[key]
savedCredentials.map[`has_${key}`] = newCreds.map[`has_${key}`]
dirty = true
}
}
})
} else {
var dashedType = nodeType.replace(/\s+/g, '-');
var definition = credentialsDef[dashedType];
Expand Down

0 comments on commit a5725c5

Please sign in to comment.