mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Let credentials also use $(...) substitutions from ENV
to close #1051 (and add to test)
This commit is contained in:
parent
6efd048fd6
commit
d042169f2e
@ -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 = {};
|
||||
|
@ -38,8 +38,9 @@ describe("red/nodes/index", function() {
|
||||
index.clearRegistry();
|
||||
});
|
||||
|
||||
process.env.foo="bar";
|
||||
var testFlows = [{"type":"test","id":"tab1","label":"Sheet 1"}];
|
||||
var testCredentials = {"tab1":{"b":1,"c":2}};
|
||||
var testCredentials = {"tab1":{"b":1, "c":"2", "d":"$(foo)"}};
|
||||
var storage = {
|
||||
getFlows: function() {
|
||||
return when({red:123,flows:testFlows,credentials:testCredentials});
|
||||
@ -58,7 +59,7 @@ describe("red/nodes/index", function() {
|
||||
var runtime = {
|
||||
settings: settings,
|
||||
storage: storage,
|
||||
log: {debug:function(){},warn:function(){}}
|
||||
log: {debug:function() {}, warn:function() {}}
|
||||
};
|
||||
|
||||
function TestNode(n) {
|
||||
@ -75,7 +76,8 @@ describe("red/nodes/index", function() {
|
||||
index.loadFlows().then(function() {
|
||||
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
|
||||
testnode.credentials.should.have.property('b',1);
|
||||
testnode.credentials.should.have.property('c',2);
|
||||
testnode.credentials.should.have.property('c',"2");
|
||||
testnode.credentials.should.have.property('d',"bar");
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
|
Loading…
Reference in New Issue
Block a user