2017-03-21 05:29:03 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
directives: {
|
2017-03-22 15:48:04 +00:00
|
|
|
get: function (providerUri) {
|
2017-03-21 05:29:03 +00:00
|
|
|
// TODO make safe
|
|
|
|
try {
|
|
|
|
return require(path.join(process.cwd(), providerUri + '.directives.json'));
|
|
|
|
} catch(e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 15:48:04 +00:00
|
|
|
, set: function (providerUri, directives) {
|
2017-03-21 05:29:03 +00:00
|
|
|
fs.writeFileSync(path.join(process.cwd(), providerUri + '.directives.json'), JSON.stringify(directives, null, 2));
|
|
|
|
return directives;
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 07:02:41 +00:00
|
|
|
|
2017-03-22 15:48:04 +00:00
|
|
|
, sessions: {
|
|
|
|
get: function (providerUri, id) {
|
2017-03-21 07:02:41 +00:00
|
|
|
// TODO make safe
|
|
|
|
try {
|
2017-03-22 15:48:04 +00:00
|
|
|
if (id) {
|
|
|
|
return require(path.join(process.cwd(), providerUri + '.' + id + '.session.json'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return require(path.join(process.cwd(), providerUri + '.session.json'));
|
|
|
|
}
|
2017-03-21 07:02:41 +00:00
|
|
|
} catch(e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 15:48:04 +00:00
|
|
|
, set: function (providerUri, session, id) {
|
|
|
|
if (id) {
|
|
|
|
fs.writeFileSync(path.join(process.cwd(), providerUri + '.' + id + '.session.json'), JSON.stringify(session, null, 2));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fs.writeFileSync(path.join(process.cwd(), providerUri + '.session.json'), JSON.stringify(session, null, 2));
|
|
|
|
}
|
2017-03-21 07:02:41 +00:00
|
|
|
return session;
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 05:29:03 +00:00
|
|
|
};
|