perf: http校验方式,支持七牛云oss、阿里云oss、腾讯云cos

This commit is contained in:
xiaojunnuo
2025-01-04 01:45:24 +08:00
parent 297d09c5ad
commit 3f74d4d9e5
23 changed files with 385 additions and 73 deletions
@@ -1,75 +0,0 @@
import { TencentAccess } from '@certd/plugin-lib';
import { CertInfo } from '@certd/plugin-cert';
import { ILogger } from '@certd/basic';
export class TencentSslClient {
access: TencentAccess;
logger: ILogger;
region?: string;
constructor(opts: { access: TencentAccess; logger: ILogger; region?: string }) {
this.access = opts.access;
this.logger = opts.logger;
this.region = opts.region;
}
async getSslClient(): Promise<any> {
const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/ssl/v20191205/index.js');
const SslClient = sdk.v20191205.Client;
const clientConfig = {
credential: {
secretId: this.access.secretId,
secretKey: this.access.secretKey,
},
region: this.region,
profile: {
httpProfile: {
endpoint: 'ssl.tencentcloudapi.com',
},
},
};
return new SslClient(clientConfig);
}
checkRet(ret: any) {
if (!ret || ret.Error) {
throw new Error('请求失败:' + ret.Error.Code + ',' + ret.Error.Message);
}
}
async uploadToTencent(opts: { certName: string; cert: CertInfo }): Promise<string> {
const client = await this.getSslClient();
const params = {
CertificatePublicKey: opts.cert.crt,
CertificatePrivateKey: opts.cert.key,
Alias: opts.certName,
};
const ret = await client.UploadCertificate(params);
this.checkRet(ret);
this.logger.info('证书上传成功:tencentCertId=', ret.CertificateId);
return ret.CertificateId;
}
async deployCertificateInstance(params: any) {
const client = await this.getSslClient();
const res = await client.DeployCertificateInstance(params);
this.checkRet(res);
return res;
}
async DescribeCertificates(params: any) {
const client = await this.getSslClient();
const res = await client.DescribeCertificates(params);
this.checkRet(res);
return res;
}
async doRequest(action: string, params: any) {
const client = await this.getSslClient();
if (!client[action]) {
throw new Error(`action ${action} not found`);
}
const res = await client[action](params);
this.checkRet(res);
return res;
}
}
@@ -1,9 +1,8 @@
import { IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
import { AbstractPlusTaskPlugin } from '@certd/plugin-plus';
import { TencentSslClient } from '../../lib/index.js';
import dayjs from 'dayjs';
import { remove } from 'lodash-es';
import { TencentAccess } from '@certd/plugin-lib';
import { TencentAccess, TencentSslClient } from '@certd/plugin-lib';
@IsTaskPlugin({
name: 'TencentDeleteExpiringCert',
@@ -1,8 +1,7 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
import { CertInfo } from '@certd/plugin-cert';
import { TencentSslClient } from '../../lib/index.js';
import { createRemoteSelectInputDefine } from '@certd/plugin-lib';
import { TencentAccess } from '@certd/plugin-lib';
import { TencentAccess, TencentSslClient } from '@certd/plugin-lib';
@IsTaskPlugin({
name: 'TencentDeployCertToCDNv2',
title: '腾讯云-部署到CDN-v2',
@@ -1,7 +1,6 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
import { CertInfo } from '@certd/plugin-cert';
import { createRemoteSelectInputDefine } from '@certd/plugin-lib';
import { TencentSslClient } from '../../lib/index.js';
import { createRemoteSelectInputDefine, TencentSslClient } from '@certd/plugin-lib';
@IsTaskPlugin({
name: 'DeployCertToTencentCosPlugin',