mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Pass full runtime object to storage and flow sub-components
This commit is contained in:
parent
ee45d6b48f
commit
e06cadd761
@ -83,7 +83,7 @@ function start() {
|
|||||||
.then(function() {
|
.then(function() {
|
||||||
return i18n.registerMessageCatalog("runtime",path.resolve(path.join(__dirname,"locales")),"runtime.json")
|
return i18n.registerMessageCatalog("runtime",path.resolve(path.join(__dirname,"locales")),"runtime.json")
|
||||||
})
|
})
|
||||||
.then(function() { return storage.init(settings)})
|
.then(function() { return storage.init(runtime)})
|
||||||
.then(function() { return settings.load(storage)})
|
.then(function() { return settings.load(storage)})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
|
||||||
|
@ -43,12 +43,12 @@ var subflowInstanceNodeMap = {};
|
|||||||
|
|
||||||
var typeEventRegistered = false;
|
var typeEventRegistered = false;
|
||||||
|
|
||||||
function init(_settings, _storage) {
|
function init(runtime) {
|
||||||
if (started) {
|
if (started) {
|
||||||
throw new Error("Cannot init without a stop");
|
throw new Error("Cannot init without a stop");
|
||||||
}
|
}
|
||||||
settings = _settings;
|
settings = runtime.settings;
|
||||||
storage = _storage;
|
storage = runtime.storage;
|
||||||
started = false;
|
started = false;
|
||||||
if (!typeEventRegistered) {
|
if (!typeEventRegistered) {
|
||||||
events.on('type-registered',function(type) {
|
events.on('type-registered',function(type) {
|
||||||
|
@ -78,7 +78,7 @@ function createNode(node,def) {
|
|||||||
function init(runtime) {
|
function init(runtime) {
|
||||||
settings = runtime.settings;
|
settings = runtime.settings;
|
||||||
credentials.init(runtime.storage);
|
credentials.init(runtime.storage);
|
||||||
flows.init(runtime.settings,runtime.storage);
|
flows.init(runtime);
|
||||||
registry.init(runtime);
|
registry.init(runtime);
|
||||||
context.init(runtime.settings);
|
context.init(runtime.settings);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ var when = require('when');
|
|||||||
var Path = require('path');
|
var Path = require('path');
|
||||||
var log = require("../log");
|
var log = require("../log");
|
||||||
|
|
||||||
|
var runtime;
|
||||||
var storageModule;
|
var storageModule;
|
||||||
var settingsAvailable;
|
var settingsAvailable;
|
||||||
var sessionsAvailable;
|
var sessionsAvailable;
|
||||||
@ -42,15 +43,16 @@ function is_malicious(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var storageModuleInterface = {
|
var storageModuleInterface = {
|
||||||
init: function(settings) {
|
init: function(_runtime) {
|
||||||
|
runtime = _runtime;
|
||||||
try {
|
try {
|
||||||
storageModule = moduleSelector(settings);
|
storageModule = moduleSelector(runtime.settings);
|
||||||
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
|
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
|
||||||
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
|
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return when.reject(e);
|
return when.reject(e);
|
||||||
}
|
}
|
||||||
return storageModule.init(settings);
|
return storageModule.init(runtime.settings);
|
||||||
},
|
},
|
||||||
getFlows: function() {
|
getFlows: function() {
|
||||||
return storageModule.getFlows();
|
return storageModule.getFlows();
|
||||||
|
@ -119,7 +119,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.setFlows(originalConfig).then(function() {
|
flows.setFlows(originalConfig).then(function() {
|
||||||
credentialsExtract.called.should.be.false;
|
credentialsExtract.called.should.be.false;
|
||||||
credentialsClean.called.should.be.true;
|
credentialsClean.called.should.be.true;
|
||||||
@ -134,7 +134,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.setFlows(originalConfig,"load").then(function() {
|
flows.setFlows(originalConfig,"load").then(function() {
|
||||||
credentialsExtract.called.should.be.false;
|
credentialsExtract.called.should.be.false;
|
||||||
credentialsClean.called.should.be.true;
|
credentialsClean.called.should.be.true;
|
||||||
@ -151,7 +151,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[],credentials:{}},
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[],credentials:{}},
|
||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.setFlows(originalConfig).then(function() {
|
flows.setFlows(originalConfig).then(function() {
|
||||||
credentialsExtract.called.should.be.true;
|
credentialsExtract.called.should.be.true;
|
||||||
credentialsClean.called.should.be.true;
|
credentialsClean.called.should.be.true;
|
||||||
@ -188,7 +188,7 @@ describe('flows/index', function() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
});
|
});
|
||||||
@ -217,7 +217,7 @@ describe('flows/index', function() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
});
|
});
|
||||||
@ -234,7 +234,7 @@ describe('flows/index', function() {
|
|||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve(originalConfig);
|
return when.resolve(originalConfig);
|
||||||
}
|
}
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
credentialsExtract.called.should.be.false;
|
credentialsExtract.called.should.be.false;
|
||||||
credentialsLoad.called.should.be.true;
|
credentialsLoad.called.should.be.true;
|
||||||
@ -262,7 +262,7 @@ describe('flows/index', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
});
|
});
|
||||||
@ -277,7 +277,7 @@ describe('flows/index', function() {
|
|||||||
return when.resolve(originalConfig);
|
return when.resolve(originalConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
flowCreate.called.should.be.false;
|
flowCreate.called.should.be.false;
|
||||||
@ -295,7 +295,7 @@ describe('flows/index', function() {
|
|||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve(originalConfig);
|
return when.resolve(originalConfig);
|
||||||
}
|
}
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
flowCreate.called.should.be.false;
|
flowCreate.called.should.be.false;
|
||||||
@ -329,7 +329,7 @@ describe('flows/index', function() {
|
|||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve(originalConfig);
|
return when.resolve(originalConfig);
|
||||||
}
|
}
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
flows.eachNode(function(node) {
|
flows.eachNode(function(node) {
|
||||||
@ -360,7 +360,7 @@ describe('flows/index', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
});
|
});
|
||||||
@ -391,7 +391,7 @@ describe('flows/index', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
});
|
});
|
||||||
@ -413,7 +413,7 @@ describe('flows/index', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
});
|
});
|
||||||
@ -445,7 +445,7 @@ describe('flows/index', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.startFlows();
|
flows.startFlows();
|
||||||
});
|
});
|
||||||
@ -473,7 +473,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.setFlows(originalConfig).then(function() {
|
flows.setFlows(originalConfig).then(function() {
|
||||||
flows.checkTypeInUse("unused-module");
|
flows.checkTypeInUse("unused-module");
|
||||||
done();
|
done();
|
||||||
@ -484,7 +484,7 @@ describe('flows/index', function() {
|
|||||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||||
{id:"t1",type:"tab"}
|
{id:"t1",type:"tab"}
|
||||||
];
|
];
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.setFlows(originalConfig).then(function() {
|
flows.setFlows(originalConfig).then(function() {
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
try {
|
try {
|
||||||
@ -507,7 +507,7 @@ describe('flows/index', function() {
|
|||||||
storage.getFlows = function() {
|
storage.getFlows = function() {
|
||||||
return when.resolve(originalConfig);
|
return when.resolve(originalConfig);
|
||||||
}
|
}
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
flows.addFlow({
|
flows.addFlow({
|
||||||
label:'new flow',
|
label:'new flow',
|
||||||
@ -534,7 +534,7 @@ describe('flows/index', function() {
|
|||||||
storage.setFlows = function() {
|
storage.setFlows = function() {
|
||||||
return when.resolve();
|
return when.resolve();
|
||||||
}
|
}
|
||||||
flows.init({},storage);
|
flows.init({settings:{},storage:storage});
|
||||||
flows.load().then(function() {
|
flows.load().then(function() {
|
||||||
return flows.startFlows();
|
return flows.startFlows();
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
|
@ -22,7 +22,9 @@ describe("red/storage/index", function() {
|
|||||||
it('rejects the promise when settings suggest loading a bad module', function(done) {
|
it('rejects the promise when settings suggest loading a bad module', function(done) {
|
||||||
|
|
||||||
var wrongModule = {
|
var wrongModule = {
|
||||||
|
settings:{
|
||||||
storageModule : "thisaintloading"
|
storageModule : "thisaintloading"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
storage.init(wrongModule).then( function() {
|
storage.init(wrongModule).then( function() {
|
||||||
@ -48,7 +50,9 @@ describe("red/storage/index", function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var setsBooleanModule = {
|
var setsBooleanModule = {
|
||||||
|
settings: {
|
||||||
storageModule : moduleWithBooleanSettingInit
|
storageModule : moduleWithBooleanSettingInit
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
storage.init(setsBooleanModule);
|
storage.init(setsBooleanModule);
|
||||||
@ -116,7 +120,9 @@ describe("red/storage/index", function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var moduleToLoad = {
|
var moduleToLoad = {
|
||||||
|
settings: {
|
||||||
storageModule : interfaceCheckerModule
|
storageModule : interfaceCheckerModule
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
storage.init(moduleToLoad);
|
storage.init(moduleToLoad);
|
||||||
@ -172,7 +178,9 @@ describe("red/storage/index", function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var moduleToLoad = {
|
var moduleToLoad = {
|
||||||
|
settings: {
|
||||||
storageModule : interfaceCheckerModule
|
storageModule : interfaceCheckerModule
|
||||||
|
}
|
||||||
};
|
};
|
||||||
before(function() {
|
before(function() {
|
||||||
storage.init(moduleToLoad);
|
storage.init(moduleToLoad);
|
||||||
@ -220,7 +228,7 @@ describe("red/storage/index", function() {
|
|||||||
var interfaceCheckerModule = {
|
var interfaceCheckerModule = {
|
||||||
init : function () {}
|
init : function () {}
|
||||||
};
|
};
|
||||||
storage.init({storageModule: interfaceCheckerModule});
|
storage.init({settings:{storageModule: interfaceCheckerModule}});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('defaults missing getSettings',function(done) {
|
it('defaults missing getSettings',function(done) {
|
||||||
|
Loading…
Reference in New Issue
Block a user