mirror of https://github.com/certd/certd
				
				
				
			perf: esa 自动删除过期证书提示
							parent
							
								
									911e69e3bc
								
							
						
					
					
						commit
						8bf1f828b9
					
				| 
						 | 
					@ -12,7 +12,7 @@ import {
 | 
				
			||||||
  title: "阿里云-部署至ESA",
 | 
					  title: "阿里云-部署至ESA",
 | 
				
			||||||
  icon: "svg:icon-aliyun",
 | 
					  icon: "svg:icon-aliyun",
 | 
				
			||||||
  group: pluginGroups.aliyun.key,
 | 
					  group: pluginGroups.aliyun.key,
 | 
				
			||||||
  desc: "部署证书到阿里云ESA(边缘安全加速)",
 | 
					  desc: "部署证书到阿里云ESA(边缘安全加速),自动删除过期证书",
 | 
				
			||||||
  needPlus: false,
 | 
					  needPlus: false,
 | 
				
			||||||
  default: {
 | 
					  default: {
 | 
				
			||||||
    strategy: {
 | 
					    strategy: {
 | 
				
			||||||
| 
						 | 
					@ -125,6 +125,7 @@ export class AliyunDeployCertToESA extends AbstractTaskPlugin {
 | 
				
			||||||
    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) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
        const res = await client.doRequest({
 | 
					        const res = await client.doRequest({
 | 
				
			||||||
          // 接口名称
 | 
					          // 接口名称
 | 
				
			||||||
| 
						 | 
					@ -159,6 +160,7 @@ export class AliyunDeployCertToESA extends AbstractTaskPlugin {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async getClient(access: AliyunAccess) {
 | 
					  async getClient(access: AliyunAccess) {
 | 
				
			||||||
    const endpoint = `esa.${this.regionId}.aliyuncs.com`;
 | 
					    const endpoint = `esa.${this.regionId}.aliyuncs.com`;
 | 
				
			||||||
    return access.getClient(endpoint);
 | 
					    return access.getClient(endpoint);
 | 
				
			||||||
| 
						 | 
					@ -211,19 +213,24 @@ export class AliyunDeployCertToESA extends AbstractTaskPlugin {
 | 
				
			||||||
      this.logger.info(`证书${item.Name}状态:${item.Status}`);
 | 
					      this.logger.info(`证书${item.Name}状态:${item.Status}`);
 | 
				
			||||||
      if (item.Status === "Expired") {
 | 
					      if (item.Status === "Expired") {
 | 
				
			||||||
        this.logger.info(`证书${item.Name}已过期,执行删除`);
 | 
					        this.logger.info(`证书${item.Name}已过期,执行删除`);
 | 
				
			||||||
        await client.doRequest({
 | 
					        try{
 | 
				
			||||||
          action: "DeleteCertificate",
 | 
					          await client.doRequest({
 | 
				
			||||||
          version: "2024-09-10",
 | 
					            action: "DeleteCertificate",
 | 
				
			||||||
          // 接口 HTTP 方法
 | 
					            version: "2024-09-10",
 | 
				
			||||||
          method: "GET",
 | 
					            // 接口 HTTP 方法
 | 
				
			||||||
           data:{
 | 
					            method: "GET",
 | 
				
			||||||
             query: {
 | 
					            data:{
 | 
				
			||||||
               SiteId: siteId,
 | 
					              query: {
 | 
				
			||||||
               Id: item.id
 | 
					                SiteId: siteId,
 | 
				
			||||||
             }
 | 
					                Id: item.id
 | 
				
			||||||
           }
 | 
					              }
 | 
				
			||||||
        });
 | 
					            }
 | 
				
			||||||
        this.logger.info(`证书${item.Name}已删除`);
 | 
					          });
 | 
				
			||||||
 | 
					          this.logger.info(`证书${item.Name}已删除`);
 | 
				
			||||||
 | 
					        }catch (e) {
 | 
				
			||||||
 | 
					          this.logger.error(`过期证书${item.Name}删除失败:`,e.message)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue