diff --git a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-cdn/index.ts b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-cdn/index.ts index d5a8fe22..dfcb2cf6 100644 --- a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-cdn/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-cdn/index.ts @@ -75,11 +75,11 @@ export class DeployCertToAliyunCDN extends AbstractTaskPlugin { return { RegionId: 'cn-hangzhou', DomainName: this.domainName, - ServerCertificateStatus: 'on', + SSLProtocol: 'on', CertName: CertName, CertType: 'upload', - ServerCertificate: cert.crt, - PrivateKey: cert.key, + SSLPub: cert.crt, + SSLPri: cert.key, }; } @@ -87,7 +87,7 @@ export class DeployCertToAliyunCDN extends AbstractTaskPlugin { const requestOption = { method: 'POST', }; - const ret: any = await client.request('SetDomainServerCertificate', params, requestOption); + const ret: any = await client.request('SetCdnDomainSSLCertificate', params, requestOption); this.checkRet(ret); this.logger.info('设置cdn证书成功:', ret.RequestId); } 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 new file mode 100644 index 00000000..704cda85 --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-dcdn/index.ts @@ -0,0 +1,101 @@ +import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline'; +import dayjs from 'dayjs'; +import { AliyunAccess } from '@certd/plugin-plus'; +import type RPCClient from '@alicloud/pop-core'; +@IsTaskPlugin({ + name: 'DeployCertToAliyunDCDN', + title: '部署证书至阿里云DCDN', + group: pluginGroups.aliyun.key, + desc: '依赖证书申请前置任务,自动部署域名证书至阿里云DCDN', + default: { + strategy: { + runStrategy: RunStrategy.SkipWhenSucceed, + }, + }, +}) +export class DeployCertToAliyunDCDN extends AbstractTaskPlugin { + @TaskInput({ + title: 'DCDN加速域名', + helper: '你在阿里云上配置的CDN加速域名,比如:certd.docmirror.cn', + required: true, + }) + domainName!: string; + + @TaskInput({ + title: '证书名称', + helper: '上传后将以此名称作为前缀备注', + }) + certName!: string; + + @TaskInput({ + title: '域名证书', + helper: '请选择前置任务输出的域名证书', + component: { + name: 'pi-output-selector', + }, + required: true, + }) + cert!: string; + + @TaskInput({ + title: 'Access授权', + helper: '阿里云授权AccessKeyId、AccessKeySecret', + component: { + name: 'pi-access-selector', + type: 'aliyun', + }, + required: true, + }) + accessId!: string; + + async onInstance() {} + async execute(): Promise { + console.log('开始部署证书到阿里云DCDN'); + const access = (await this.accessService.getById(this.accessId)) as AliyunAccess; + const client = await this.getClient(access); + const params = await this.buildParams(); + await this.doRequest(client, params); + console.log('部署完成'); + } + + async getClient(access: AliyunAccess) { + const Core = await import('@alicloud/pop-core'); + + return new Core.default({ + accessKeyId: access.accessKeyId, + accessKeySecret: access.accessKeySecret, + endpoint: 'https://dcdn.aliyuncs.com', + apiVersion: '2018-05-10', + }); + } + + async buildParams() { + const CertName = (this.certName ?? 'certd') + '-' + dayjs().format('YYYYMMDDHHmmss'); + const cert: any = this.cert; + return { + RegionId: 'cn-hangzhou', + DomainName: this.domainName, + SSLProtocol: 'on', + CertName: CertName, + CertType: 'upload', + SSLPub: cert.crt, + SSLPri: cert.key, + }; + } + + async doRequest(client: RPCClient, params: any) { + const requestOption = { + method: 'POST', + }; + const ret: any = await client.request('SetDcdnDomainSSLCertificate', params, requestOption); + this.checkRet(ret); + this.logger.info('设置Dcdn证书成功:', ret.RequestId); + } + + checkRet(ret: any) { + if (ret.code != null) { + throw new Error('执行失败:' + ret.Message); + } + } +} +new DeployCertToAliyunDCDN(); diff --git a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/index.ts b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/index.ts index 409b2232..59d348dd 100644 --- a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/index.ts @@ -1,3 +1,4 @@ export * from './deploy-to-cdn/index.js'; +export * from './deploy-to-dcdn/index.js'; export * from './deploy-to-ack-ingress/index.js'; export * from './upload-to-aliyun/index.js';