refactor: huawei

This commit is contained in:
xiaojunnuo
2023-05-09 13:52:25 +08:00
parent 9747d40734
commit d2897cefaa
8 changed files with 128 additions and 77 deletions

View File

@@ -181,6 +181,17 @@ export class CertApplyPlugin implements ITaskPlugin {
if (this.forceUpdate) {
return null;
}
let inputChanged = false;
const inputCacheKey = "input.cert";
const oldInputStr = await this.pipelineContext.get(inputCacheKey);
await this.pipelineContext.set(inputCacheKey, this.cert);
const oldInput = JSON.stringify(oldInputStr);
const thisInput = JSON.stringify(this.cert);
if (oldInput !== thisInput) {
inputChanged = true;
}
let oldCert;
try {
oldCert = await this.readCurrentCert();
@@ -192,6 +203,11 @@ export class CertApplyPlugin implements ITaskPlugin {
return null;
}
if (inputChanged) {
this.logger.info("输入参数变更,申请新证书");
return null;
}
const ret = this.isWillExpire(oldCert.expires, this.renewDays);
if (!ret.isWillExpire) {
this.logger.info(`证书还未过期:过期时间${dayjs(oldCert.expires).format("YYYY-MM-DD HH:mm:ss")},剩余${ret.leftDays}`);
@@ -261,6 +277,9 @@ export class CertApplyPlugin implements ITaskPlugin {
csr: this.formatCert(cert.csr),
};
await this.pipelineContext.set("cert", newCert);
await this.pipelineContext.set("cert.crt", newCert.crt);
await this.pipelineContext.set("cert.key", newCert.key);
await this.pipelineContext.set("cert.csr", newCert.csr);
}
async readCurrentCert() {