From 3a213dc9c3d047542033eda972870fb79365df5f Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Sun, 20 Oct 2024 17:51:36 +0800 Subject: [PATCH] feat: do not use region from access when deploy to huaweicloud cdn --- internal/deployer/huaweicloud_cdn.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/deployer/huaweicloud_cdn.go b/internal/deployer/huaweicloud_cdn.go index f7db488d..3548c256 100644 --- a/internal/deployer/huaweicloud_cdn.go +++ b/internal/deployer/huaweicloud_cdn.go @@ -41,7 +41,8 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context) error { return err } - client, err := d.createClient(access) + // TODO: CDN 服务与 DNS 服务所支持的区域可能不一致,这里暂时不传而是使用默认值,仅支持华为云国内版 + client, err := d.createClient("", access.AccessKeyId, access.SecretAccessKey) if err != nil { return err } @@ -62,13 +63,14 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context) error { // 更新加速域名配置 // REF: https://support.huaweicloud.com/api-cdn/UpdateDomainMultiCertificates.html + // REF: https://support.huaweicloud.com/usermanual-cdn/cdn_01_0306.html updateDomainMultiCertificatesReqBodyContent := &huaweicloudCDNUpdateDomainMultiCertificatesRequestBodyContent{} updateDomainMultiCertificatesReqBodyContent.DomainName = d.option.DeployConfig.GetConfigAsString("domain") updateDomainMultiCertificatesReqBodyContent.HttpsSwitch = 1 var updateDomainMultiCertificatesResp *cdnModel.UpdateDomainMultiCertificatesResponse if d.option.DeployConfig.GetConfigAsBool("useSCM") { uploader, err := uploaderImpl.NewHuaweiCloudSCMUploader(&uploaderImpl.HuaweiCloudSCMUploaderConfig{ - Region: "", // TODO: SCM 服务与 CDN 服务的区域不一致,这里暂时不传而是使用默认值,仅支持华为云国内版 + Region: "", // TODO: SCM 服务与 DNS 服务所支持的区域可能不一致,这里暂时不传而是使用默认值,仅支持华为云国内版 AccessKeyId: access.AccessKeyId, SecretAccessKey: access.SecretAccessKey, }) @@ -109,22 +111,26 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context) error { return nil } -func (d *HuaweiCloudCDNDeployer) createClient(access *domain.HuaweiCloudAccess) (*cdn.CdnClient, error) { +func (d *HuaweiCloudCDNDeployer) createClient(region, accessKeyId, secretAccessKey string) (*cdn.CdnClient, error) { auth, err := global.NewCredentialsBuilder(). - WithAk(access.AccessKeyId). - WithSk(access.SecretAccessKey). + WithAk(accessKeyId). + WithSk(secretAccessKey). SafeBuild() if err != nil { return nil, err } - region, err := cdnRegion.SafeValueOf(access.Region) + if region == "" { + region = "cn-north-1" // CDN 服务默认区域:华北北京一 + } + + hcRegion, err := cdnRegion.SafeValueOf(region) if err != nil { return nil, err } hcClient, err := cdn.CdnClientBuilder(). - WithRegion(region). + WithRegion(hcRegion). WithCredential(auth). SafeBuild() if err != nil {