From b091657b5c537acf2442a2bfc345d0a77f5e2c50 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 26 May 2025 23:10:31 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=98=BF=E9=87=8C?= =?UTF-8?q?=E4=BA=91DCDN=E6=8F=92=E4=BB=B6=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/deploy-to-dcdn/index.ts | 83 ++++++++++++++++--- .../src/plugins/plugin-farcdn/access.ts | 2 +- .../plugin/deploy-to-cdn-v2/index.ts | 58 +++++++------ 3 files changed, 106 insertions(+), 37 deletions(-) diff --git a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-dcdn/index.ts b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-dcdn/index.ts index cd864c3c..9d8c8a3c 100644 --- a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-dcdn/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-dcdn/index.ts @@ -1,8 +1,14 @@ import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline'; import dayjs from 'dayjs'; -import { AliyunAccess, AliyunClient, createCertDomainGetterInputDefine } from '@certd/plugin-lib'; +import { + AliyunAccess, + AliyunClient, + createCertDomainGetterInputDefine, + createRemoteSelectInputDefine +} from "@certd/plugin-lib"; import { CertInfo } from '@certd/plugin-cert'; import { CertApplyPluginNames} from '@certd/plugin-cert'; +import { optionsUtils } from "@certd/basic/dist/utils/util.options.js"; @IsTaskPlugin({ name: 'DeployCertToAliyunDCDN', title: '阿里云-部署证书至DCDN', @@ -41,12 +47,6 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin { }) accessId!: string; - @TaskInput({ - title: 'DCDN加速域名', - helper: '你在阿里云上配置的CDN加速域名,比如:certd.docmirror.cn', - required: true, - }) - domainName!: string; @TaskInput({ title: '证书名称', @@ -54,13 +54,37 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin { }) certName!: string; + + @TaskInput( + createRemoteSelectInputDefine({ + title: 'DCDN加速域名', + helper: '你在阿里云上配置的DCDN加速域名,比如:certd.docmirror.cn', + action: DeployCertToAliyunDCDN.prototype.onGetDomainList.name, + watches: ['certDomains', 'accessId'], + required: true, + }) + ) + domainName!: string | string[]; + + async onInstance() {} async execute(): Promise { this.logger.info('开始部署证书到阿里云DCDN'); + if(!this.domainName){ + throw new Error('您还未选择DCDN域名'); + } const access = (await this.getAccess(this.accessId)) as AliyunAccess; const client = await this.getClient(access); - const params = await this.buildParams(); - await this.doRequest(client, params); + if(typeof this.domainName === 'string'){ + this.domainName = [this.domainName]; + } + for (const domainName of this.domainName ) { + this.logger.info(`[${this.domainName}]开始部署`) + const params = await this.buildParams(domainName); + await this.doRequest(client, params); + this.logger.info(`[${this.domainName}]部署成功`) + } + this.logger.info('部署完成'); } @@ -75,14 +99,14 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin { return client; } - async buildParams() { + async buildParams(domainName:string) { const CertName = (this.certName ?? 'certd') + '-' + dayjs().format('YYYYMMDDHHmmss'); if (typeof this.cert !== 'object') { const certId = this.cert; this.logger.info('使用已上传的证书:', certId); return { - DomainName: this.domainName, + DomainName: domainName, SSLProtocol: 'on', CertType: 'cas', CertName: CertName, @@ -93,7 +117,7 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin { this.logger.info('上传证书:', CertName); const cert: any = this.cert; return { - DomainName: this.domainName, + DomainName: domainName, SSLProtocol: 'on', CertName: CertName, CertType: 'upload', @@ -117,5 +141,40 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin { throw new Error('执行失败:' + ret.Message); } } + + + async onGetDomainList(data: any) { + if (!this.accessId) { + throw new Error('请选择Access授权'); + } + const access = await this.getAccess(this.accessId); + + const client = await this.getClient(access); + + const params = { + // 'DomainName': 'aaa', + PageSize: 500, + }; + + const requestOption = { + method: 'POST', + formatParams: false, + }; + + const res = await client.request('DescribeDcdnUserDomains', params, requestOption); + this.checkRet(res); + const pageData = res?.Domains?.PageData; + if (!pageData || pageData.length === 0) { + throw new Error('找不到CDN域名,您可以手动输入'); + } + const options = pageData.map((item: any) => { + return { + value: item.DomainName, + label: item.DomainName, + domain: item.DomainName, + }; + }); + return optionsUtils.buildGroupOptions(options, this.certDomains); + } } new DeployCertToAliyunDCDN(); diff --git a/packages/ui/certd-server/src/plugins/plugin-farcdn/access.ts b/packages/ui/certd-server/src/plugins/plugin-farcdn/access.ts index 81fa5b06..cb0140f7 100644 --- a/packages/ui/certd-server/src/plugins/plugin-farcdn/access.ts +++ b/packages/ui/certd-server/src/plugins/plugin-farcdn/access.ts @@ -186,7 +186,7 @@ export class FarcdnAccess extends BaseAccess { if (res.code === "200") { return res.data; } - throw new Error(res.message); + throw new Error(res.message || res); } } diff --git a/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-cdn-v2/index.ts b/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-cdn-v2/index.ts index 72980cba..25ef2987 100644 --- a/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-cdn-v2/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-cdn-v2/index.ts @@ -1,6 +1,6 @@ import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline'; -import { CertInfo } from '@certd/plugin-cert'; -import { createRemoteSelectInputDefine } from '@certd/plugin-lib'; +import { CertInfo ,CertReader} from '@certd/plugin-cert'; +import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib"; import { TencentAccess, TencentSslClient } from '@certd/plugin-lib'; import { CertApplyPluginNames} from '@certd/plugin-cert'; @IsTaskPlugin({ @@ -16,26 +16,6 @@ import { CertApplyPluginNames} from '@certd/plugin-cert'; }, }) export class TencentDeployCertToCDNv2 extends AbstractTaskPlugin { - @TaskInput({ - title: 'Access提供者', - helper: 'access 授权', - component: { - name: 'access-selector', - type: 'tencent', - }, - required: true, - }) - accessId!: string; - - @TaskInput( - createRemoteSelectInputDefine({ - title: 'CDN域名', - helper: '请选择域名或输入域名', - typeName: 'TencentDeployCertToCDNv2', - action: TencentDeployCertToCDNv2.prototype.onGetDomainList.name, - }) - ) - domains!: string | string[]; @TaskInput({ title: '域名证书', @@ -48,8 +28,35 @@ export class TencentDeployCertToCDNv2 extends AbstractTaskPlugin { }) cert!: CertInfo | string; + @TaskInput(createCertDomainGetterInputDefine({ props: { required: false } })) + certDomains!: string[]; + + @TaskInput({ + title: 'Access提供者', + helper: 'access 授权', + component: { + name: 'access-selector', + type: 'tencent', + }, + required: true, + }) + accessId!: string; + + + @TaskInput( + createRemoteSelectInputDefine({ + title: 'CDN域名', + helper: '请选择域名或输入域名', + typeName: 'TencentDeployCertToCDNv2', + action: TencentDeployCertToCDNv2.prototype.onGetDomainList.name, + }) + ) + domains!: string | string[]; + + async onInstance() {} + async execute(): Promise { const access = await this.getAccess(this.accessId); const sslClient = new TencentSslClient({ @@ -59,8 +66,9 @@ export class TencentDeployCertToCDNv2 extends AbstractTaskPlugin { let tencentCertId = this.cert as string; if (typeof this.cert !== 'string') { + const certReader = new CertReader(this.cert); tencentCertId = await sslClient.uploadToTencent({ - certName: this.appendTimeSuffix('certd'), + certName: certReader.buildCertName(), cert: this.cert, }); } @@ -108,11 +116,13 @@ export class TencentDeployCertToCDNv2 extends AbstractTaskPlugin { Limit: 1000, }); this.checkRet(res); - return res.Domains.map((item: any) => { + const options = res.Domains.map((item: any) => { return { label: item.Domain, value: item.Domain, + domain: item.Domain }; }); + return this.ctx.utils.options.buildGroupOptions(options, this.certDomains); } }