mirror of
https://github.com/usual2970/certimate.git
synced 2025-10-05 14:04:54 +00:00
feat: allow set a different region on deployment to huaweicloud cdn
This commit is contained in:
@@ -9,13 +9,13 @@ type Uploader interface {
|
||||
// 上传证书。
|
||||
//
|
||||
// 入参:
|
||||
// - ctx:
|
||||
// - certPem:证书 PEM 内容
|
||||
// - privkeyPem:私钥 PEM 内容
|
||||
// - ctx:上下文。
|
||||
// - certPem:证书 PEM 内容。
|
||||
// - privkeyPem:私钥 PEM 内容。
|
||||
//
|
||||
// 出参:
|
||||
// - res:
|
||||
// - err:
|
||||
// - res:上传结果。
|
||||
// - err: 错误。
|
||||
Upload(ctx context.Context, certPem string, privkeyPem string) (res *UploadResult, err error)
|
||||
}
|
||||
|
||||
|
@@ -26,8 +26,12 @@ type AliyunCASUploader struct {
|
||||
sdkRuntime *util.RuntimeOptions
|
||||
}
|
||||
|
||||
func NewAliyunCASUploader(config *AliyunCASUploaderConfig) (*AliyunCASUploader, error) {
|
||||
client, err := (&AliyunCASUploader{config: config}).createSdkClient()
|
||||
func NewAliyunCASUploader(config *AliyunCASUploaderConfig) (Uploader, error) {
|
||||
client, err := (&AliyunCASUploader{}).createSdkClient(
|
||||
config.Region,
|
||||
config.AccessKeyId,
|
||||
config.AccessKeySecret,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create sdk client: %w", err)
|
||||
}
|
||||
@@ -98,11 +102,11 @@ func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyP
|
||||
|
||||
if listUserCertificateOrderResp.Body.CertificateOrderList == nil || len(listUserCertificateOrderResp.Body.CertificateOrderList) < int(listUserCertificateOrderLimit) {
|
||||
break
|
||||
}
|
||||
|
||||
listUserCertificateOrderPage += 1
|
||||
if listUserCertificateOrderPage > 99 { // 避免死循环
|
||||
break
|
||||
} else {
|
||||
listUserCertificateOrderPage += 1
|
||||
if listUserCertificateOrderPage > 99 { // 避免死循环
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +133,7 @@ func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyP
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *AliyunCASUploader) createSdkClient() (*cas20200407.Client, error) {
|
||||
region := u.config.Region
|
||||
accessKeyId := u.config.AccessKeyId
|
||||
accessKeySecret := u.config.AccessKeySecret
|
||||
func (u *AliyunCASUploader) createSdkClient(region, accessKeyId, accessKeySecret string) (*cas20200407.Client, error) {
|
||||
if region == "" {
|
||||
region = "cn-hangzhou" // CAS 服务默认区域:华东一杭州
|
||||
}
|
||||
|
@@ -26,8 +26,12 @@ type HuaweiCloudELBUploader struct {
|
||||
sdkClient *hcElb.ElbClient
|
||||
}
|
||||
|
||||
func NewHuaweiCloudELBUploader(config *HuaweiCloudELBUploaderConfig) (*HuaweiCloudELBUploader, error) {
|
||||
client, err := (&HuaweiCloudELBUploader{config: config}).createSdkClient()
|
||||
func NewHuaweiCloudELBUploader(config *HuaweiCloudELBUploaderConfig) (Uploader, error) {
|
||||
client, err := (&HuaweiCloudELBUploader{}).createSdkClient(
|
||||
config.Region,
|
||||
config.AccessKeyId,
|
||||
config.SecretAccessKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create sdk client: %w", err)
|
||||
}
|
||||
@@ -87,12 +91,12 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
||||
|
||||
if listCertificatesResp.Certificates == nil || len(*listCertificatesResp.Certificates) < int(listCertificatesLimit) {
|
||||
break
|
||||
}
|
||||
|
||||
listCertificatesMarker = listCertificatesResp.PageInfo.NextMarker
|
||||
listCertificatesPage++
|
||||
if listCertificatesPage >= 9 { // 避免死循环
|
||||
break
|
||||
} else {
|
||||
listCertificatesMarker = listCertificatesResp.PageInfo.NextMarker
|
||||
listCertificatesPage++
|
||||
if listCertificatesPage >= 9 { // 避免死循环
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,10 +129,7 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *HuaweiCloudELBUploader) createSdkClient() (*hcElb.ElbClient, error) {
|
||||
region := u.config.Region
|
||||
accessKeyId := u.config.AccessKeyId
|
||||
secretAccessKey := u.config.SecretAccessKey
|
||||
func (u *HuaweiCloudELBUploader) createSdkClient(region, accessKeyId, secretAccessKey string) (*hcElb.ElbClient, error) {
|
||||
if region == "" {
|
||||
region = "cn-north-4" // ELB 服务默认区域:华北四北京
|
||||
}
|
||||
|
@@ -25,8 +25,12 @@ type HuaweiCloudSCMUploader struct {
|
||||
sdkClient *hcScm.ScmClient
|
||||
}
|
||||
|
||||
func NewHuaweiCloudSCMUploader(config *HuaweiCloudSCMUploaderConfig) (*HuaweiCloudSCMUploader, error) {
|
||||
client, err := (&HuaweiCloudSCMUploader{config: config}).createSdkClient()
|
||||
func NewHuaweiCloudSCMUploader(config *HuaweiCloudSCMUploaderConfig) (Uploader, error) {
|
||||
client, err := (&HuaweiCloudSCMUploader{}).createSdkClient(
|
||||
config.Region,
|
||||
config.AccessKeyId,
|
||||
config.SecretAccessKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create sdk client: %w", err)
|
||||
}
|
||||
@@ -99,12 +103,12 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
|
||||
|
||||
if listCertificatesResp.Certificates == nil || len(*listCertificatesResp.Certificates) < int(listCertificatesLimit) {
|
||||
break
|
||||
}
|
||||
|
||||
listCertificatesOffset += listCertificatesLimit
|
||||
listCertificatesPage += 1
|
||||
if listCertificatesPage > 99 { // 避免死循环
|
||||
break
|
||||
} else {
|
||||
listCertificatesOffset += listCertificatesLimit
|
||||
listCertificatesPage += 1
|
||||
if listCertificatesPage > 99 { // 避免死循环
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,10 +137,7 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *HuaweiCloudSCMUploader) createSdkClient() (*hcScm.ScmClient, error) {
|
||||
region := u.config.Region
|
||||
accessKeyId := u.config.AccessKeyId
|
||||
secretAccessKey := u.config.SecretAccessKey
|
||||
func (u *HuaweiCloudSCMUploader) createSdkClient(region, accessKeyId, secretAccessKey string) (*hcScm.ScmClient, error) {
|
||||
if region == "" {
|
||||
region = "cn-north-4" // SCM 服务默认区域:华北四北京
|
||||
}
|
||||
|
@@ -23,8 +23,12 @@ type TencentCloudSSLUploader struct {
|
||||
sdkClient *tcSsl.Client
|
||||
}
|
||||
|
||||
func NewTencentCloudSSLUploader(config *TencentCloudSSLUploaderConfig) (*TencentCloudSSLUploader, error) {
|
||||
client, err := (&TencentCloudSSLUploader{config: config}).createSdkClient()
|
||||
func NewTencentCloudSSLUploader(config *TencentCloudSSLUploaderConfig) (Uploader, error) {
|
||||
client, err := (&TencentCloudSSLUploader{}).createSdkClient(
|
||||
config.Region,
|
||||
config.SecretId,
|
||||
config.SecretKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create sdk client: %w", err)
|
||||
}
|
||||
@@ -73,10 +77,7 @@ func (u *TencentCloudSSLUploader) Upload(ctx context.Context, certPem string, pr
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *TencentCloudSSLUploader) createSdkClient() (*tcSsl.Client, error) {
|
||||
region := u.config.Region
|
||||
secretId := u.config.SecretId
|
||||
secretKey := u.config.SecretKey
|
||||
func (u *TencentCloudSSLUploader) createSdkClient(region, secretId, secretKey string) (*tcSsl.Client, error) {
|
||||
if region == "" {
|
||||
region = "ap-guangzhou" // SSL 服务默认区域:广州
|
||||
}
|
||||
|
Reference in New Issue
Block a user