mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Let credentials also use $(...) substitutions from ENV
to close #1051 (and add to test)
This commit is contained in:
@@ -69,6 +69,20 @@ function createNode(node,def) {
|
||||
var creds = credentials.get(id);
|
||||
if (creds) {
|
||||
//console.log("Attaching credentials to ",node.id);
|
||||
// allow $(foo) syntax to substitute env variables for credentials also...
|
||||
var EnvVarPropertyRE = /^\$\((\S+)\)$/;
|
||||
var loopOver = function (obj) {
|
||||
for (var o in obj) {
|
||||
if (typeof obj[o] === "object" && obj[o] !== null) { loopOver(obj[o]); }
|
||||
else {
|
||||
var m;
|
||||
if ( (m = EnvVarPropertyRE.exec(obj[o])) !== null ) {
|
||||
if (process.env.hasOwnProperty(m[1])) { obj[o] = process.env[m[1]]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
loopOver(creds);
|
||||
node.credentials = creds;
|
||||
} else if (credentials.getDefinition(node.type)) {
|
||||
node.credentials = {};
|
||||
|
Reference in New Issue
Block a user