refactor: improve international checks for aliyun and tencentcloud

This commit is contained in:
Fu Diwei
2026-07-03 17:55:28 +08:00
parent e9b74a24a4
commit f29a08432e
23 changed files with 67 additions and 69 deletions
@@ -20,6 +20,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
xwait "github.com/certimate-go/certimate/pkg/utils/wait"
)
@@ -78,9 +79,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -19,6 +19,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -78,9 +79,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -18,6 +18,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -64,9 +65,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -18,6 +18,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -64,9 +65,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -17,6 +17,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -63,9 +64,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -18,6 +18,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -66,9 +67,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -5,7 +5,6 @@ import (
"fmt"
"log/slog"
"strconv"
"strings"
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/alibabacloud-go/tea/dara"
@@ -16,6 +15,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -59,9 +59,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"log/slog"
"strings"
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/alibabacloud-go/tea/dara"
@@ -16,6 +15,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -65,9 +65,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log/slog"
"strings"
"github.com/alibabacloud-go/tea/tea"
"github.com/samber/lo"
@@ -12,6 +11,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
osssdk "github.com/certimate-go/certimate/pkg/sdk3rd/alibabacloud/oss"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -57,9 +57,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -18,6 +18,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -64,9 +65,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -16,6 +16,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/aliyun-cas"
xalibabacloud "github.com/certimate-go/certimate/pkg/utils/third-party/alibabacloud"
)
type (
@@ -75,9 +76,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
AccessKeyId: config.AccessKeyId,
AccessKeySecret: config.AccessKeySecret,
ResourceGroupId: config.ResourceGroupId,
Region: lo.
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
Else("ap-southeast-1"),
Region: lo.Ternary(xalibabacloud.IsIntlRegion(config.Region), "ap-southeast-1", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -16,6 +16,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -62,9 +63,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"log/slog"
"strings"
"time"
"github.com/samber/lo"
@@ -16,6 +15,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
xwait "github.com/certimate-go/certimate/pkg/utils/wait"
)
@@ -71,9 +71,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log/slog"
"strings"
"github.com/samber/lo"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
@@ -15,6 +14,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -61,9 +61,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -16,6 +16,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -62,9 +63,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -20,6 +20,7 @@ import (
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xcertkey "github.com/certimate-go/certimate/pkg/utils/cert/key"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -70,9 +71,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -17,6 +17,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -71,9 +72,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"log/slog"
"strings"
"github.com/samber/lo"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
@@ -16,6 +15,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xcerthostname "github.com/certimate-go/certimate/pkg/utils/cert/hostname"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -64,9 +64,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"log/slog"
"strings"
"github.com/samber/lo"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
@@ -15,6 +14,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -63,9 +63,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log/slog"
"strings"
"github.com/samber/lo"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
@@ -14,6 +13,7 @@ import (
"github.com/certimate-go/certimate/pkg/core"
cmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/tencentcloud-ssl"
xtencentcloud "github.com/certimate-go/certimate/pkg/utils/third-party/tencentcloud"
)
type (
@@ -63,9 +63,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
SecretId: config.SecretId,
SecretKey: config.SecretKey,
ProjectId: config.ProjectId,
Endpoint: lo.
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
Else(""),
Endpoint: lo.Ternary(xtencentcloud.IsIntlAPIEndpoint(config.Endpoint), "ssl.intl.tencentcloudapi.com", ""),
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
+11
View File
@@ -0,0 +1,11 @@
package alibabacloud
import (
"strings"
)
// 判断地域是否属于阿里云国际版。
func IsIntlRegion(region string) bool {
region = strings.TrimSpace(region)
return region != "" && !strings.HasPrefix(region, "cn-")
}
+15
View File
@@ -0,0 +1,15 @@
package tencentcloud
import (
"strings"
)
// 判断 API 接口端点是否属于腾讯云国际版。
func IsIntlAPIEndpoint(endpoint string) bool {
return strings.Contains(endpoint, "intl.tencentcloudapi.com")
}
// 判断 EdgeOne 接口端点是否属于腾讯云国际版。
func IsIntlEdgeOneEndpoint(endpoint string) bool {
return strings.Contains(endpoint, "edgeone.ai")
}