mirror of
https://github.com/certd/certd.git
synced 2026-04-25 05:07:25 +08:00
perf: doge云支持删除过期证书
This commit is contained in:
@@ -1,16 +1,18 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import querystring from 'querystring';
|
import querystring from 'querystring';
|
||||||
import { DogeCloudAccess } from '../access.js';
|
import { DogeCloudAccess } from '../access.js';
|
||||||
import { HttpClient } from '@certd/basic';
|
import { HttpClient, ILogger } from '@certd/basic';
|
||||||
|
|
||||||
export class DogeClient {
|
export class DogeClient {
|
||||||
accessKey: string;
|
accessKey: string;
|
||||||
secretKey: string;
|
secretKey: string;
|
||||||
http: HttpClient;
|
http: HttpClient;
|
||||||
constructor(access: DogeCloudAccess, http: HttpClient) {
|
logger: ILogger;
|
||||||
|
constructor(access: DogeCloudAccess, http: HttpClient,logger: ILogger) {
|
||||||
this.accessKey = access.accessKey;
|
this.accessKey = access.accessKey;
|
||||||
this.secretKey = access.secretKey;
|
this.secretKey = access.secretKey;
|
||||||
this.http = http;
|
this.http = http;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
async request(apiPath: string, data: any = {}, jsonMode = false, ignoreResNullCode = false) {
|
async request(apiPath: string, data: any = {}, jsonMode = false, ignoreResNullCode = false) {
|
||||||
@@ -36,6 +38,7 @@ export class DogeClient {
|
|||||||
|
|
||||||
if (res.code == null && ignoreResNullCode) {
|
if (res.code == null && ignoreResNullCode) {
|
||||||
//ignore
|
//ignore
|
||||||
|
this.logger.warn('执行出错:', res);
|
||||||
} else if (res.code !== 200) {
|
} else if (res.code !== 200) {
|
||||||
throw new Error('API Error: ' + res.msg);
|
throw new Error('API Error: ' + res.msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin {
|
|||||||
|
|
||||||
async onInstance() {
|
async onInstance() {
|
||||||
const access = await this.getAccess(this.accessId);
|
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> {
|
async execute(): Promise<void> {
|
||||||
const certId: number = await this.updateCert();
|
const certId: number = await this.updateCert();
|
||||||
@@ -81,7 +81,10 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin {
|
|||||||
this.ctx.logger.info(`绑定证书${certId}到域名${domain}`);
|
this.ctx.logger.info(`绑定证书${certId}到域名${domain}`);
|
||||||
await this.bindCert(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() {
|
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 = {}) {
|
async onGetDomainList(data: PageSearch = {}) {
|
||||||
const res = await this.dogeClient.request(
|
const res = await this.dogeClient.request(
|
||||||
|
|||||||
Reference in New Issue
Block a user