diff --git a/red/runtime/index.js b/red/runtime/index.js index 5dbe34130..988a3220c 100644 --- a/red/runtime/index.js +++ b/red/runtime/index.js @@ -83,7 +83,7 @@ function start() { .then(function() { 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() { diff --git a/red/runtime/nodes/flows/index.js b/red/runtime/nodes/flows/index.js index f95e72555..a5eccc69e 100644 --- a/red/runtime/nodes/flows/index.js +++ b/red/runtime/nodes/flows/index.js @@ -43,12 +43,12 @@ var subflowInstanceNodeMap = {}; var typeEventRegistered = false; -function init(_settings, _storage) { +function init(runtime) { if (started) { throw new Error("Cannot init without a stop"); } - settings = _settings; - storage = _storage; + settings = runtime.settings; + storage = runtime.storage; started = false; if (!typeEventRegistered) { events.on('type-registered',function(type) { diff --git a/red/runtime/nodes/index.js b/red/runtime/nodes/index.js index f39e6c3cc..7b1b9c84e 100644 --- a/red/runtime/nodes/index.js +++ b/red/runtime/nodes/index.js @@ -78,7 +78,7 @@ function createNode(node,def) { function init(runtime) { settings = runtime.settings; credentials.init(runtime.storage); - flows.init(runtime.settings,runtime.storage); + flows.init(runtime); registry.init(runtime); context.init(runtime.settings); } diff --git a/red/runtime/storage/index.js b/red/runtime/storage/index.js index f60a92736..176422f08 100644 --- a/red/runtime/storage/index.js +++ b/red/runtime/storage/index.js @@ -18,6 +18,7 @@ var when = require('when'); var Path = require('path'); var log = require("../log"); +var runtime; var storageModule; var settingsAvailable; var sessionsAvailable; @@ -42,15 +43,16 @@ function is_malicious(path) { } var storageModuleInterface = { - init: function(settings) { + init: function(_runtime) { + runtime = _runtime; try { - storageModule = moduleSelector(settings); + storageModule = moduleSelector(runtime.settings); settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings"); sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions"); } catch (e) { return when.reject(e); } - return storageModule.init(settings); + return storageModule.init(runtime.settings); }, getFlows: function() { return storageModule.getFlows(); diff --git a/test/red/runtime/nodes/flows/index_spec.js b/test/red/runtime/nodes/flows/index_spec.js index 3a18bd73d..b3a9cb29b 100644 --- a/test/red/runtime/nodes/flows/index_spec.js +++ b/test/red/runtime/nodes/flows/index_spec.js @@ -119,7 +119,7 @@ describe('flows/index', function() { {id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]}, {id:"t1",type:"tab"} ]; - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.setFlows(originalConfig).then(function() { credentialsExtract.called.should.be.false; 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",type:"tab"} ]; - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.setFlows(originalConfig,"load").then(function() { credentialsExtract.called.should.be.false; 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",type:"tab"} ]; - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.setFlows(originalConfig).then(function() { credentialsExtract.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.startFlows(); }); @@ -217,7 +217,7 @@ describe('flows/index', function() { }) }); - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); }); @@ -234,7 +234,7 @@ describe('flows/index', function() { storage.getFlows = function() { return when.resolve(originalConfig); } - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { credentialsExtract.called.should.be.false; credentialsLoad.called.should.be.true; @@ -262,7 +262,7 @@ describe('flows/index', function() { done(); }); - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); }); @@ -277,7 +277,7 @@ describe('flows/index', function() { return when.resolve(originalConfig); } - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); flowCreate.called.should.be.false; @@ -295,7 +295,7 @@ describe('flows/index', function() { storage.getFlows = function() { return when.resolve(originalConfig); } - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); flowCreate.called.should.be.false; @@ -329,7 +329,7 @@ describe('flows/index', function() { storage.getFlows = function() { return when.resolve(originalConfig); } - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { var c = 0; flows.eachNode(function(node) { @@ -360,7 +360,7 @@ describe('flows/index', function() { done(); }); - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); }); @@ -391,7 +391,7 @@ describe('flows/index', function() { } }); - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); }); @@ -413,7 +413,7 @@ describe('flows/index', function() { done(); }); - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); }); @@ -445,7 +445,7 @@ describe('flows/index', function() { } }); - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.startFlows(); }); @@ -473,7 +473,7 @@ describe('flows/index', function() { {id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]}, {id:"t1",type:"tab"} ]; - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.setFlows(originalConfig).then(function() { flows.checkTypeInUse("unused-module"); done(); @@ -484,7 +484,7 @@ describe('flows/index', function() { {id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]}, {id:"t1",type:"tab"} ]; - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.setFlows(originalConfig).then(function() { /*jshint immed: false */ try { @@ -507,7 +507,7 @@ describe('flows/index', function() { storage.getFlows = function() { return when.resolve(originalConfig); } - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { flows.addFlow({ label:'new flow', @@ -534,7 +534,7 @@ describe('flows/index', function() { storage.setFlows = function() { return when.resolve(); } - flows.init({},storage); + flows.init({settings:{},storage:storage}); flows.load().then(function() { return flows.startFlows(); }).then(function() { diff --git a/test/red/runtime/storage/index_spec.js b/test/red/runtime/storage/index_spec.js index 268c4ea57..b7a5786de 100644 --- a/test/red/runtime/storage/index_spec.js +++ b/test/red/runtime/storage/index_spec.js @@ -22,7 +22,9 @@ describe("red/storage/index", function() { it('rejects the promise when settings suggest loading a bad module', function(done) { var wrongModule = { + settings:{ storageModule : "thisaintloading" + } }; storage.init(wrongModule).then( function() { @@ -42,13 +44,15 @@ describe("red/storage/index", function() { var initSetsMeToTrue = false; var moduleWithBooleanSettingInit = { - init : function() { - initSetsMeToTrue = true; - } + init : function() { + initSetsMeToTrue = true; + } }; var setsBooleanModule = { + settings: { storageModule : moduleWithBooleanSettingInit + } }; storage.init(setsBooleanModule); @@ -116,7 +120,9 @@ describe("red/storage/index", function() { }; var moduleToLoad = { - storageModule : interfaceCheckerModule + settings: { + storageModule : interfaceCheckerModule + } }; storage.init(moduleToLoad); @@ -172,7 +178,9 @@ describe("red/storage/index", function() { }; var moduleToLoad = { - storageModule : interfaceCheckerModule + settings: { + storageModule : interfaceCheckerModule + } }; before(function() { storage.init(moduleToLoad); @@ -220,7 +228,7 @@ describe("red/storage/index", function() { var interfaceCheckerModule = { init : function () {} }; - storage.init({storageModule: interfaceCheckerModule}); + storage.init({settings:{storageModule: interfaceCheckerModule}}); }); it('defaults missing getSettings',function(done) {