Move sessionStorageModule into main storageModule

Fixes #586

 - add get/saveSessions to main storage module
 - handle storage modules without those functions
 - store .session file in userDir
This commit is contained in:
Nick O'Leary
2015-03-13 23:37:59 +00:00
parent 731efe1c01
commit 51e891ff88
14 changed files with 243 additions and 517 deletions

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2013, 2014 IBM Corp.
* Copyright 2013, 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ var storageModuleInterface = {
try {
storageModule = moduleSelector(settings);
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
sessionsAvailable = storageModule.hasOwnProperty("getUserSessions") && storageModule.hasOwnProperty("saveUserSessions");
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
} catch (e) {
return when.reject(e);
}
@@ -76,6 +76,20 @@ var storageModuleInterface = {
return when.resolve();
}
},
getSessions: function() {
if (sessionsAvailable) {
return storageModule.getSessions();
} else {
return when.resolve(null);
}
},
saveSessions: function(sessions) {
if (sessionsAvailable) {
return storageModule.saveSessions(sessions);
} else {
return when.resolve();
}
},
/* Library Functions */
getAllFlows: function() {

View File

@@ -32,6 +32,7 @@ var flowsFileBackup;
var credentialsFile;
var credentialsFileBackup;
var oldCredentialsFile;
var sessionsFile;
var libDir;
var libFlowsDir;
var globalSettingsFile;
@@ -191,6 +192,8 @@ var localfilesystem = {
flowsFileBackup = fspath.join(ffDir,"."+ffName+".backup");
sessionsFile = fspath.join(settings.userDir,".sessions.json");
libDir = fspath.join(settings.userDir,"lib");
libFlowsDir = fspath.join(libDir,"flows");
@@ -288,6 +291,26 @@ var localfilesystem = {
saveSettings: function(settings) {
return writeFile(globalSettingsFile,JSON.stringify(settings,null,1));
},
getSessions: function() {
if (fs.existsSync(sessionsFile)) {
return nodeFn.call(fs.readFile,sessionsFile,'utf8').then(function(data) {
if (data) {
try {
return JSON.parse(data);
} catch(err) {
log.info("Corrupted sessions file - resetting");
return {};
}
} else {
return {};
}
});
}
return when.resolve({});
},
saveSessions: function(sessions) {
return writeFile(sessionsFile,JSON.stringify(sessions));
},
getAllFlows: function() {
return listFiles(libFlowsDir);