certs: show daysLeft in the logs

This commit is contained in:
Girish Ramakrishnan
2021-06-24 00:48:54 -07:00
parent 7d3270e51a
commit 6da7218d34
2 changed files with 7 additions and 4 deletions

View File

@@ -105,9 +105,12 @@ function getExpiryDate(certFilePath) {
if (!result) return null; // some error
const notAfter = result.stdout.toString('utf8').trim().split('=')[1];
debug(`expiryDate: ${certFilePath} notAfter=${notAfter}`);
const notAfterDate = new Date(notAfter);
return new Date(notAfter);
const daysLeft = (notAfterDate - new Date())/(24 * 60 * 60 * 1000);
debug(`expiryDate: ${certFilePath} notAfter=${notAfter} daysLeft=${daysLeft}`);
return notAfterDate;
}
// We used to check for the must-staple in the cert using openssl x509 -text -noout -in ${certFilePath} | grep -q status_request
@@ -422,7 +425,7 @@ function ensureCertificate(vhost, domain, auditSource, callback) {
if (currentBundle) {
debug(`ensureCertificate: ${vhost} certificate already exists at ${currentBundle.keyFilePath}`);
notAfter = getExpiryDate(currentBundle.certFilePath);
const isExpiring = (notAfter - new Date()) <= (60 * 60 * 24 * 30 * 1000); // expiring in a month
const isExpiring = (notAfter - new Date()) <= (30 * 24 * 60 * 60 * 1000); // expiring in a month
if (!isExpiring && providerMatchesSync(domainObject, currentBundle.certFilePath, apiOptions)) return callback(null, currentBundle, { renewed: false });
debug(`ensureCertificate: ${vhost} cert requires renewal`);
} else {