From 79df39acabab10ae7e1864dadcdc186bb007a3c5 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Wed, 16 Apr 2025 09:34:04 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E5=88=B0=E5=8D=8E=E4=B8=BA=E4=BA=91CDN=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=85=88=E4=B8=8A=E4=BC=A0=E5=88=B0ccm=EF=BC=8C?= =?UTF-8?q?=E5=86=8D=E4=BD=BF=E7=94=A8=E8=AF=81=E4=B9=A6id=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=EF=BC=8C=E4=BF=AE=E5=A4=8Doffline=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8B=E5=AF=BC=E8=87=B4=E9=83=A8=E7=BD=B2=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/deploy-to-cdn/index.ts | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/ui/certd-server/src/plugins/plugin-huawei/plugins/deploy-to-cdn/index.ts b/packages/ui/certd-server/src/plugins/plugin-huawei/plugins/deploy-to-cdn/index.ts index 5827b37b..32a916ef 100644 --- a/packages/ui/certd-server/src/plugins/plugin-huawei/plugins/deploy-to-cdn/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-huawei/plugins/deploy-to-cdn/index.ts @@ -22,11 +22,11 @@ export class HauweiDeployCertToCDN extends AbstractTaskPlugin { helper: '请选择前置任务输出的域名证书', component: { name: 'output-selector', - from: [...CertApplyPluginNames], + from: [...CertApplyPluginNames,'HauweiUploadToCCM'], }, required: true, }) - cert!: CertInfo; + cert!: CertInfo | string; @TaskInput(createCertDomainGetterInputDefine({ props: { required: false } })) certDomains!: string[]; @@ -53,14 +53,25 @@ export class HauweiDeployCertToCDN extends AbstractTaskPlugin { domains!: string[]; async execute(): Promise { + if (!this.cert) { + throw new Error('域名证书不能为空'); + } this.logger.info('开始部署证书到华为云cdn'); const { cdn, client } = await this.getCdnClient(); - const httpsConfig = new cdn.HttpPutBody() + let httpsConfig = new cdn.HttpPutBody() .withHttpsStatus('on') .withCertificateType('server') - .withCertificateName(this.appendTimeSuffix('certd')) - .withCertificateValue(this.cert.crt) - .withPrivateKey(this.cert.key); + + if(typeof this.cert === 'object'){ + httpsConfig= httpsConfig.withCertificateSource(0) + .withCertificateName(this.appendTimeSuffix('certd')) + .withCertificateValue(this.cert.crt) + .withPrivateKey(this.cert.key); + }else{ + this.logger.info('使用已有域名证书:', this.cert); + httpsConfig= httpsConfig.withCertificateSource(2)//scm证书 + .withScmCertificateId(this.cert) + } const config = new cdn.Configs().withHttps(httpsConfig); const body = new cdn.ModifyDomainConfigRequestBody().withConfigs(config); @@ -70,9 +81,28 @@ export class HauweiDeployCertToCDN extends AbstractTaskPlugin { this.logger.info('部署域名:', JSON.stringify(this.domains)); for (const domain of this.domains) { this.logger.info('部署到域名:', domain); - const req = new cdn.UpdateDomainFullConfigRequest().withDomainName(domain).withBody(body); - await client.updateDomainFullConfig(req); - this.logger.info(`部署到域名${domain}完成:`); + + const queryReq = new cdn.ShowDomainDetailByNameRequest(domain); + const domainDetail = await client.showDomainDetailByName(queryReq); + //@ts-ignore + const status = domainDetail.domain.domainStatus || domainDetail.domain.domain_status + this.logger.info(`当前域名状态:`, status); + let ignoreError = false + if (status === 'offline') { + ignoreError = true + } + try{ + const req = new cdn.UpdateDomainFullConfigRequest().withDomainName(domain).withBody(body); + await client.updateDomainFullConfig(req); + this.logger.info(`部署到域名${domain}完成:`); + }catch (e) { + if (ignoreError){ + this.logger.warn(`部署到域名${domain}失败,由于其处于offline状态,忽略部署错误,继续执行:`, e); + }else{ + throw e + } + } + } this.logger.info('部署证书到华为云cdn完成');