From 932780c578f01a0f37e0da5a5692ccf2bb1f8b02 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 12 Apr 2025 22:02:16 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E4=BC=98=E5=8C=96=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E5=88=B0=E8=85=BE=E8=AE=AF=E4=BA=91=E4=BB=BB=E6=84=8F=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=8F=92=E4=BB=B6=EF=BC=8C=E6=94=AF=E6=8C=81region?= =?UTF-8?q?=EF=BC=8C=E5=92=8C=E8=B5=84=E6=BA=90=E7=B1=BB=E5=9E=8B=E9=80=89?= =?UTF-8?q?=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加资源类型选择输入,支持多种腾讯云产品 -增加证书上传功能,支持直接上传证书到腾讯云 - 优化证书 ID 输入,支持选择上传任务或申请任务的输出- 添加 Region 输入,用于指定云资源所在地域 - 更新文档链接,提供更详细的参考信息 --- .../plugin/deploy-to-all/index.ts | 104 ++++++++++++++++-- 1 file changed, 92 insertions(+), 12 deletions(-) diff --git a/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-all/index.ts b/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-all/index.ts index 63072581..e40b637c 100644 --- a/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-all/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-all/index.ts @@ -1,4 +1,6 @@ import {AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline'; +import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert"; +import { TencentSslClient } from "@certd/plugin-lib"; @IsTaskPlugin({ name: 'DeployCertToTencentAll', @@ -6,7 +8,7 @@ import {AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} needPlus: false, icon: 'svg:icon-tencentcloud', group: pluginGroups.tencent.key, - desc: '需要【上传到腾讯云】作为前置任务', + desc: '支持负载均衡、CDN、DDoS、直播、点播、Web应用防火墙、API网关、TEO、容器服务、对象存储、轻应用服务器、云原生微服务、云开发', default: { strategy: { runStrategy: RunStrategy.SkipWhenSucceed, @@ -29,15 +31,70 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin { accessId!: string; @TaskInput({ - title: '腾讯云证书id', - helper: '请选择“上传证书到腾讯云”前置任务的输出', + title: '证书', + helper: '请选择"证书申请任务"或“上传证书到腾讯云”前置任务的输出', component: { name: 'output-selector', - from: 'UploadCertToTencent', + from: [...CertApplyPluginNames,'UploadCertToTencent'], }, required: true, }) - tencentCertId!: string; + tencentCertId!: string | CertInfo; + + + + + @TaskInput({ + title: '资源类型', + component: { + name: 'a-select', + vModel: 'value', + allowClear: true, + //- clb + // - cdn + // - ddos + // - live + // - vod + // - waf + // - apigateway + // - teo + // - tke + // - cos + // - lighthouse + // - tse + // - tcb + options: [ + { value: 'clb',label: '负载均衡'}, + { value: 'cdn',label: 'CDN'}, + { value: 'ddos',label: 'DDoS'}, + { value: 'live',label: '直播'}, + { value: 'vod',label: '点播'}, + { value: 'waf',label: 'Web应用防火墙'}, + { value: 'apigateway',label: 'API网关'}, + { value: 'teo',label: 'TEO'}, + { value: 'tke',label: '容器服务'}, + { value: 'cos',label: '对象存储'}, + { value: 'lighthouse',label: '轻应用服务器'}, + { value: 'tse',label: '云原生微服务'}, + { value: 'tcb',label: '云开发'}, + ] + }, + helper: '', + required: true, + }) + resourceType!: string; + + @TaskInput({ + title: 'Region', + component: { + name: 'a-input', + vModel: 'value', + allowClear: true, + }, + helper: '当云资源类型传入clb、waf、apigateway、cos、lighthouse、tke、tse、tcb 时,公共参数Region必传。[参考文档](https://cloud.tencent.com/document/product/400/91667)', + }) + region!: string; + @TaskInput({ title: '云资源实例Id列表', @@ -47,22 +104,22 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin { open: false, mode: 'tags', }, - helper: '', + helper: '[参考文档](https://cloud.tencent.com/document/product/400/91667)', }) instanceIdList!: string[]; async onInstance() {} async execute(): Promise { - const accessProvider = await this.getAccess(this.accessId); + const access = await this.getAccess(this.accessId); const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/ssl/v20191205/index.js'); const Client = sdk.v20191205.Client; const client = new Client({ credential: { - secretId: accessProvider.secretId, - secretKey: accessProvider.secretKey, + secretId: access.secretId, + secretKey: access.secretKey, }, - region: '', + region: this.region, profile: { httpProfile: { endpoint: 'ssl.tencentcloudapi.com', @@ -70,14 +127,25 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin { }, }); + let certId:string = null + if (typeof certId === 'string') { + certId = this.tencentCertId as string; + } else { + //上传 + certId = await this.uploadToTencent(access,this.tencentCertId as CertInfo); + } + const params = { - CertificateId: this.tencentCertId, + CertificateId: certId, + ResourceType: this.resourceType, InstanceIdList: this.instanceIdList, + IsCache:0, }; const res = await client.DeployCertificateInstance(params); this.checkRet(res); - this.logger.info('部署成功'); + this.logger.info('部署成功,等待5s:',JSON.stringify(res)); + await this.ctx.utils.sleep(5000); } checkRet(ret: any) { @@ -85,4 +153,16 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin { throw new Error('执行失败:' + ret.Error.Code + ',' + ret.Error.Message); } } + + private async uploadToTencent(access: any, cert: CertInfo) { + const sslClient = new TencentSslClient({ + access, + logger: this.logger, + }); + + return await sslClient.uploadToTencent({ + certName: this.appendTimeSuffix('certd'), + cert: cert, + }); + } }