mirror of
https://github.com/certd/certd.git
synced 2026-04-28 07:57:25 +08:00
fix: 阿里云esa查询证书限制接口无效,改成配置证书数量上限检查方式进行清理
This commit is contained in:
@@ -91,17 +91,17 @@ export class AliyunDeployCertToESA extends AbstractTaskPlugin {
|
|||||||
siteIds!: string[];
|
siteIds!: string[];
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: "是否免费版",
|
title: "免费证书数量限制",
|
||||||
value: true,
|
value: 2,
|
||||||
component: {
|
component: {
|
||||||
name: "a-switch",
|
name: "a-input-number",
|
||||||
vModel: "value"
|
vModel: "value"
|
||||||
},
|
},
|
||||||
helper: "如果是免费站点,将检查证书数量限制,如果超限将删除最旧的那张证书",
|
helper: "将检查证书数量限制,如果超限将删除最旧的那张证书",
|
||||||
required: true
|
required: true
|
||||||
})
|
})
|
||||||
|
|
||||||
isFree: boolean;
|
certLimit: number = 2;
|
||||||
|
|
||||||
|
|
||||||
async onInstance() {
|
async onInstance() {
|
||||||
@@ -138,42 +138,40 @@ export class AliyunDeployCertToESA extends AbstractTaskPlugin {
|
|||||||
|
|
||||||
const client = await this.getClient(access);
|
const client = await this.getClient(access);
|
||||||
|
|
||||||
const { certId, certName } = await this.getAliyunCertId(access);
|
// const { certId, certName } = await this.getAliyunCertId(access);
|
||||||
|
|
||||||
for (const siteId of this.siteIds) {
|
for (const siteId of this.siteIds) {
|
||||||
if (this.isFree) {
|
await this.clearSiteLimitCert(client, siteId);
|
||||||
await this.clearSiteLimitCert(client, siteId);
|
// try {
|
||||||
}
|
// const res = await client.doRequest({
|
||||||
try {
|
// // 接口名称
|
||||||
const res = await client.doRequest({
|
// action: "SetCertificate",
|
||||||
// 接口名称
|
// // 接口版本
|
||||||
action: "SetCertificate",
|
// version: "2024-09-10",
|
||||||
// 接口版本
|
// data: {
|
||||||
version: "2024-09-10",
|
// body: {
|
||||||
data: {
|
// SiteId: siteId,
|
||||||
body: {
|
// CasId: certId,
|
||||||
SiteId: siteId,
|
// Type: "cas",
|
||||||
CasId: certId,
|
// Name: certName
|
||||||
Type: "cas",
|
// }
|
||||||
Name: certName
|
// }
|
||||||
}
|
// });
|
||||||
}
|
// this.logger.info(`部署站点[${siteId}]证书成功:${JSON.stringify(res)}`);
|
||||||
});
|
|
||||||
this.logger.info(`部署站点[${siteId}]证书成功:${JSON.stringify(res)}`);
|
|
||||||
|
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
if (e.message.includes("Certificate.Duplicated")) {
|
// if (e.message.includes("Certificate.Duplicated")) {
|
||||||
this.logger.info(`站点[${siteId}]证书已存在,无需重复部署`);
|
// this.logger.info(`站点[${siteId}]证书已存在,无需重复部署`);
|
||||||
} else {
|
// } else {
|
||||||
throw e;
|
// throw e;
|
||||||
}
|
// }
|
||||||
} finally {
|
// } finally {
|
||||||
try {
|
// try {
|
||||||
await this.clearSiteExpiredCert(client, siteId);
|
// await this.clearSiteExpiredCert(client, siteId);
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
this.logger.error(`清理站点[${siteId}]过期证书失败`, e)
|
// this.logger.error(`清理站点[${siteId}]过期证书失败`, e)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,25 +252,9 @@ export class AliyunDeployCertToESA extends AbstractTaskPlugin {
|
|||||||
|
|
||||||
|
|
||||||
async clearSiteLimitCert(client: AliyunClientV2, siteId: string) {
|
async clearSiteLimitCert(client: AliyunClientV2, siteId: string) {
|
||||||
const res = await client.doRequest({
|
|
||||||
action: "GetCertificateQuota",
|
|
||||||
version: "2024-09-10",
|
|
||||||
method: "GET",
|
|
||||||
data: {
|
|
||||||
query: {
|
|
||||||
SiteId: siteId,
|
|
||||||
Type: "free"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.logger.info(`站点[${siteId}]证书限制情况, 限制${res.Quota} ,已使用${res.QuotaUsage}`);
|
|
||||||
|
|
||||||
if (res.QuotaUsage < res.Quota) {
|
|
||||||
this.logger.info(`站点[${siteId}]证书未超限制, 无需删除`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//删除最旧的证书
|
//删除最旧的证书
|
||||||
this.logger.info(`站点[${siteId}]证书已超限制, 开始删除最旧的证书`);
|
this.logger.info(`站点[${siteId}]证书数量检查,当前限制${this.certLimit}`);
|
||||||
const certListRes = await client.doRequest({
|
const certListRes = await client.doRequest({
|
||||||
action: "ListCertificates",
|
action: "ListCertificates",
|
||||||
version: "2024-09-10",
|
version: "2024-09-10",
|
||||||
@@ -290,6 +272,12 @@ export class AliyunDeployCertToESA extends AbstractTaskPlugin {
|
|||||||
this.logger.info(`站点[${siteId}]没有证书, 无需删除`);
|
this.logger.info(`站点[${siteId}]没有证书, 无需删除`);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (list.length < this.certLimit) {
|
||||||
|
this.logger.info(`站点[${siteId}]证书数量(${list.length})未超限制, 无需删除`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.logger.info(`站点[${siteId}]证书数量(${list.length})已超限制, 开始删除最旧的证书`);
|
||||||
|
|
||||||
let oldly:any = null;
|
let oldly:any = null;
|
||||||
for (const item of list) {
|
for (const item of list) {
|
||||||
if (!oldly) {
|
if (!oldly) {
|
||||||
|
|||||||
Reference in New Issue
Block a user