reimplement $(env var) replace to share common code.

and add test to utils
This commit is contained in:
Dave Conway-Jones
2016-11-17 13:56:17 +00:00
parent 74f2180fa4
commit 8d5286703f
4 changed files with 53 additions and 48 deletions

View File

@@ -259,32 +259,6 @@ function Flow(global,flow) {
}
}
}
}
var EnvVarPropertyRE = /^\$\((\S+)\)$/;
function mapEnvVarProperties(obj,prop) {
if (Buffer.isBuffer(obj[prop])) {
return;
} else if (Array.isArray(obj[prop])) {
for (var i=0;i<obj[prop].length;i++) {
mapEnvVarProperties(obj[prop],i);
}
} else if (typeof obj[prop] === 'string') {
var m;
if ( (m = EnvVarPropertyRE.exec(obj[prop])) !== null) {
if (process.env.hasOwnProperty(m[1])) {
obj[prop] = process.env[m[1]];
}
}
} else {
for (var p in obj[prop]) {
if (obj[prop].hasOwnProperty(p)) {
mapEnvVarProperties(obj[prop],p);
}
}
}
}
function createNode(type,config) {
@@ -295,7 +269,7 @@ function createNode(type,config) {
delete conf.credentials;
for (var p in conf) {
if (conf.hasOwnProperty(p)) {
mapEnvVarProperties(conf,p);
flowUtil.mapEnvVarProperties(conf,p);
}
}
try {