forked from ocelotconsulting/node-acme-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (27 loc) · 859 Bytes
/
app.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
const generateCertificate = require('./src/acme/generateCertificate')
const isExpired = require('./src/util/isExpired')
const config = require('./config')
const single = (key, domains) =>
isExpired(key)
.then((expired) =>
(expired
? generateCertificate({key, domains})
: {
err: false,
msg: `Certificate for ${key} is still valid, going back to bed.`
}
)
)
.catch((err) => ({
err: true,
msg: `Updating cert for ${key}, received err ${err}, ${err.stack}`
}))
const certificates = (certDefinitions) =>
Object.keys(certDefinitions)
.map((certKey) =>
single(certKey, certDefinitions[certKey])
)
const updateCertificates = (options, context) =>
Promise.all(certificates(config['certificate-info']))
.then((msgs) => context.succeed(msgs))
module.exports = { handler: updateCertificates }