forked from roylines/node-credstash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
44 lines (37 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const async = require('async');
const decrypter = require('./lib/decrypter');
const encoder = require('./lib/encoder');
const hmac = require('./lib/hmac');
const keys = require('./lib/keys');
const secrets = require('./lib/secrets');
const xtend = require('xtend');
const defaults = {
limit: 1
};
function Credstash(config) {
this.table = config ? config.table : undefined;
this.awsConfig = config.awsConfig
}
Credstash.prototype.get = function(name, options, done) {
if (typeof options === 'function') {
done = options;
options = defaults;
} else {
options = xtend(defaults, options);
}
return async.waterfall([
async.apply(secrets.get, this.table, name, options, this.awsConfig),
async.apply(keys.decrypt(this.awsConfig)),
async.apply(hmac.check),
async.apply(decrypter.decrypt)
], function (err, secrets) {
if (err) {
return done(err);
}
if (options.limit === 1) {
return done(null, secrets && secrets[0]);
}
done(null, secrets);
});
};
module.exports = Credstash;