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

Commit b7cf54c

Browse files
committed
reduce complexity of hasValidCertificate
1 parent 5fe13f0 commit b7cf54c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,12 @@ module.exports = (options) => {
103103
};
104104

105105
const hasValidCertificate = (pagesDomain) => {
106-
if (options.domain.includes(pagesDomain.domain)) {
107-
if (pagesDomain.certificate) {
108-
if (!pagesDomain.certificate.expired) {
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;
112-
}
113-
}
114-
return false;
106+
if (pagesDomain.certificate && !pagesDomain.certificate.expired) {
107+
const validUntil = pki.certificateFromPem(pagesDomain.certificate.certificate).validity.notAfter;
108+
const expiresInMS = validUntil.getTime() - new Date().getTime();
109+
return expiresInMS > DEFAULT_EXPIRATION_IN_MS;
115110
}
116-
// We do not care about the current domain, as we did not give it in the arguments
117-
return true;
111+
return false;
118112
};
119113

120114
const createPagesDomains = (repo) => {
@@ -130,10 +124,14 @@ module.exports = (options) => {
130124
return !pagesDomainsNames.includes(domain);
131125
});
132126

127+
const domainsToCheck = pagesDomains.filter(pagesDomain => {
128+
return options.domain.includes(pagesDomain.domain);
129+
});
130+
133131
const needsNoRenewal =
134132
!options.forceRenewal &&
135133
domainsToCreate.length === 0 &&
136-
pagesDomains.every(hasValidCertificate);
134+
domainsToCheck.every(hasValidCertificate);
137135

138136
if (needsNoRenewal) {
139137
console.log(`All domains (${options.domain.join(', ')}) have a valid certificate (expiration in more than ${DEFAULT_EXPIRATION})`);

0 commit comments

Comments
 (0)