forked from daguej/le-store-mongoz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (50 loc) · 1.63 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
45
46
47
48
49
50
51
52
53
54
exports.create = function(db) {
var store = {};
const accounts = db.collection('domains-le-accounts')
const certs = db.collection('domains-le-certs')
store.accounts = {
setKeypair: function(opts) {
var id = (opts.account && opts.account.id) || opts.email || 'default';
return accounts.updateOne({ id: id }, { $set: {
id: id,
privateKeyPem: opts.keypair.privateKeyPem,
privateKeyJwk: opts.keypair.privateKeyJwk
}}, { upsert: true });
},
checkKeypair: function(opts) {
var id = (opts.account && opts.account.id) || opts.email || 'default';
return accounts.findOne({ id: id });
}
};
store.certificates = {
setKeypair: function(opts) {
var id = (opts.certificate && (opts.certificate.kid || opts.certificate.id)) || opts.subject;
return certs.updateOne({ id: id }, { $set: {
id: id,
privateKeyPem: opts.keypair.privateKeyPem,
privateKeyJwk: opts.keypair.privateKeyJwk
}}, { upsert: true });
},
checkKeypair: function(opts) {
var id = (opts.certificate && (opts.certificate.kid || opts.certificate.id)) || opts.subject;
return certs.findOne({ id: id });
},
set: function(opts) {
var id = (opts.certificate && opts.certificate.id) || opts.subject;
return certs.updateOne({ id: id }, { $set: {
id: id,
cert: opts.pems.cert,
chain: opts.pems.chain,
subject: opts.pems.subject,
altnames: opts.pems.altnames,
issuedAt: opts.pems.issuedAt,
expiresAt: opts.pems.expiresAt
}}, { upsert: true });
},
check: function(opts) {
var id = (opts.certificate && opts.certificate.id) || opts.subject;
return certs.findOne({ id: id });
}
};
return store;
};