mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 17:31:55 +08:00
refactor: clean code
This commit is contained in:
parent
21cc1d43de
commit
7160589ac7
@ -103,7 +103,7 @@ type AccessConfigForQiniu struct {
|
|||||||
|
|
||||||
type AccessConfigForSSH struct {
|
type AccessConfigForSSH struct {
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Port int `json:"port"`
|
Port int32 `json:"port"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
providerScm "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/huaweicloud-scm"
|
providerScm "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/huaweicloud-scm"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
hwsdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk"
|
||||||
hcCdnSdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk/cdn"
|
hwsdkCdn "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk/cdn"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HuaweiCloudCDNDeployerConfig struct {
|
type HuaweiCloudCDNDeployerConfig struct {
|
||||||
@ -32,7 +32,7 @@ type HuaweiCloudCDNDeployerConfig struct {
|
|||||||
type HuaweiCloudCDNDeployer struct {
|
type HuaweiCloudCDNDeployer struct {
|
||||||
config *HuaweiCloudCDNDeployerConfig
|
config *HuaweiCloudCDNDeployerConfig
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
sdkClient *hcCdnSdk.Client
|
sdkClient *hwsdkCdn.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,15 +100,15 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pri
|
|||||||
// 更新加速域名配置
|
// 更新加速域名配置
|
||||||
// REF: https://support.huaweicloud.com/api-cdn/UpdateDomainMultiCertificates.html
|
// REF: https://support.huaweicloud.com/api-cdn/UpdateDomainMultiCertificates.html
|
||||||
// REF: https://support.huaweicloud.com/usermanual-cdn/cdn_01_0306.html
|
// REF: https://support.huaweicloud.com/usermanual-cdn/cdn_01_0306.html
|
||||||
updateDomainMultiCertificatesReqBodyContent := &hcCdnSdk.UpdateDomainMultiCertificatesExRequestBodyContent{}
|
updateDomainMultiCertificatesReqBodyContent := &hwsdkCdn.UpdateDomainMultiCertificatesExRequestBodyContent{}
|
||||||
updateDomainMultiCertificatesReqBodyContent.DomainName = d.config.Domain
|
updateDomainMultiCertificatesReqBodyContent.DomainName = d.config.Domain
|
||||||
updateDomainMultiCertificatesReqBodyContent.HttpsSwitch = 1
|
updateDomainMultiCertificatesReqBodyContent.HttpsSwitch = 1
|
||||||
updateDomainMultiCertificatesReqBodyContent.CertificateType = cast.Int32Ptr(2)
|
updateDomainMultiCertificatesReqBodyContent.CertificateType = hwsdk.Int32Ptr(2)
|
||||||
updateDomainMultiCertificatesReqBodyContent.SCMCertificateId = cast.StringPtr(upres.CertId)
|
updateDomainMultiCertificatesReqBodyContent.SCMCertificateId = hwsdk.StringPtr(upres.CertId)
|
||||||
updateDomainMultiCertificatesReqBodyContent.CertName = cast.StringPtr(upres.CertName)
|
updateDomainMultiCertificatesReqBodyContent.CertName = hwsdk.StringPtr(upres.CertName)
|
||||||
updateDomainMultiCertificatesReqBodyContent = updateDomainMultiCertificatesReqBodyContent.MergeConfig(showDomainFullConfigResp.Configs)
|
updateDomainMultiCertificatesReqBodyContent = updateDomainMultiCertificatesReqBodyContent.MergeConfig(showDomainFullConfigResp.Configs)
|
||||||
updateDomainMultiCertificatesReq := &hcCdnSdk.UpdateDomainMultiCertificatesExRequest{
|
updateDomainMultiCertificatesReq := &hwsdkCdn.UpdateDomainMultiCertificatesExRequest{
|
||||||
Body: &hcCdnSdk.UpdateDomainMultiCertificatesExRequestBody{
|
Body: &hwsdkCdn.UpdateDomainMultiCertificatesExRequestBody{
|
||||||
Https: updateDomainMultiCertificatesReqBodyContent,
|
Https: updateDomainMultiCertificatesReqBodyContent,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pri
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcCdnSdk.Client, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hwsdkCdn.Client, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-north-1" // CDN 服务默认区域:华北一北京
|
region = "cn-north-1" // CDN 服务默认区域:华北一北京
|
||||||
}
|
}
|
||||||
@ -148,6 +148,6 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcCdnSdk.Cli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := hcCdnSdk.NewClient(hcClient)
|
client := hwsdkCdn.NewClient(hcClient)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
providerElb "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/huaweicloud-elb"
|
providerElb "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/huaweicloud-elb"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
hwsdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HuaweiCloudELBDeployerConfig struct {
|
type HuaweiCloudELBDeployerConfig struct {
|
||||||
@ -131,8 +131,8 @@ func (d *HuaweiCloudELBDeployer) deployToCertificate(ctx context.Context, certPe
|
|||||||
CertificateId: d.config.CertificateId,
|
CertificateId: d.config.CertificateId,
|
||||||
Body: &hcElbModel.UpdateCertificateRequestBody{
|
Body: &hcElbModel.UpdateCertificateRequestBody{
|
||||||
Certificate: &hcElbModel.UpdateCertificateOption{
|
Certificate: &hcElbModel.UpdateCertificateOption{
|
||||||
Certificate: cast.StringPtr(certPem),
|
Certificate: hwsdk.StringPtr(certPem),
|
||||||
PrivateKey: cast.StringPtr(privkeyPem),
|
PrivateKey: hwsdk.StringPtr(privkeyPem),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -151,8 +151,6 @@ func (d *HuaweiCloudELBDeployer) deployToLoadbalancer(ctx context.Context, certP
|
|||||||
return errors.New("config `loadbalancerId` is required")
|
return errors.New("config `loadbalancerId` is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
listenerIds := make([]string, 0)
|
|
||||||
|
|
||||||
// 查询负载均衡器详情
|
// 查询负载均衡器详情
|
||||||
// REF: https://support.huaweicloud.com/api-elb/ShowLoadBalancer.html
|
// REF: https://support.huaweicloud.com/api-elb/ShowLoadBalancer.html
|
||||||
showLoadBalancerReq := &hcElbModel.ShowLoadBalancerRequest{
|
showLoadBalancerReq := &hcElbModel.ShowLoadBalancerRequest{
|
||||||
@ -167,11 +165,12 @@ func (d *HuaweiCloudELBDeployer) deployToLoadbalancer(ctx context.Context, certP
|
|||||||
|
|
||||||
// 查询监听器列表
|
// 查询监听器列表
|
||||||
// REF: https://support.huaweicloud.com/api-elb/ListListeners.html
|
// REF: https://support.huaweicloud.com/api-elb/ListListeners.html
|
||||||
|
listenerIds := make([]string, 0)
|
||||||
listListenersLimit := int32(2000)
|
listListenersLimit := int32(2000)
|
||||||
var listListenersMarker *string = nil
|
var listListenersMarker *string = nil
|
||||||
for {
|
for {
|
||||||
listListenersReq := &hcElbModel.ListListenersRequest{
|
listListenersReq := &hcElbModel.ListListenersRequest{
|
||||||
Limit: cast.Int32Ptr(listListenersLimit),
|
Limit: hwsdk.Int32Ptr(listListenersLimit),
|
||||||
Marker: listListenersMarker,
|
Marker: listListenersMarker,
|
||||||
Protocol: &[]string{"HTTPS", "TERMINATED_HTTPS"},
|
Protocol: &[]string{"HTTPS", "TERMINATED_HTTPS"},
|
||||||
LoadbalancerId: &[]string{showLoadBalancerResp.Loadbalancer.Id},
|
LoadbalancerId: &[]string{showLoadBalancerResp.Loadbalancer.Id},
|
||||||
@ -204,15 +203,21 @@ func (d *HuaweiCloudELBDeployer) deployToLoadbalancer(ctx context.Context, certP
|
|||||||
|
|
||||||
d.logger.Logt("certificate file uploaded", upres)
|
d.logger.Logt("certificate file uploaded", upres)
|
||||||
|
|
||||||
// 批量更新监听器证书
|
// 遍历更新监听器证书
|
||||||
var errs []error
|
if len(listenerIds) == 0 {
|
||||||
for _, listenerId := range listenerIds {
|
return xerrors.New("listener not found")
|
||||||
if err := d.modifyListenerCertificate(ctx, listenerId, upres.CertId); err != nil {
|
} else {
|
||||||
errs = append(errs, err)
|
var errs []error
|
||||||
|
|
||||||
|
for _, listenerId := range listenerIds {
|
||||||
|
if err := d.modifyListenerCertificate(ctx, listenerId, upres.CertId); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return errors.Join(errs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -258,7 +263,7 @@ func (d *HuaweiCloudELBDeployer) modifyListenerCertificate(ctx context.Context,
|
|||||||
ListenerId: cloudListenerId,
|
ListenerId: cloudListenerId,
|
||||||
Body: &hcElbModel.UpdateListenerRequestBody{
|
Body: &hcElbModel.UpdateListenerRequestBody{
|
||||||
Listener: &hcElbModel.UpdateListenerOption{
|
Listener: &hcElbModel.UpdateListenerOption{
|
||||||
DefaultTlsContainerRef: cast.StringPtr(cloudCertId),
|
DefaultTlsContainerRef: hwsdk.StringPtr(cloudCertId),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -305,7 +310,7 @@ func (d *HuaweiCloudELBDeployer) modifyListenerCertificate(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if showListenerResp.Listener.SniMatchAlgo != "" {
|
if showListenerResp.Listener.SniMatchAlgo != "" {
|
||||||
updateListenerReq.Body.Listener.SniMatchAlgo = cast.StringPtr(showListenerResp.Listener.SniMatchAlgo)
|
updateListenerReq.Body.Listener.SniMatchAlgo = hwsdk.StringPtr(showListenerResp.Listener.SniMatchAlgo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateListenerResp, err := d.sdkClient.UpdateListener(updateListenerReq)
|
updateListenerResp, err := d.sdkClient.UpdateListener(updateListenerReq)
|
||||||
@ -319,10 +324,6 @@ func (d *HuaweiCloudELBDeployer) modifyListenerCertificate(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbClient, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbClient, error) {
|
||||||
if region == "" {
|
|
||||||
region = "cn-north-4" // ELB 服务默认区域:华北四北京
|
|
||||||
}
|
|
||||||
|
|
||||||
projectId, err := getSdkProjectId(accessKeyId, secretAccessKey, region)
|
projectId, err := getSdkProjectId(accessKeyId, secretAccessKey, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -30,13 +30,13 @@ type TencentCloudCDNDeployerConfig struct {
|
|||||||
type TencentCloudCDNDeployer struct {
|
type TencentCloudCDNDeployer struct {
|
||||||
config *TencentCloudCDNDeployerConfig
|
config *TencentCloudCDNDeployerConfig
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
sdkClients *tencentCloudCDNDeployerSdkClients
|
sdkClients *wSdkClients
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*TencentCloudCDNDeployer)(nil)
|
var _ deployer.Deployer = (*TencentCloudCDNDeployer)(nil)
|
||||||
|
|
||||||
type tencentCloudCDNDeployerSdkClients struct {
|
type wSdkClients struct {
|
||||||
ssl *tcSsl.Client
|
ssl *tcSsl.Client
|
||||||
cdn *tcCdn.Client
|
cdn *tcCdn.Client
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ func (d *TencentCloudCDNDeployer) getDeployedDomainsByCertificateId(cloudCertId
|
|||||||
return domains, nil
|
return domains, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClients(secretId, secretKey string) (*tencentCloudCDNDeployerSdkClients, error) {
|
func createSdkClients(secretId, secretKey string) (*wSdkClients, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
|
|
||||||
sslClient, err := tcSsl.NewClient(credential, "", profile.NewClientProfile())
|
sslClient, err := tcSsl.NewClient(credential, "", profile.NewClientProfile())
|
||||||
@ -192,7 +192,7 @@ func createSdkClients(secretId, secretKey string) (*tencentCloudCDNDeployerSdkCl
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tencentCloudCDNDeployerSdkClients{
|
return &wSdkClients{
|
||||||
ssl: sslClient,
|
ssl: sslClient,
|
||||||
cdn: cdnClient,
|
cdn: cdnClient,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -138,10 +138,10 @@ func (d *TencentCloudCLBDeployer) deployToInstanceUseSsl(ctx context.Context, cl
|
|||||||
deployCertificateInstanceReq.ResourceType = common.StringPtr("clb")
|
deployCertificateInstanceReq.ResourceType = common.StringPtr("clb")
|
||||||
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
||||||
if d.config.Domain == "" {
|
if d.config.Domain == "" {
|
||||||
// 未开启 SNI,只需指定到监听器
|
// 未指定 SNI,只需部署到监听器
|
||||||
deployCertificateInstanceReq.InstanceIdList = common.StringPtrs([]string{fmt.Sprintf("%s|%s", d.config.LoadbalancerId, d.config.ListenerId)})
|
deployCertificateInstanceReq.InstanceIdList = common.StringPtrs([]string{fmt.Sprintf("%s|%s", d.config.LoadbalancerId, d.config.ListenerId)})
|
||||||
} else {
|
} else {
|
||||||
// 开启 SNI,需指定到域名(支持泛域名)
|
// 指定 SNI,需部署到域名(支持泛域名)
|
||||||
deployCertificateInstanceReq.InstanceIdList = common.StringPtrs([]string{fmt.Sprintf("%s|%s|%s", d.config.LoadbalancerId, d.config.ListenerId, d.config.Domain)})
|
deployCertificateInstanceReq.InstanceIdList = common.StringPtrs([]string{fmt.Sprintf("%s|%s|%s", d.config.LoadbalancerId, d.config.ListenerId, d.config.Domain)})
|
||||||
}
|
}
|
||||||
deployCertificateInstanceResp, err := d.sdkClients.ssl.DeployCertificateInstance(deployCertificateInstanceReq)
|
deployCertificateInstanceResp, err := d.sdkClients.ssl.DeployCertificateInstance(deployCertificateInstanceReq)
|
||||||
@ -159,10 +159,9 @@ func (d *TencentCloudCLBDeployer) deployToLoadbalancer(ctx context.Context, clou
|
|||||||
return errors.New("config `loadbalancerId` is required")
|
return errors.New("config `loadbalancerId` is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
listenerIds := make([]string, 0)
|
|
||||||
|
|
||||||
// 查询监听器列表
|
// 查询监听器列表
|
||||||
// REF: https://cloud.tencent.com/document/api/214/30686
|
// REF: https://cloud.tencent.com/document/api/214/30686
|
||||||
|
listenerIds := make([]string, 0)
|
||||||
describeListenersReq := tcClb.NewDescribeListenersRequest()
|
describeListenersReq := tcClb.NewDescribeListenersRequest()
|
||||||
describeListenersReq.LoadBalancerId = common.StringPtr(d.config.LoadbalancerId)
|
describeListenersReq.LoadBalancerId = common.StringPtr(d.config.LoadbalancerId)
|
||||||
describeListenersResp, err := d.sdkClients.clb.DescribeListeners(describeListenersReq)
|
describeListenersResp, err := d.sdkClients.clb.DescribeListeners(describeListenersReq)
|
||||||
@ -182,8 +181,10 @@ func (d *TencentCloudCLBDeployer) deployToLoadbalancer(ctx context.Context, clou
|
|||||||
|
|
||||||
d.logger.Logt("已查询到负载均衡器下的监听器", listenerIds)
|
d.logger.Logt("已查询到负载均衡器下的监听器", listenerIds)
|
||||||
|
|
||||||
// 批量更新监听器证书
|
// 遍历更新监听器证书
|
||||||
if len(listenerIds) > 0 {
|
if len(listenerIds) == 0 {
|
||||||
|
return xerrors.New("listener not found")
|
||||||
|
} else {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
|
||||||
for _, listenerId := range listenerIds {
|
for _, listenerId := range listenerIds {
|
||||||
|
@ -102,7 +102,7 @@ func (d *VolcEngineDCDNDeployer) Deploy(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veDcdn.DCDN, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veDcdn.DCDN, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-beijing" // 证书中心默认区域:北京
|
region = "cn-beijing" // DCDN 服务默认区域:北京
|
||||||
}
|
}
|
||||||
|
|
||||||
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
||||||
|
@ -8,12 +8,12 @@ import (
|
|||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
veLive "github.com/volcengine/volc-sdk-golang/service/live/v20230101"
|
veLive "github.com/volcengine/volc-sdk-golang/service/live/v20230101"
|
||||||
|
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
providerLive "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/volcengine-live"
|
providerLive "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/volcengine-live"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type VolcEngineLiveDeployerConfig struct {
|
type VolcEngineLiveDeployerConfig struct {
|
||||||
@ -128,7 +128,7 @@ func (d *VolcEngineLiveDeployer) Deploy(ctx context.Context, certPem string, pri
|
|||||||
bindCertReq := &veLive.BindCertBody{
|
bindCertReq := &veLive.BindCertBody{
|
||||||
ChainID: upres.CertId,
|
ChainID: upres.CertId,
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
HTTPS: cast.BoolPtr(true),
|
HTTPS: ve.Bool(true),
|
||||||
}
|
}
|
||||||
bindCertResp, err := d.sdkClient.BindCert(ctx, bindCertReq)
|
bindCertResp, err := d.sdkClient.BindCert(ctx, bindCertReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -113,9 +113,6 @@ func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
listUserCertificateOrderPage += 1
|
listUserCertificateOrderPage += 1
|
||||||
if listUserCertificateOrderPage > 99 { // 避免死循环
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,10 +120,6 @@ func (u *AliyunSLBUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Client, error) {
|
||||||
if region == "" {
|
|
||||||
region = "cn-hangzhou" // SLB 服务默认区域:华东一杭州
|
|
||||||
}
|
|
||||||
|
|
||||||
// 接入点一览 https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-endpoint
|
// 接入点一览 https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-endpoint
|
||||||
var endpoint string
|
var endpoint string
|
||||||
switch region {
|
switch region {
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -60,9 +59,9 @@ func (u *ByteplusCDNUploader) Upload(ctx context.Context, certPem string, privke
|
|||||||
listCertInfoPageSize := int64(100)
|
listCertInfoPageSize := int64(100)
|
||||||
listCertInfoTotal := 0
|
listCertInfoTotal := 0
|
||||||
listCertInfoReq := &bpCdn.ListCertInfoRequest{
|
listCertInfoReq := &bpCdn.ListCertInfoRequest{
|
||||||
PageNum: cast.Int64Ptr(listCertInfoPageNum),
|
PageNum: bpCdn.GetInt64Ptr(listCertInfoPageNum),
|
||||||
PageSize: cast.Int64Ptr(listCertInfoPageSize),
|
PageSize: bpCdn.GetInt64Ptr(listCertInfoPageSize),
|
||||||
Source: cast.StringPtr("cert_center"),
|
Source: bpCdn.GetStrPtr("cert_center"),
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
listCertInfoResp, err := u.sdkClient.ListCertInfo(listCertInfoReq)
|
listCertInfoResp, err := u.sdkClient.ListCertInfo(listCertInfoReq)
|
||||||
@ -104,8 +103,8 @@ func (u *ByteplusCDNUploader) Upload(ctx context.Context, certPem string, privke
|
|||||||
addCertificateReq := &bpCdn.AddCertificateRequest{
|
addCertificateReq := &bpCdn.AddCertificateRequest{
|
||||||
Certificate: certPem,
|
Certificate: certPem,
|
||||||
PrivateKey: privkeyPem,
|
PrivateKey: privkeyPem,
|
||||||
Source: cast.StringPtr("cert_center"),
|
Source: bpCdn.GetStrPtr("cert_center"),
|
||||||
Desc: cast.StringPtr(certName),
|
Desc: bpCdn.GetStrPtr(certName),
|
||||||
}
|
}
|
||||||
addCertificateResp, err := u.sdkClient.AddCertificate(addCertificateReq)
|
addCertificateResp, err := u.sdkClient.AddCertificate(addCertificateReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,8 +17,8 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
|
hwsdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HuaweiCloudELBUploaderConfig struct {
|
type HuaweiCloudELBUploaderConfig struct {
|
||||||
@ -66,12 +66,11 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 遍历查询已有证书,避免重复上传
|
// 遍历查询已有证书,避免重复上传
|
||||||
// REF: https://support.huaweicloud.com/api-elb/ListCertificates.html
|
// REF: https://support.huaweicloud.com/api-elb/ListCertificates.html
|
||||||
listCertificatesPage := 1
|
|
||||||
listCertificatesLimit := int32(2000)
|
listCertificatesLimit := int32(2000)
|
||||||
var listCertificatesMarker *string = nil
|
var listCertificatesMarker *string = nil
|
||||||
for {
|
for {
|
||||||
listCertificatesReq := &hcElbModel.ListCertificatesRequest{
|
listCertificatesReq := &hcElbModel.ListCertificatesRequest{
|
||||||
Limit: cast.Int32Ptr(listCertificatesLimit),
|
Limit: hwsdk.Int32Ptr(listCertificatesLimit),
|
||||||
Marker: listCertificatesMarker,
|
Marker: listCertificatesMarker,
|
||||||
Type: &[]string{"server"},
|
Type: &[]string{"server"},
|
||||||
}
|
}
|
||||||
@ -108,10 +107,6 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
listCertificatesMarker = listCertificatesResp.PageInfo.NextMarker
|
listCertificatesMarker = listCertificatesResp.PageInfo.NextMarker
|
||||||
listCertificatesPage++
|
|
||||||
if listCertificatesPage >= 9 { // 避免死循环
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,10 +126,10 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
createCertificateReq := &hcElbModel.CreateCertificateRequest{
|
createCertificateReq := &hcElbModel.CreateCertificateRequest{
|
||||||
Body: &hcElbModel.CreateCertificateRequestBody{
|
Body: &hcElbModel.CreateCertificateRequestBody{
|
||||||
Certificate: &hcElbModel.CreateCertificateOption{
|
Certificate: &hcElbModel.CreateCertificateOption{
|
||||||
ProjectId: cast.StringPtr(projectId),
|
ProjectId: hwsdk.StringPtr(projectId),
|
||||||
Name: cast.StringPtr(certName),
|
Name: hwsdk.StringPtr(certName),
|
||||||
Certificate: cast.StringPtr(certPem),
|
Certificate: hwsdk.StringPtr(certPem),
|
||||||
PrivateKey: cast.StringPtr(privkeyPem),
|
PrivateKey: hwsdk.StringPtr(privkeyPem),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
|
hwsdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HuaweiCloudSCMUploaderConfig struct {
|
type HuaweiCloudSCMUploaderConfig struct {
|
||||||
@ -63,15 +63,14 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
// 遍历查询已有证书,避免重复上传
|
// 遍历查询已有证书,避免重复上传
|
||||||
// REF: https://support.huaweicloud.com/api-ccm/ListCertificates.html
|
// REF: https://support.huaweicloud.com/api-ccm/ListCertificates.html
|
||||||
// REF: https://support.huaweicloud.com/api-ccm/ExportCertificate_0.html
|
// REF: https://support.huaweicloud.com/api-ccm/ExportCertificate_0.html
|
||||||
listCertificatesPage := 1
|
|
||||||
listCertificatesLimit := int32(50)
|
listCertificatesLimit := int32(50)
|
||||||
listCertificatesOffset := int32(0)
|
listCertificatesOffset := int32(0)
|
||||||
for {
|
for {
|
||||||
listCertificatesReq := &hcScmModel.ListCertificatesRequest{
|
listCertificatesReq := &hcScmModel.ListCertificatesRequest{
|
||||||
Limit: cast.Int32Ptr(listCertificatesLimit),
|
Limit: hwsdk.Int32Ptr(listCertificatesLimit),
|
||||||
Offset: cast.Int32Ptr(listCertificatesOffset),
|
Offset: hwsdk.Int32Ptr(listCertificatesOffset),
|
||||||
SortDir: cast.StringPtr("DESC"),
|
SortDir: hwsdk.StringPtr("DESC"),
|
||||||
SortKey: cast.StringPtr("certExpiredTime"),
|
SortKey: hwsdk.StringPtr("certExpiredTime"),
|
||||||
}
|
}
|
||||||
listCertificatesResp, err := u.sdkClient.ListCertificates(listCertificatesReq)
|
listCertificatesResp, err := u.sdkClient.ListCertificates(listCertificatesReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -117,10 +116,6 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
listCertificatesOffset += listCertificatesLimit
|
listCertificatesOffset += listCertificatesLimit
|
||||||
listCertificatesPage += 1
|
|
||||||
if listCertificatesPage > 99 { // 避免死循环
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ import (
|
|||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
veCdn "github.com/volcengine/volc-sdk-golang/service/cdn"
|
veCdn "github.com/volcengine/volc-sdk-golang/service/cdn"
|
||||||
|
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -60,8 +60,8 @@ func (u *VolcEngineCDNUploader) Upload(ctx context.Context, certPem string, priv
|
|||||||
listCertInfoPageSize := int64(100)
|
listCertInfoPageSize := int64(100)
|
||||||
listCertInfoTotal := 0
|
listCertInfoTotal := 0
|
||||||
listCertInfoReq := &veCdn.ListCertInfoRequest{
|
listCertInfoReq := &veCdn.ListCertInfoRequest{
|
||||||
PageNum: cast.Int64Ptr(listCertInfoPageNum),
|
PageNum: ve.Int64(listCertInfoPageNum),
|
||||||
PageSize: cast.Int64Ptr(listCertInfoPageSize),
|
PageSize: ve.Int64(listCertInfoPageSize),
|
||||||
Source: "volc_cert_center",
|
Source: "volc_cert_center",
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
@ -104,8 +104,8 @@ func (u *VolcEngineCDNUploader) Upload(ctx context.Context, certPem string, priv
|
|||||||
addCertificateReq := &veCdn.AddCertificateRequest{
|
addCertificateReq := &veCdn.AddCertificateRequest{
|
||||||
Certificate: certPem,
|
Certificate: certPem,
|
||||||
PrivateKey: privkeyPem,
|
PrivateKey: privkeyPem,
|
||||||
Source: cast.StringPtr("volc_cert_center"),
|
Source: ve.String("volc_cert_center"),
|
||||||
Desc: cast.StringPtr(certName),
|
Desc: ve.String(certName),
|
||||||
}
|
}
|
||||||
addCertificateResp, err := u.sdkClient.AddCertificate(addCertificateReq)
|
addCertificateResp, err := u.sdkClient.AddCertificate(addCertificateReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,9 +9,9 @@ import (
|
|||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
veLive "github.com/volcengine/volc-sdk-golang/service/live/v20230101"
|
veLive "github.com/volcengine/volc-sdk-golang/service/live/v20230101"
|
||||||
|
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ func (u *VolcEngineLiveUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
// 查询证书详细信息
|
// 查询证书详细信息
|
||||||
// REF: https://www.volcengine.com/docs/6469/1186278#%E6%9F%A5%E7%9C%8B%E8%AF%81%E4%B9%A6%E8%AF%A6%E6%83%85
|
// REF: https://www.volcengine.com/docs/6469/1186278#%E6%9F%A5%E7%9C%8B%E8%AF%81%E4%B9%A6%E8%AF%A6%E6%83%85
|
||||||
describeCertDetailSecretReq := &veLive.DescribeCertDetailSecretV2Body{
|
describeCertDetailSecretReq := &veLive.DescribeCertDetailSecretV2Body{
|
||||||
ChainID: cast.StringPtr(certDetail.ChainID),
|
ChainID: ve.String(certDetail.ChainID),
|
||||||
}
|
}
|
||||||
describeCertDetailSecretResp, err := u.sdkClient.DescribeCertDetailSecretV2(ctx, describeCertDetailSecretReq)
|
describeCertDetailSecretResp, err := u.sdkClient.DescribeCertDetailSecretV2(ctx, describeCertDetailSecretReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,9 +100,9 @@ func (u *VolcEngineLiveUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
// 上传新证书
|
// 上传新证书
|
||||||
// REF: https://www.volcengine.com/docs/6469/1186278#%E6%B7%BB%E5%8A%A0%E8%AF%81%E4%B9%A6
|
// REF: https://www.volcengine.com/docs/6469/1186278#%E6%B7%BB%E5%8A%A0%E8%AF%81%E4%B9%A6
|
||||||
createCertReq := &veLive.CreateCertBody{
|
createCertReq := &veLive.CreateCertBody{
|
||||||
CertName: &certName,
|
CertName: ve.String(certName),
|
||||||
UseWay: "https",
|
UseWay: "https",
|
||||||
ProjectName: cast.StringPtr("default"),
|
ProjectName: ve.String("default"),
|
||||||
Rsa: veLive.CreateCertBodyRsa{
|
Rsa: veLive.CreateCertBodyRsa{
|
||||||
Prikey: privkeyPem,
|
Prikey: privkeyPem,
|
||||||
Pubkey: certPem,
|
Pubkey: certPem,
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
package cast
|
|
||||||
|
|
||||||
func Int32Ptr(i int32) *int32 {
|
|
||||||
return &i
|
|
||||||
}
|
|
||||||
|
|
||||||
func Int64Ptr(i int64) *int64 {
|
|
||||||
return &i
|
|
||||||
}
|
|
||||||
|
|
||||||
func UInt32Ptr(i uint32) *uint32 {
|
|
||||||
return &i
|
|
||||||
}
|
|
||||||
|
|
||||||
func UInt64Ptr(i uint64) *uint64 {
|
|
||||||
return &i
|
|
||||||
}
|
|
||||||
|
|
||||||
func StringPtr(s string) *string {
|
|
||||||
return &s
|
|
||||||
}
|
|
||||||
|
|
||||||
func BoolPtr(b bool) *bool {
|
|
||||||
return &b
|
|
||||||
}
|
|
9
internal/pkg/vendors/huaweicloud-sdk/cast.go
vendored
Normal file
9
internal/pkg/vendors/huaweicloud-sdk/cast.go
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package huaweicloudsdk
|
||||||
|
|
||||||
|
func Int32Ptr(i int32) *int32 {
|
||||||
|
return &i
|
||||||
|
}
|
||||||
|
|
||||||
|
func StringPtr(s string) *string {
|
||||||
|
return &s
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
import (
|
import (
|
||||||
hcCdnModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
|
hcCdnModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
hwsdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateDomainMultiCertificatesExRequestBodyContent struct {
|
type UpdateDomainMultiCertificatesExRequestBodyContent struct {
|
||||||
@ -34,11 +34,11 @@ func (m *UpdateDomainMultiCertificatesExRequestBodyContent) MergeConfig(src *hcC
|
|||||||
// 而且蛋疼的是查询接口返回的数据结构和更新接口传入的参数结构不一致,需要做很多转化。
|
// 而且蛋疼的是查询接口返回的数据结构和更新接口传入的参数结构不一致,需要做很多转化。
|
||||||
|
|
||||||
if *src.OriginProtocol == "follow" {
|
if *src.OriginProtocol == "follow" {
|
||||||
m.AccessOriginWay = cast.Int32Ptr(1)
|
m.AccessOriginWay = hwsdk.Int32Ptr(1)
|
||||||
} else if *src.OriginProtocol == "http" {
|
} else if *src.OriginProtocol == "http" {
|
||||||
m.AccessOriginWay = cast.Int32Ptr(2)
|
m.AccessOriginWay = hwsdk.Int32Ptr(2)
|
||||||
} else if *src.OriginProtocol == "https" {
|
} else if *src.OriginProtocol == "https" {
|
||||||
m.AccessOriginWay = cast.Int32Ptr(3)
|
m.AccessOriginWay = hwsdk.Int32Ptr(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
if src.ForceRedirect != nil {
|
if src.ForceRedirect != nil {
|
||||||
@ -54,7 +54,7 @@ func (m *UpdateDomainMultiCertificatesExRequestBodyContent) MergeConfig(src *hcC
|
|||||||
|
|
||||||
if src.Https != nil {
|
if src.Https != nil {
|
||||||
if *src.Https.Http2Status == "on" {
|
if *src.Https.Http2Status == "on" {
|
||||||
m.Http2 = cast.Int32Ptr(1)
|
m.Http2 = hwsdk.Int32Ptr(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user