Skip to content
This repository was archived by the owner on Aug 21, 2019. It is now read-only.

Commit adacd72

Browse files
committed
remove dependency to moment
1 parent 1be80c8 commit adacd72

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

lib.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const ms = require('ms');
66
const request = require('request-promise');
77
const xtend = require('xtend');
88
const pki = require('node-forge').pki;
9-
const moment = require('moment');
109
const path = require('path');
1110
const { URL } = require('url');
1211

13-
const EXPIRATION_IN_DAYS = 30;
12+
const DEFAULT_EXPIRATION = '30 days';
13+
const DEFAULT_EXPIRATION_IN_MS = ms(DEFAULT_EXPIRATION);
1414

1515
const generateRsa = () => RSA.generateKeypairAsync(2048, 65537, {});
1616

@@ -106,12 +106,9 @@ module.exports = (options) => {
106106
if (options.domain.includes(pagesDomain.domain)) {
107107
if (pagesDomain.certificate) {
108108
if (!pagesDomain.certificate.expired) {
109-
const certificate = pki.certificateFromPem(pagesDomain.certificate.certificate);
110-
const validUntil = moment(certificate.validity.notAfter);
111-
const diff = validUntil.diff(moment(), 'days');
112-
if (diff > EXPIRATION_IN_DAYS) {
113-
return true;
114-
}
109+
const validUntil = pki.certificateFromPem(pagesDomain.certificate.certificate).validity.notAfter;
110+
const expiresInMS = validUntil.getTime() - new Date().getTime();
111+
return expiresInMS > DEFAULT_EXPIRATION_IN_MS;
115112
}
116113
}
117114
return false;
@@ -139,7 +136,7 @@ module.exports = (options) => {
139136
pagesDomains.every(hasValidCertificate);
140137

141138
if (needsNoRenewal) {
142-
console.log(`All domains (${options.domain.join(', ')}) have a valid certificate (expiration in more than ${EXPIRATION_IN_DAYS} days)`);
139+
console.log(`All domains (${options.domain.join(', ')}) have a valid certificate (expiration in more than ${DEFAULT_EXPIRATION})`);
143140
process.exit(0);
144141
}
145142

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"dependencies": {
1010
"bluebird": "3.5.0",
1111
"le-acme-core": "https://git.daplie.com/rolodato/le-acme-core/repository/archive.tar.gz",
12-
"moment": "^2.20.1",
1312
"ms": "2.0.0",
1413
"node-forge": "0.7.1",
1514
"request": "2.81.0",

0 commit comments

Comments
 (0)