2019-03-07 06:18:26 +00:00
|
|
|
'use strict';
|
2019-03-09 12:05:37 +00:00
|
|
|
/*global Promise*/
|
2019-03-07 06:18:26 +00:00
|
|
|
|
|
|
|
var fs = require('fs').promises;
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
module.exports.create = function (opts) {
|
2019-03-09 12:05:37 +00:00
|
|
|
var keyext = '.key';
|
2019-03-07 06:18:26 +00:00
|
|
|
return {
|
|
|
|
getPassword: function (service, name) {
|
2019-03-09 12:05:37 +00:00
|
|
|
var f = path.join(opts.configDir, name + keyext);
|
2019-03-07 06:18:26 +00:00
|
|
|
return fs.readFile(f, 'utf8').catch(function (err) {
|
|
|
|
if ('ENOEXIST' === err.code) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
, setPassword: function (service, name, key) {
|
2019-03-09 12:05:37 +00:00
|
|
|
var f = path.join(opts.configDir, name + keyext);
|
2019-03-07 06:18:26 +00:00
|
|
|
return fs.writeFile(f, key, 'utf8');
|
|
|
|
}
|
|
|
|
, deletePassword: function (service, name) {
|
2019-03-09 12:05:37 +00:00
|
|
|
var f = path.join(opts.configDir, name + keyext);
|
2019-03-07 06:18:26 +00:00
|
|
|
return fs.unlink(f);
|
|
|
|
}
|
2019-03-09 12:05:37 +00:00
|
|
|
, findCredentials: function (/*service*/) {
|
2019-05-12 05:40:22 +00:00
|
|
|
return fs.readdir(opts.configDir).then(function (nodes) {
|
2019-03-09 12:05:37 +00:00
|
|
|
return Promise.all(nodes.filter(function (node) {
|
|
|
|
return keyext === node.slice(-4);
|
|
|
|
}).map(function (node) {
|
2019-05-12 06:10:58 +00:00
|
|
|
return fs.readFile(path.join(opts.configDir, node), 'utf8').then(function (data) {
|
|
|
|
return { password: data };
|
|
|
|
});
|
2019-03-09 12:05:37 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
2019-03-07 06:18:26 +00:00
|
|
|
, insecure: true
|
|
|
|
};
|
|
|
|
};
|