forked from ocelotconsulting/node-acme-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
29 lines (25 loc) · 914 Bytes
/
runner.js
File metadata and controls
29 lines (25 loc) · 914 Bytes
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
import generateCertificate from './libs/acme/generateCertificate';
import isExpired from './libs/util/isExpired';
import config from './config';
export async function main(event, context, callback) {
const singleCertificate = (key, domains) =>
isExpired(key)
.then(expired =>
(expired
? generateCertificate({ key, domains })
: {
err: false,
msg: `Certificate for ${key} is still valid, skipping renewal.`,
}
))
.catch(err => ({
err: true,
msg: `Updating cert for ${key}, received err ${err}, ${err.stack}`,
}));
const certificates = certificateDefinitions =>
Object.keys(certificateDefinitions)
.map(certKey =>
singleCertificate(certKey, certificateDefinitions[certKey]));
Promise.all(certificates(config['certificate-definitions']))
.then(msgs => context.succeed(msgs));
}