telebit.js/lib/keystore-fallback.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
2019-03-09 12:05:37 +00:00
/*global Promise*/
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';
return {
getPassword: function (service, name) {
2019-03-09 12:05:37 +00:00
var f = path.join(opts.configDir, name + keyext);
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);
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);
return fs.unlink(f);
}
2019-03-09 12:05:37 +00:00
, findCredentials: function (/*service*/) {
return fs.readDir(opts.configDir).then(function (nodes) {
return Promise.all(nodes.filter(function (node) {
return keyext === node.slice(-4);
}).map(function (node) {
return fs.readFile(path.join(opts.configDir, node + keyext));
}));
});
}
, insecure: true
};
};