mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow properties to be specified by environment variables
A property set to $(ABC) will be substituted with the environment variable ABC - if it exists. If the property doesn't exist, the property is left unchanged.
This commit is contained in:
parent
86aa7c97be
commit
f626ee060a
@ -27,10 +27,42 @@ function getID() {
|
|||||||
return (1+Math.random()*4294967295).toString(16);
|
return (1+Math.random()*4294967295).toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
mapEnvVarProperties(obj[prop],p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createNode(type,config) {
|
function createNode(type,config) {
|
||||||
var nn = null;
|
var nn = null;
|
||||||
|
var m;
|
||||||
var nt = typeRegistry.get(type);
|
var nt = typeRegistry.get(type);
|
||||||
if (nt) {
|
if (nt) {
|
||||||
|
for (var p in config) {
|
||||||
|
if (config.hasOwnProperty(p)) {
|
||||||
|
mapEnvVarProperties(config,p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nn = new nt(clone(config));
|
nn = new nt(clone(config));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user