mirror of
https://github.com/certd/certd.git
synced 2026-04-26 13:48:07 +08:00
perf: 当ip证书天数太小时,自动调整更新天数,避免每次运行都重新申请ip证书
This commit is contained in:
@@ -90,7 +90,7 @@ const preferredChainMergeScript = (() => {
|
|||||||
desc: "免费通配符域名证书申请,支持多个域名打到同一个证书上",
|
desc: "免费通配符域名证书申请,支持多个域名打到同一个证书上",
|
||||||
default: {
|
default: {
|
||||||
input: {
|
input: {
|
||||||
renewDays: 18,
|
renewDays: 15,
|
||||||
forceUpdate: false,
|
forceUpdate: false,
|
||||||
},
|
},
|
||||||
strategy: {
|
strategy: {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export abstract class CertApplyBasePlugin extends CertApplyBaseConvertPlugin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ret = this.isWillExpire(oldCert.expires, this.renewDays);
|
const ret = this.isWillExpire(oldCert, this.renewDays);
|
||||||
if (!ret.isWillExpire) {
|
if (!ret.isWillExpire) {
|
||||||
this.logger.info(`证书还未过期:过期时间${dayjs(oldCert.expires).format("YYYY-MM-DD HH:mm:ss")},剩余${ret.leftDays}天`);
|
this.logger.info(`证书还未过期:过期时间${dayjs(oldCert.expires).format("YYYY-MM-DD HH:mm:ss")},剩余${ret.leftDays}天`);
|
||||||
return oldCert;
|
return oldCert;
|
||||||
@@ -135,13 +135,27 @@ export abstract class CertApplyBasePlugin extends CertApplyBaseConvertPlugin {
|
|||||||
* @param expires
|
* @param expires
|
||||||
* @param maxDays
|
* @param maxDays
|
||||||
*/
|
*/
|
||||||
isWillExpire(expires: number, maxDays = 20) {
|
isWillExpire(cert: CertReader, maxDays = 15) {
|
||||||
if (expires == null) {
|
const expires = cert.expires;
|
||||||
|
if (expires == null) {
|
||||||
throw new Error("过期时间不能为空");
|
throw new Error("过期时间不能为空");
|
||||||
}
|
}
|
||||||
// 检查有效期
|
const begin = dayjs(cert.detail?.notBefore )
|
||||||
|
|
||||||
|
//证书总天数
|
||||||
|
const totalDays = Math.floor((expires - begin.valueOf()) / (1000 * 60 * 60 * 24));
|
||||||
|
// 检查有效期
|
||||||
const leftDays = Math.floor((expires - dayjs().valueOf()) / (1000 * 60 * 60 * 24));
|
const leftDays = Math.floor((expires - dayjs().valueOf()) / (1000 * 60 * 60 * 24));
|
||||||
this.logger.info(`证书剩余天数:${leftDays}`);
|
this.logger.info(`证书有效期剩余天数:${leftDays}`);
|
||||||
|
if(totalDays < maxDays){
|
||||||
|
this.logger.warn(`当前更新到期前天数为${maxDays},证书总天数${totalDays},总天数小于更新到期前天数`);
|
||||||
|
maxDays = Math.floor(totalDays/2);
|
||||||
|
if(maxDays < 2){
|
||||||
|
maxDays = 2;
|
||||||
|
}
|
||||||
|
this.logger.warn(`为避免每次运行都更新证书,更新天数自动减半,调整为${maxDays}`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isWillExpire: leftDays <= maxDays,
|
isWillExpire: leftDays <= maxDays,
|
||||||
leftDays,
|
leftDays,
|
||||||
|
|||||||
Reference in New Issue
Block a user