mirror of
https://github.com/certd/certd.git
synced 2025-11-25 09:10:11 +08:00
perf: doge云支持删除过期证书
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import crypto from 'crypto';
|
||||
import querystring from 'querystring';
|
||||
import { DogeCloudAccess } from '../access.js';
|
||||
import { HttpClient } from '@certd/basic';
|
||||
import { HttpClient, ILogger } from '@certd/basic';
|
||||
|
||||
export class DogeClient {
|
||||
accessKey: string;
|
||||
secretKey: string;
|
||||
http: HttpClient;
|
||||
constructor(access: DogeCloudAccess, http: HttpClient) {
|
||||
logger: ILogger;
|
||||
constructor(access: DogeCloudAccess, http: HttpClient,logger: ILogger) {
|
||||
this.accessKey = access.accessKey;
|
||||
this.secretKey = access.secretKey;
|
||||
this.http = http;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
async request(apiPath: string, data: any = {}, jsonMode = false, ignoreResNullCode = false) {
|
||||
@@ -36,6 +38,7 @@ export class DogeClient {
|
||||
|
||||
if (res.code == null && ignoreResNullCode) {
|
||||
//ignore
|
||||
this.logger.warn('执行出错:', res);
|
||||
} else if (res.code !== 200) {
|
||||
throw new Error('API Error: ' + res.msg);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin {
|
||||
|
||||
async onInstance() {
|
||||
const access = await this.getAccess(this.accessId);
|
||||
this.dogeClient = new DogeClient(access, this.ctx.http);
|
||||
this.dogeClient = new DogeClient(access, this.ctx.http, this.ctx.logger);
|
||||
}
|
||||
async execute(): Promise<void> {
|
||||
const certId: number = await this.updateCert();
|
||||
@@ -81,7 +81,10 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin {
|
||||
this.ctx.logger.info(`绑定证书${certId}到域名${domain}`);
|
||||
await this.bindCert(certId,domain);
|
||||
}
|
||||
this.logger.info("执行完成")
|
||||
this.logger.info("执行完成,3秒后删除过期证书");
|
||||
|
||||
await this.ctx.utils.sleep(3000);
|
||||
await this.clearExpiredCert();
|
||||
}
|
||||
|
||||
async updateCert() {
|
||||
@@ -104,6 +107,24 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
async clearExpiredCert() {
|
||||
const res = await this.dogeClient.request(
|
||||
'/cdn/cert/list.json',
|
||||
{},
|
||||
);
|
||||
const list = res.certs?.filter((item: any) => item.expire < dayjs().unix() && item.domainCount === 0) || [];
|
||||
for (const item of list) {
|
||||
this.ctx.logger.info(`删除过期证书${item.id}->${item.domain}`);
|
||||
await this.dogeClient.request(
|
||||
'/cdn/cert/delete.json',
|
||||
{
|
||||
id: item.id,
|
||||
},
|
||||
this.ignoreDeployNullCode
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async onGetDomainList(data: PageSearch = {}) {
|
||||
const res = await this.dogeClient.request(
|
||||
|
||||
Reference in New Issue
Block a user