mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-19 09:51:55 +08:00
refactor: clean code
This commit is contained in:
parent
1dee14e32d
commit
6b5580a30c
@ -27,7 +27,7 @@ type AliyunCASUploader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(config *AliyunCASUploaderConfig) (*AliyunCASUploader, error) {
|
func New(config *AliyunCASUploaderConfig) (*AliyunCASUploader, error) {
|
||||||
client, err := (&AliyunCASUploader{}).createSdkClient(
|
client, err := createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.AccessKeySecret,
|
config.AccessKeySecret,
|
||||||
config.Region,
|
config.Region,
|
||||||
@ -132,7 +132,7 @@ func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *AliyunCASUploader) createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunCas.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunCas.Client, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-hangzhou" // CAS 服务默认区域:华东一杭州
|
region = "cn-hangzhou" // CAS 服务默认区域:华东一杭州
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ type AliyunSLBUploader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(config *AliyunSLBUploaderConfig) (*AliyunSLBUploader, error) {
|
func New(config *AliyunSLBUploaderConfig) (*AliyunSLBUploader, error) {
|
||||||
client, err := (&AliyunSLBUploader{}).createSdkClient(
|
client, err := createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.AccessKeySecret,
|
config.AccessKeySecret,
|
||||||
config.Region,
|
config.Region,
|
||||||
@ -102,7 +102,7 @@ func (u *AliyunSLBUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *AliyunSLBUploader) createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Client, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-hangzhou" // SLB 服务默认区域:华东一杭州
|
region = "cn-hangzhou" // SLB 服务默认区域:华东一杭州
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ type HuaweiCloudELBUploader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(config *HuaweiCloudELBUploaderConfig) (*HuaweiCloudELBUploader, error) {
|
func New(config *HuaweiCloudELBUploaderConfig) (*HuaweiCloudELBUploader, error) {
|
||||||
client, err := (&HuaweiCloudELBUploader{}).createSdkClient(
|
client, err := createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.SecretAccessKey,
|
config.SecretAccessKey,
|
||||||
config.Region,
|
config.Region,
|
||||||
@ -108,7 +108,7 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 获取项目 ID
|
// 获取项目 ID
|
||||||
// REF: https://support.huaweicloud.com/api-iam/iam_06_0001.html
|
// REF: https://support.huaweicloud.com/api-iam/iam_06_0001.html
|
||||||
projectId, err := u.getSdkProjectId(u.config.Region, u.config.AccessKeyId, u.config.SecretAccessKey)
|
projectId, err := getSdkProjectId(u.config.AccessKeyId, u.config.SecretAccessKey, u.config.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Wrap(err, "failed to get SDK project id")
|
return nil, xerrors.Wrap(err, "failed to get SDK project id")
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *HuaweiCloudELBUploader) createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbClient, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbClient, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-north-4" // ELB 服务默认区域:华北四北京
|
region = "cn-north-4" // ELB 服务默认区域:华北四北京
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ func (u *HuaweiCloudELBUploader) createSdkClient(accessKeyId, secretAccessKey, r
|
|||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *HuaweiCloudELBUploader) getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error) {
|
func getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-north-4" // IAM 服务默认区域:华北四北京
|
region = "cn-north-4" // IAM 服务默认区域:华北四北京
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ type HuaweiCloudSCMUploader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(config *HuaweiCloudSCMUploaderConfig) (*HuaweiCloudSCMUploader, error) {
|
func New(config *HuaweiCloudSCMUploaderConfig) (*HuaweiCloudSCMUploader, error) {
|
||||||
client, err := (&HuaweiCloudSCMUploader{}).createSdkClient(
|
client, err := createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.SecretAccessKey,
|
config.SecretAccessKey,
|
||||||
config.Region,
|
config.Region,
|
||||||
@ -139,7 +139,7 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *HuaweiCloudSCMUploader) createSdkClient(accessKeyId, secretAccessKey, region string) (*hcScm.ScmClient, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcScm.ScmClient, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-north-4" // SCM 服务默认区域:华北四北京
|
region = "cn-north-4" // SCM 服务默认区域:华北四北京
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ type QiniuSSLCertUploader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(config *QiniuSSLCertUploaderConfig) (*QiniuSSLCertUploader, error) {
|
func New(config *QiniuSSLCertUploaderConfig) (*QiniuSSLCertUploader, error) {
|
||||||
client, err := (&QiniuSSLCertUploader{}).createSdkClient(
|
client, err := createSdkClient(
|
||||||
config.AccessKey,
|
config.AccessKey,
|
||||||
config.SecretKey,
|
config.SecretKey,
|
||||||
)
|
)
|
||||||
@ -63,7 +63,7 @@ func (u *QiniuSSLCertUploader) Upload(ctx context.Context, certPem string, privk
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *QiniuSSLCertUploader) createSdkClient(accessKey, secretKey string) (*qiniuEx.Client, error) {
|
func createSdkClient(accessKey, secretKey string) (*qiniuEx.Client, error) {
|
||||||
credential := auth.New(accessKey, secretKey)
|
credential := auth.New(accessKey, secretKey)
|
||||||
client := qiniuEx.NewClient(credential)
|
client := qiniuEx.NewClient(credential)
|
||||||
return client, nil
|
return client, nil
|
||||||
|
@ -22,7 +22,7 @@ type TencentCloudSSLUploader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(config *TencentCloudSSLUploaderConfig) (*TencentCloudSSLUploader, error) {
|
func New(config *TencentCloudSSLUploaderConfig) (*TencentCloudSSLUploader, error) {
|
||||||
client, err := (&TencentCloudSSLUploader{}).createSdkClient(
|
client, err := createSdkClient(
|
||||||
config.SecretId,
|
config.SecretId,
|
||||||
config.SecretKey,
|
config.SecretKey,
|
||||||
)
|
)
|
||||||
@ -55,7 +55,7 @@ func (u *TencentCloudSSLUploader) Upload(ctx context.Context, certPem string, pr
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *TencentCloudSSLUploader) createSdkClient(secretId, secretKey string) (*tcSsl.Client, error) {
|
func createSdkClient(secretId, secretKey string) (*tcSsl.Client, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
client, err := tcSsl.NewClient(credential, "", profile.NewClientProfile())
|
client, err := tcSsl.NewClient(credential, "", profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user