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
43d851c7ef
commit
752acb591f
@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bceDns "github.com/baidubce/bce-sdk-go/services/dns"
|
bcedns "github.com/baidubce/bce-sdk-go/services/dns"
|
||||||
"github.com/go-acme/lego/v4/challenge"
|
"github.com/go-acme/lego/v4/challenge"
|
||||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||||
"github.com/go-acme/lego/v4/platform/config/env"
|
"github.com/go-acme/lego/v4/platform/config/env"
|
||||||
@ -38,7 +38,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DNSProvider struct {
|
type DNSProvider struct {
|
||||||
client *bceDns.Client
|
client *bcedns.Client
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
|
|||||||
return nil, errors.New("baiducloud: the configuration of the DNS provider is nil")
|
return nil, errors.New("baiducloud: the configuration of the DNS provider is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := bceDns.NewClient(config.AccessKeyID, config.SecretAccessKey, "")
|
client, err := bcedns.NewClient(config.AccessKeyID, config.SecretAccessKey, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
@ -128,11 +128,11 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
|
|||||||
return d.config.PropagationTimeout, d.config.PollingInterval
|
return d.config.PropagationTimeout, d.config.PollingInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSProvider) getDNSRecord(zoneName, subDomain string) (*bceDns.Record, error) {
|
func (d *DNSProvider) getDNSRecord(zoneName, subDomain string) (*bcedns.Record, error) {
|
||||||
pageMarker := ""
|
pageMarker := ""
|
||||||
pageSize := 1000
|
pageSize := 1000
|
||||||
for {
|
for {
|
||||||
request := &bceDns.ListRecordRequest{}
|
request := &bcedns.ListRecordRequest{}
|
||||||
request.Rr = subDomain
|
request.Rr = subDomain
|
||||||
request.Marker = pageMarker
|
request.Marker = pageMarker
|
||||||
request.MaxKeys = pageSize
|
request.MaxKeys = pageSize
|
||||||
@ -165,7 +165,7 @@ func (d *DNSProvider) addOrUpdateDNSRecord(zoneName, subDomain, value string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if record == nil {
|
if record == nil {
|
||||||
request := &bceDns.CreateRecordRequest{
|
request := &bcedns.CreateRecordRequest{
|
||||||
Type: "TXT",
|
Type: "TXT",
|
||||||
Rr: subDomain,
|
Rr: subDomain,
|
||||||
Value: value,
|
Value: value,
|
||||||
@ -174,7 +174,7 @@ func (d *DNSProvider) addOrUpdateDNSRecord(zoneName, subDomain, value string) er
|
|||||||
err := d.client.CreateRecord(zoneName, request, d.generateClientToken())
|
err := d.client.CreateRecord(zoneName, request, d.generateClientToken())
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
request := &bceDns.UpdateRecordRequest{
|
request := &bcedns.UpdateRecordRequest{
|
||||||
Type: "TXT",
|
Type: "TXT",
|
||||||
Rr: subDomain,
|
Rr: subDomain,
|
||||||
Value: value,
|
Value: value,
|
||||||
|
@ -8,10 +8,10 @@ import (
|
|||||||
"github.com/go-acme/lego/v4/challenge"
|
"github.com/go-acme/lego/v4/challenge"
|
||||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||||
"github.com/go-acme/lego/v4/platform/config/env"
|
"github.com/go-acme/lego/v4/platform/config/env"
|
||||||
jdCore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
jdcore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
||||||
jdDnsApi "github.com/jdcloud-api/jdcloud-sdk-go/services/domainservice/apis"
|
jddnsapi "github.com/jdcloud-api/jdcloud-sdk-go/services/domainservice/apis"
|
||||||
jdDnsClient "github.com/jdcloud-api/jdcloud-sdk-go/services/domainservice/client"
|
jddnsclient "github.com/jdcloud-api/jdcloud-sdk-go/services/domainservice/client"
|
||||||
jdDnsModel "github.com/jdcloud-api/jdcloud-sdk-go/services/domainservice/models"
|
jddnsmodel "github.com/jdcloud-api/jdcloud-sdk-go/services/domainservice/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -41,7 +41,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DNSProvider struct {
|
type DNSProvider struct {
|
||||||
client *jdDnsClient.DomainserviceClient
|
client *jddnsclient.DomainserviceClient
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,12 +73,12 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
|
|||||||
return nil, errors.New("jdcloud: the configuration of the DNS provider is nil")
|
return nil, errors.New("jdcloud: the configuration of the DNS provider is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
clientCredentials := jdCore.NewCredentials(config.AccessKeyID, config.AccessKeySecret)
|
clientCredentials := jdcore.NewCredentials(config.AccessKeyID, config.AccessKeySecret)
|
||||||
client := jdDnsClient.NewDomainserviceClient(clientCredentials)
|
client := jddnsclient.NewDomainserviceClient(clientCredentials)
|
||||||
clientConfig := &client.Config
|
clientConfig := &client.Config
|
||||||
clientConfig.SetTimeout(config.HTTPTimeout)
|
clientConfig.SetTimeout(config.HTTPTimeout)
|
||||||
client.SetConfig(clientConfig)
|
client.SetConfig(clientConfig)
|
||||||
client.SetLogger(jdCore.NewDefaultLogger(jdCore.LogWarn))
|
client.SetLogger(jdcore.NewDefaultLogger(jdcore.LogWarn))
|
||||||
|
|
||||||
return &DNSProvider{
|
return &DNSProvider{
|
||||||
client: client,
|
client: client,
|
||||||
@ -130,11 +130,11 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
|
|||||||
return d.config.PropagationTimeout, d.config.PollingInterval
|
return d.config.PropagationTimeout, d.config.PollingInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSProvider) getDNSZone(zoneName string) (*jdDnsModel.DomainInfo, error) {
|
func (d *DNSProvider) getDNSZone(zoneName string) (*jddnsmodel.DomainInfo, error) {
|
||||||
pageNumber := 1
|
pageNumber := 1
|
||||||
pageSize := 10
|
pageSize := 10
|
||||||
for {
|
for {
|
||||||
request := jdDnsApi.NewDescribeDomainsRequest(d.config.RegionId, pageNumber, pageSize)
|
request := jddnsapi.NewDescribeDomainsRequest(d.config.RegionId, pageNumber, pageSize)
|
||||||
request.SetDomainName(zoneName)
|
request.SetDomainName(zoneName)
|
||||||
|
|
||||||
response, err := d.client.DescribeDomains(request)
|
response, err := d.client.DescribeDomains(request)
|
||||||
@ -158,7 +158,7 @@ func (d *DNSProvider) getDNSZone(zoneName string) (*jdDnsModel.DomainInfo, error
|
|||||||
return nil, fmt.Errorf("jdcloud: zone %s not found", zoneName)
|
return nil, fmt.Errorf("jdcloud: zone %s not found", zoneName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSProvider) getDNSZoneAndRecord(zoneName, subDomain string) (*jdDnsModel.DomainInfo, *jdDnsModel.RRInfo, error) {
|
func (d *DNSProvider) getDNSZoneAndRecord(zoneName, subDomain string) (*jddnsmodel.DomainInfo, *jddnsmodel.RRInfo, error) {
|
||||||
zone, err := d.getDNSZone(zoneName)
|
zone, err := d.getDNSZone(zoneName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -167,7 +167,7 @@ func (d *DNSProvider) getDNSZoneAndRecord(zoneName, subDomain string) (*jdDnsMod
|
|||||||
pageNumber := 1
|
pageNumber := 1
|
||||||
pageSize := 10
|
pageSize := 10
|
||||||
for {
|
for {
|
||||||
request := jdDnsApi.NewDescribeResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id))
|
request := jddnsapi.NewDescribeResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id))
|
||||||
request.SetSearch(subDomain)
|
request.SetSearch(subDomain)
|
||||||
request.SetPageNumber(pageNumber)
|
request.SetPageNumber(pageNumber)
|
||||||
request.SetPageSize(pageSize)
|
request.SetPageSize(pageSize)
|
||||||
@ -200,7 +200,7 @@ func (d *DNSProvider) addOrUpdateDNSRecord(zoneName, subDomain, value string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if record == nil {
|
if record == nil {
|
||||||
request := jdDnsApi.NewCreateResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id), &jdDnsModel.AddRR{
|
request := jddnsapi.NewCreateResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id), &jddnsmodel.AddRR{
|
||||||
Type: "TXT",
|
Type: "TXT",
|
||||||
HostRecord: subDomain,
|
HostRecord: subDomain,
|
||||||
HostValue: value,
|
HostValue: value,
|
||||||
@ -210,7 +210,7 @@ func (d *DNSProvider) addOrUpdateDNSRecord(zoneName, subDomain, value string) er
|
|||||||
_, err := d.client.CreateResourceRecord(request)
|
_, err := d.client.CreateResourceRecord(request)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
request := jdDnsApi.NewModifyResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id), fmt.Sprintf("%d", record.Id), &jdDnsModel.UpdateRR{
|
request := jddnsapi.NewModifyResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id), fmt.Sprintf("%d", record.Id), &jddnsmodel.UpdateRR{
|
||||||
Type: "TXT",
|
Type: "TXT",
|
||||||
HostRecord: subDomain,
|
HostRecord: subDomain,
|
||||||
HostValue: value,
|
HostValue: value,
|
||||||
@ -231,7 +231,7 @@ func (d *DNSProvider) removeDNSRecord(zoneName, subDomain string) error {
|
|||||||
if record == nil {
|
if record == nil {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
request := jdDnsApi.NewDeleteResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id), fmt.Sprintf("%d", record.Id))
|
request := jddnsapi.NewDeleteResourceRecordRequest(d.config.RegionId, fmt.Sprintf("%d", zone.Id), fmt.Sprintf("%d", record.Id))
|
||||||
_, err = d.client.DeleteResourceRecord(request)
|
_, err = d.client.DeleteResourceRecord(request)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
aliyunAlb "github.com/alibabacloud-go/alb-20200616/v2/client"
|
alialb "github.com/alibabacloud-go/alb-20200616/v2/client"
|
||||||
aliyunCas "github.com/alibabacloud-go/cas-20200407/v3/client"
|
alicas "github.com/alibabacloud-go/cas-20200407/v3/client"
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
@ -51,8 +51,8 @@ type DeployerProvider struct {
|
|||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
|
|
||||||
type wSdkClients struct {
|
type wSdkClients struct {
|
||||||
alb *aliyunAlb.Client
|
alb *alialb.Client
|
||||||
cas *aliyunCas.Client
|
cas *alicas.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||||
@ -123,7 +123,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
|
|
||||||
// 查询负载均衡实例的详细信息
|
// 查询负载均衡实例的详细信息
|
||||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-getloadbalancerattribute
|
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-getloadbalancerattribute
|
||||||
getLoadBalancerAttributeReq := &aliyunAlb.GetLoadBalancerAttributeRequest{
|
getLoadBalancerAttributeReq := &alialb.GetLoadBalancerAttributeRequest{
|
||||||
LoadBalancerId: tea.String(d.config.LoadbalancerId),
|
LoadBalancerId: tea.String(d.config.LoadbalancerId),
|
||||||
}
|
}
|
||||||
getLoadBalancerAttributeResp, err := d.sdkClients.alb.GetLoadBalancerAttribute(getLoadBalancerAttributeReq)
|
getLoadBalancerAttributeResp, err := d.sdkClients.alb.GetLoadBalancerAttribute(getLoadBalancerAttributeReq)
|
||||||
@ -138,7 +138,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
listListenersLimit := int32(100)
|
listListenersLimit := int32(100)
|
||||||
var listListenersToken *string = nil
|
var listListenersToken *string = nil
|
||||||
for {
|
for {
|
||||||
listListenersReq := &aliyunAlb.ListListenersRequest{
|
listListenersReq := &alialb.ListListenersRequest{
|
||||||
MaxResults: tea.Int32(listListenersLimit),
|
MaxResults: tea.Int32(listListenersLimit),
|
||||||
NextToken: listListenersToken,
|
NextToken: listListenersToken,
|
||||||
LoadBalancerIds: []*string{tea.String(d.config.LoadbalancerId)},
|
LoadBalancerIds: []*string{tea.String(d.config.LoadbalancerId)},
|
||||||
@ -167,7 +167,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-listlisteners
|
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-listlisteners
|
||||||
listListenersToken = nil
|
listListenersToken = nil
|
||||||
for {
|
for {
|
||||||
listListenersReq := &aliyunAlb.ListListenersRequest{
|
listListenersReq := &alialb.ListListenersRequest{
|
||||||
MaxResults: tea.Int32(listListenersLimit),
|
MaxResults: tea.Int32(listListenersLimit),
|
||||||
NextToken: listListenersToken,
|
NextToken: listListenersToken,
|
||||||
LoadBalancerIds: []*string{tea.String(d.config.LoadbalancerId)},
|
LoadBalancerIds: []*string{tea.String(d.config.LoadbalancerId)},
|
||||||
@ -229,7 +229,7 @@ func (d *DeployerProvider) deployToListener(ctx context.Context, cloudCertId str
|
|||||||
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
||||||
// 查询监听的属性
|
// 查询监听的属性
|
||||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-getlistenerattribute
|
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-getlistenerattribute
|
||||||
getListenerAttributeReq := &aliyunAlb.GetListenerAttributeRequest{
|
getListenerAttributeReq := &alialb.GetListenerAttributeRequest{
|
||||||
ListenerId: tea.String(cloudListenerId),
|
ListenerId: tea.String(cloudListenerId),
|
||||||
}
|
}
|
||||||
getListenerAttributeResp, err := d.sdkClients.alb.GetListenerAttribute(getListenerAttributeReq)
|
getListenerAttributeResp, err := d.sdkClients.alb.GetListenerAttribute(getListenerAttributeReq)
|
||||||
@ -243,9 +243,9 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 修改监听的属性
|
// 修改监听的属性
|
||||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-updatelistenerattribute
|
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-updatelistenerattribute
|
||||||
updateListenerAttributeReq := &aliyunAlb.UpdateListenerAttributeRequest{
|
updateListenerAttributeReq := &alialb.UpdateListenerAttributeRequest{
|
||||||
ListenerId: tea.String(cloudListenerId),
|
ListenerId: tea.String(cloudListenerId),
|
||||||
Certificates: []*aliyunAlb.UpdateListenerAttributeRequestCertificates{{
|
Certificates: []*alialb.UpdateListenerAttributeRequestCertificates{{
|
||||||
CertificateId: tea.String(cloudCertId),
|
CertificateId: tea.String(cloudCertId),
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
@ -259,11 +259,11 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 查询监听证书列表
|
// 查询监听证书列表
|
||||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-listlistenercertificates
|
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-listlistenercertificates
|
||||||
listenerCertificates := make([]aliyunAlb.ListListenerCertificatesResponseBodyCertificates, 0)
|
listenerCertificates := make([]alialb.ListListenerCertificatesResponseBodyCertificates, 0)
|
||||||
listListenerCertificatesLimit := int32(100)
|
listListenerCertificatesLimit := int32(100)
|
||||||
var listListenerCertificatesToken *string = nil
|
var listListenerCertificatesToken *string = nil
|
||||||
for {
|
for {
|
||||||
listListenerCertificatesReq := &aliyunAlb.ListListenerCertificatesRequest{
|
listListenerCertificatesReq := &alialb.ListListenerCertificatesRequest{
|
||||||
NextToken: listListenerCertificatesToken,
|
NextToken: listListenerCertificatesToken,
|
||||||
MaxResults: tea.Int32(listListenerCertificatesLimit),
|
MaxResults: tea.Int32(listListenerCertificatesLimit),
|
||||||
ListenerId: tea.String(cloudListenerId),
|
ListenerId: tea.String(cloudListenerId),
|
||||||
@ -315,7 +315,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserCertificateDetailReq := &aliyunCas.GetUserCertificateDetailRequest{
|
getUserCertificateDetailReq := &alicas.GetUserCertificateDetailRequest{
|
||||||
CertId: tea.Int64(certificateIdAsInt64),
|
CertId: tea.Int64(certificateIdAsInt64),
|
||||||
}
|
}
|
||||||
getUserCertificateDetailResp, err := d.sdkClients.cas.GetUserCertificateDetail(getUserCertificateDetailReq)
|
getUserCertificateDetailResp, err := d.sdkClients.cas.GetUserCertificateDetail(getUserCertificateDetailReq)
|
||||||
@ -347,9 +347,9 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
// 关联监听和扩展证书
|
// 关联监听和扩展证书
|
||||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-associateadditionalcertificateswithlistener
|
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-associateadditionalcertificateswithlistener
|
||||||
if !certificateIsAssociated {
|
if !certificateIsAssociated {
|
||||||
associateAdditionalCertificatesFromListenerReq := &aliyunAlb.AssociateAdditionalCertificatesWithListenerRequest{
|
associateAdditionalCertificatesFromListenerReq := &alialb.AssociateAdditionalCertificatesWithListenerRequest{
|
||||||
ListenerId: tea.String(cloudListenerId),
|
ListenerId: tea.String(cloudListenerId),
|
||||||
Certificates: []*aliyunAlb.AssociateAdditionalCertificatesWithListenerRequestCertificates{
|
Certificates: []*alialb.AssociateAdditionalCertificatesWithListenerRequestCertificates{
|
||||||
{
|
{
|
||||||
CertificateId: tea.String(cloudCertId),
|
CertificateId: tea.String(cloudCertId),
|
||||||
},
|
},
|
||||||
@ -365,14 +365,14 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
// 解除关联监听和扩展证书
|
// 解除关联监听和扩展证书
|
||||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-dissociateadditionalcertificatesfromlistener
|
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-dissociateadditionalcertificatesfromlistener
|
||||||
if len(certificateIdsExpired) > 0 {
|
if len(certificateIdsExpired) > 0 {
|
||||||
dissociateAdditionalCertificates := make([]*aliyunAlb.DissociateAdditionalCertificatesFromListenerRequestCertificates, 0)
|
dissociateAdditionalCertificates := make([]*alialb.DissociateAdditionalCertificatesFromListenerRequestCertificates, 0)
|
||||||
for _, certificateId := range certificateIdsExpired {
|
for _, certificateId := range certificateIdsExpired {
|
||||||
dissociateAdditionalCertificates = append(dissociateAdditionalCertificates, &aliyunAlb.DissociateAdditionalCertificatesFromListenerRequestCertificates{
|
dissociateAdditionalCertificates = append(dissociateAdditionalCertificates, &alialb.DissociateAdditionalCertificatesFromListenerRequestCertificates{
|
||||||
CertificateId: tea.String(certificateId),
|
CertificateId: tea.String(certificateId),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
dissociateAdditionalCertificatesFromListenerReq := &aliyunAlb.DissociateAdditionalCertificatesFromListenerRequest{
|
dissociateAdditionalCertificatesFromListenerReq := &alialb.DissociateAdditionalCertificatesFromListenerRequest{
|
||||||
ListenerId: tea.String(cloudListenerId),
|
ListenerId: tea.String(cloudListenerId),
|
||||||
Certificates: dissociateAdditionalCertificates,
|
Certificates: dissociateAdditionalCertificates,
|
||||||
}
|
}
|
||||||
@ -397,12 +397,12 @@ func createSdkClients(accessKeyId, accessKeySecret, region string) (*wSdkClients
|
|||||||
albEndpoint = fmt.Sprintf("alb.%s.aliyuncs.com", region)
|
albEndpoint = fmt.Sprintf("alb.%s.aliyuncs.com", region)
|
||||||
}
|
}
|
||||||
|
|
||||||
albConfig := &aliyunOpen.Config{
|
albConfig := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(albEndpoint),
|
Endpoint: tea.String(albEndpoint),
|
||||||
}
|
}
|
||||||
albClient, err := aliyunAlb.NewClient(albConfig)
|
albClient, err := alialb.NewClient(albConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -415,12 +415,12 @@ func createSdkClients(accessKeyId, accessKeySecret, region string) (*wSdkClients
|
|||||||
casEndpoint = "cas.aliyuncs.com"
|
casEndpoint = "cas.aliyuncs.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
casConfig := &aliyunOpen.Config{
|
casConfig := &aliopen.Config{
|
||||||
Endpoint: tea.String(casEndpoint),
|
Endpoint: tea.String(casEndpoint),
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
}
|
}
|
||||||
casClient, err := aliyunCas.NewClient(casConfig)
|
casClient, err := alicas.NewClient(casConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
aliyunCas "github.com/alibabacloud-go/cas-20200407/v3/client"
|
alicas "github.com/alibabacloud-go/cas-20200407/v3/client"
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunCas.Client
|
sdkClient *alicas.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
if len(contactIds) == 0 {
|
if len(contactIds) == 0 {
|
||||||
// 获取联系人列表
|
// 获取联系人列表
|
||||||
// REF: https://help.aliyun.com/zh/ssl-certificate/developer-reference/api-cas-2020-04-07-listcontact
|
// REF: https://help.aliyun.com/zh/ssl-certificate/developer-reference/api-cas-2020-04-07-listcontact
|
||||||
listContactReq := &aliyunCas.ListContactRequest{}
|
listContactReq := &alicas.ListContactRequest{}
|
||||||
listContactReq.ShowSize = tea.Int32(1)
|
listContactReq.ShowSize = tea.Int32(1)
|
||||||
listContactReq.CurrentPage = tea.Int32(1)
|
listContactReq.CurrentPage = tea.Int32(1)
|
||||||
listContactResp, err := d.sdkClient.ListContact(listContactReq)
|
listContactResp, err := d.sdkClient.ListContact(listContactReq)
|
||||||
@ -111,7 +111,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 创建部署任务
|
// 创建部署任务
|
||||||
// REF: https://help.aliyun.com/zh/ssl-certificate/developer-reference/api-cas-2020-04-07-createdeploymentjob
|
// REF: https://help.aliyun.com/zh/ssl-certificate/developer-reference/api-cas-2020-04-07-createdeploymentjob
|
||||||
createDeploymentJobReq := &aliyunCas.CreateDeploymentJobRequest{
|
createDeploymentJobReq := &alicas.CreateDeploymentJobRequest{
|
||||||
Name: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
Name: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
JobType: tea.String("user"),
|
JobType: tea.String("user"),
|
||||||
CertIds: tea.String(upres.CertId),
|
CertIds: tea.String(upres.CertId),
|
||||||
@ -131,7 +131,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
describeDeploymentJobReq := &aliyunCas.DescribeDeploymentJobRequest{
|
describeDeploymentJobReq := &alicas.DescribeDeploymentJobRequest{
|
||||||
JobId: createDeploymentJobResp.Body.JobId,
|
JobId: createDeploymentJobResp.Body.JobId,
|
||||||
}
|
}
|
||||||
describeDeploymentJobResp, err := d.sdkClient.DescribeDeploymentJob(describeDeploymentJobReq)
|
describeDeploymentJobResp, err := d.sdkClient.DescribeDeploymentJob(describeDeploymentJobReq)
|
||||||
@ -155,7 +155,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunCas.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*alicas.Client, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-hangzhou" // CAS 服务默认区域:华东一杭州
|
region = "cn-hangzhou" // CAS 服务默认区域:华东一杭州
|
||||||
}
|
}
|
||||||
@ -169,13 +169,13 @@ func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunCas.Cl
|
|||||||
endpoint = fmt.Sprintf("cas.%s.aliyuncs.com", region)
|
endpoint = fmt.Sprintf("cas.%s.aliyuncs.com", region)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(endpoint),
|
Endpoint: tea.String(endpoint),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunCas.NewClient(config)
|
client, err := alicas.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
aliyunCdn "github.com/alibabacloud-go/cdn-20180510/v5/client"
|
alicdn "github.com/alibabacloud-go/cdn-20180510/v5/client"
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunCdn.Client
|
sdkClient *alicdn.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
@ -64,7 +64,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 设置 CDN 域名域名证书
|
// 设置 CDN 域名域名证书
|
||||||
// REF: https://help.aliyun.com/zh/cdn/developer-reference/api-cdn-2018-05-10-setcdndomainsslcertificate
|
// REF: https://help.aliyun.com/zh/cdn/developer-reference/api-cdn-2018-05-10-setcdndomainsslcertificate
|
||||||
setCdnDomainSSLCertificateReq := &aliyunCdn.SetCdnDomainSSLCertificateRequest{
|
setCdnDomainSSLCertificateReq := &alicdn.SetCdnDomainSSLCertificateRequest{
|
||||||
DomainName: tea.String(domain),
|
DomainName: tea.String(domain),
|
||||||
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
CertType: tea.String("upload"),
|
CertType: tea.String("upload"),
|
||||||
@ -81,14 +81,14 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret string) (*aliyunCdn.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret string) (*alicdn.Client, error) {
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String("cdn.aliyuncs.com"),
|
Endpoint: tea.String("cdn.aliyuncs.com"),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunCdn.NewClient(config)
|
client, err := alicdn.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
aliyunSlb "github.com/alibabacloud-go/slb-20140515/v4/client"
|
alislb "github.com/alibabacloud-go/slb-20140515/v4/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunSlb.Client
|
sdkClient *alislb.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
|
|
||||||
// 查询负载均衡实例的详细信息
|
// 查询负载均衡实例的详细信息
|
||||||
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeloadbalancerattribute
|
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeloadbalancerattribute
|
||||||
describeLoadBalancerAttributeReq := &aliyunSlb.DescribeLoadBalancerAttributeRequest{
|
describeLoadBalancerAttributeReq := &alislb.DescribeLoadBalancerAttributeRequest{
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
LoadBalancerId: tea.String(d.config.LoadbalancerId),
|
LoadBalancerId: tea.String(d.config.LoadbalancerId),
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
describeLoadBalancerListenersLimit := int32(100)
|
describeLoadBalancerListenersLimit := int32(100)
|
||||||
var describeLoadBalancerListenersToken *string = nil
|
var describeLoadBalancerListenersToken *string = nil
|
||||||
for {
|
for {
|
||||||
describeLoadBalancerListenersReq := &aliyunSlb.DescribeLoadBalancerListenersRequest{
|
describeLoadBalancerListenersReq := &alislb.DescribeLoadBalancerListenersRequest{
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
MaxResults: tea.Int32(describeLoadBalancerListenersLimit),
|
MaxResults: tea.Int32(describeLoadBalancerListenersLimit),
|
||||||
NextToken: describeLoadBalancerListenersToken,
|
NextToken: describeLoadBalancerListenersToken,
|
||||||
@ -199,7 +199,7 @@ func (d *DeployerProvider) deployToListener(ctx context.Context, cloudCertId str
|
|||||||
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudLoadbalancerId string, cloudListenerPort int32, cloudCertId string) error {
|
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudLoadbalancerId string, cloudListenerPort int32, cloudCertId string) error {
|
||||||
// 查询监听配置
|
// 查询监听配置
|
||||||
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeloadbalancerhttpslistenerattribute
|
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeloadbalancerhttpslistenerattribute
|
||||||
describeLoadBalancerHTTPSListenerAttributeReq := &aliyunSlb.DescribeLoadBalancerHTTPSListenerAttributeRequest{
|
describeLoadBalancerHTTPSListenerAttributeReq := &alislb.DescribeLoadBalancerHTTPSListenerAttributeRequest{
|
||||||
LoadBalancerId: tea.String(cloudLoadbalancerId),
|
LoadBalancerId: tea.String(cloudLoadbalancerId),
|
||||||
ListenerPort: tea.Int32(cloudListenerPort),
|
ListenerPort: tea.Int32(cloudListenerPort),
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 修改监听配置
|
// 修改监听配置
|
||||||
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-setloadbalancerhttpslistenerattribute
|
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-setloadbalancerhttpslistenerattribute
|
||||||
setLoadBalancerHTTPSListenerAttributeReq := &aliyunSlb.SetLoadBalancerHTTPSListenerAttributeRequest{
|
setLoadBalancerHTTPSListenerAttributeReq := &alislb.SetLoadBalancerHTTPSListenerAttributeRequest{
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
LoadBalancerId: tea.String(cloudLoadbalancerId),
|
LoadBalancerId: tea.String(cloudLoadbalancerId),
|
||||||
ListenerPort: tea.Int32(cloudListenerPort),
|
ListenerPort: tea.Int32(cloudListenerPort),
|
||||||
@ -230,7 +230,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 查询扩展域名
|
// 查询扩展域名
|
||||||
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describedomainextensions
|
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describedomainextensions
|
||||||
describeDomainExtensionsReq := &aliyunSlb.DescribeDomainExtensionsRequest{
|
describeDomainExtensionsReq := &alislb.DescribeDomainExtensionsRequest{
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
LoadBalancerId: tea.String(cloudLoadbalancerId),
|
LoadBalancerId: tea.String(cloudLoadbalancerId),
|
||||||
ListenerPort: tea.Int32(cloudListenerPort),
|
ListenerPort: tea.Int32(cloudListenerPort),
|
||||||
@ -251,7 +251,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
setDomainExtensionAttributeReq := &aliyunSlb.SetDomainExtensionAttributeRequest{
|
setDomainExtensionAttributeReq := &alislb.SetDomainExtensionAttributeRequest{
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
DomainExtensionId: tea.String(*domainExtension.DomainExtensionId),
|
DomainExtensionId: tea.String(*domainExtension.DomainExtensionId),
|
||||||
ServerCertificateId: tea.String(cloudCertId),
|
ServerCertificateId: tea.String(cloudCertId),
|
||||||
@ -273,7 +273,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*alislb.Client, error) {
|
||||||
// 接入点一览 https://api.aliyun.com/product/Slb
|
// 接入点一览 https://api.aliyun.com/product/Slb
|
||||||
var endpoint string
|
var endpoint string
|
||||||
switch region {
|
switch region {
|
||||||
@ -287,13 +287,13 @@ func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Cl
|
|||||||
endpoint = fmt.Sprintf("slb.%s.aliyuncs.com", region)
|
endpoint = fmt.Sprintf("slb.%s.aliyuncs.com", region)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(endpoint),
|
Endpoint: tea.String(endpoint),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunSlb.NewClient(config)
|
client, err := alislb.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
aliyunDcdn "github.com/alibabacloud-go/dcdn-20180115/v3/client"
|
alidcdn "github.com/alibabacloud-go/dcdn-20180115/v3/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunDcdn.Client
|
sdkClient *alidcdn.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
@ -64,7 +64,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 配置域名证书
|
// 配置域名证书
|
||||||
// REF: https://help.aliyun.com/zh/edge-security-acceleration/dcdn/developer-reference/api-dcdn-2018-01-15-setdcdndomainsslcertificate
|
// REF: https://help.aliyun.com/zh/edge-security-acceleration/dcdn/developer-reference/api-dcdn-2018-01-15-setdcdndomainsslcertificate
|
||||||
setDcdnDomainSSLCertificateReq := &aliyunDcdn.SetDcdnDomainSSLCertificateRequest{
|
setDcdnDomainSSLCertificateReq := &alidcdn.SetDcdnDomainSSLCertificateRequest{
|
||||||
DomainName: tea.String(domain),
|
DomainName: tea.String(domain),
|
||||||
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
CertType: tea.String("upload"),
|
CertType: tea.String("upload"),
|
||||||
@ -81,14 +81,14 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret string) (*aliyunDcdn.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret string) (*alidcdn.Client, error) {
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String("dcdn.aliyuncs.com"),
|
Endpoint: tea.String("dcdn.aliyuncs.com"),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunDcdn.NewClient(config)
|
client, err := alidcdn.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
aliyunEsa "github.com/alibabacloud-go/esa-20240910/v2/client"
|
aliesa "github.com/alibabacloud-go/esa-20240910/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunEsa.Client
|
sdkClient *aliesa.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
// 配置站点证书
|
// 配置站点证书
|
||||||
// REF: https://help.aliyun.com/zh/edge-security-acceleration/esa/api-esa-2024-09-10-setcertificate
|
// REF: https://help.aliyun.com/zh/edge-security-acceleration/esa/api-esa-2024-09-10-setcertificate
|
||||||
certId, _ := strconv.ParseInt(upres.CertId, 10, 64)
|
certId, _ := strconv.ParseInt(upres.CertId, 10, 64)
|
||||||
setCertificateReq := &aliyunEsa.SetCertificateRequest{
|
setCertificateReq := &aliesa.SetCertificateRequest{
|
||||||
SiteId: tea.Int64(d.config.SiteId),
|
SiteId: tea.Int64(d.config.SiteId),
|
||||||
Type: tea.String("cas"),
|
Type: tea.String("cas"),
|
||||||
CasId: tea.Int64(certId),
|
CasId: tea.Int64(certId),
|
||||||
@ -101,15 +101,15 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunEsa.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliesa.Client, error) {
|
||||||
// 接入点一览 https://api.aliyun.com/product/ESA
|
// 接入点一览 https://api.aliyun.com/product/ESA
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(fmt.Sprintf("esa.%s.aliyuncs.com", region)),
|
Endpoint: tea.String(fmt.Sprintf("esa.%s.aliyuncs.com", region)),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunEsa.NewClient(config)
|
client, err := aliesa.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
aliyunFc3 "github.com/alibabacloud-go/fc-20230330/v4/client"
|
alifc3 "github.com/alibabacloud-go/fc-20230330/v4/client"
|
||||||
aliyunFc2 "github.com/alibabacloud-go/fc-open-20210406/v2/client"
|
alifc2 "github.com/alibabacloud-go/fc-open-20210406/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -37,8 +37,8 @@ type DeployerProvider struct {
|
|||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
|
|
||||||
type wSdkClients struct {
|
type wSdkClients struct {
|
||||||
fc2 *aliyunFc2.Client
|
fc2 *alifc2.Client
|
||||||
fc3 *aliyunFc3.Client
|
fc3 *alifc3.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||||
@ -97,9 +97,9 @@ func (d *DeployerProvider) deployToFC3(ctx context.Context, certPem string, priv
|
|||||||
|
|
||||||
// 更新自定义域名
|
// 更新自定义域名
|
||||||
// REF: https://help.aliyun.com/zh/functioncompute/fc-3-0/developer-reference/api-fc-2023-03-30-updatecustomdomain
|
// REF: https://help.aliyun.com/zh/functioncompute/fc-3-0/developer-reference/api-fc-2023-03-30-updatecustomdomain
|
||||||
updateCustomDomainReq := &aliyunFc3.UpdateCustomDomainRequest{
|
updateCustomDomainReq := &alifc3.UpdateCustomDomainRequest{
|
||||||
Body: &aliyunFc3.UpdateCustomDomainInput{
|
Body: &alifc3.UpdateCustomDomainInput{
|
||||||
CertConfig: &aliyunFc3.CertConfig{
|
CertConfig: &alifc3.CertConfig{
|
||||||
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
Certificate: tea.String(certPem),
|
Certificate: tea.String(certPem),
|
||||||
PrivateKey: tea.String(privkeyPem),
|
PrivateKey: tea.String(privkeyPem),
|
||||||
@ -128,8 +128,8 @@ func (d *DeployerProvider) deployToFC2(ctx context.Context, certPem string, priv
|
|||||||
|
|
||||||
// 更新自定义域名
|
// 更新自定义域名
|
||||||
// REF: https://help.aliyun.com/zh/functioncompute/fc-2-0/developer-reference/api-fc-open-2021-04-06-updatecustomdomain
|
// REF: https://help.aliyun.com/zh/functioncompute/fc-2-0/developer-reference/api-fc-open-2021-04-06-updatecustomdomain
|
||||||
updateCustomDomainReq := &aliyunFc2.UpdateCustomDomainRequest{
|
updateCustomDomainReq := &alifc2.UpdateCustomDomainRequest{
|
||||||
CertConfig: &aliyunFc2.CertConfig{
|
CertConfig: &alifc2.CertConfig{
|
||||||
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
Certificate: tea.String(certPem),
|
Certificate: tea.String(certPem),
|
||||||
PrivateKey: tea.String(privkeyPem),
|
PrivateKey: tea.String(privkeyPem),
|
||||||
@ -156,24 +156,24 @@ func createSdkClients(accessKeyId, accessKeySecret, region string) (*wSdkClients
|
|||||||
fc2Endpoint = fmt.Sprintf("fc.%s.aliyuncs.com", region)
|
fc2Endpoint = fmt.Sprintf("fc.%s.aliyuncs.com", region)
|
||||||
}
|
}
|
||||||
|
|
||||||
fc2Config := &aliyunOpen.Config{
|
fc2Config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(fc2Endpoint),
|
Endpoint: tea.String(fc2Endpoint),
|
||||||
}
|
}
|
||||||
fc2Client, err := aliyunFc2.NewClient(fc2Config)
|
fc2Client, err := alifc2.NewClient(fc2Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 接入点一览 https://api.aliyun.com/product/FC-Open
|
// 接入点一览 https://api.aliyun.com/product/FC-Open
|
||||||
fc3Endpoint := fmt.Sprintf("fcv3.%s.aliyuncs.com", region)
|
fc3Endpoint := fmt.Sprintf("fcv3.%s.aliyuncs.com", region)
|
||||||
fc3Config := &aliyunOpen.Config{
|
fc3Config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(fc3Endpoint),
|
Endpoint: tea.String(fc3Endpoint),
|
||||||
}
|
}
|
||||||
fc3Client, err := aliyunFc3.NewClient(fc3Config)
|
fc3Client, err := alifc3.NewClient(fc3Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
aliyunLive "github.com/alibabacloud-go/live-20161101/client"
|
alilive "github.com/alibabacloud-go/live-20161101/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunLive.Client
|
sdkClient *alilive.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
@ -66,7 +66,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 设置域名证书
|
// 设置域名证书
|
||||||
// REF: https://help.aliyun.com/zh/live/developer-reference/api-live-2016-11-01-setlivedomaincertificate
|
// REF: https://help.aliyun.com/zh/live/developer-reference/api-live-2016-11-01-setlivedomaincertificate
|
||||||
setLiveDomainSSLCertificateReq := &aliyunLive.SetLiveDomainCertificateRequest{
|
setLiveDomainSSLCertificateReq := &alilive.SetLiveDomainCertificateRequest{
|
||||||
DomainName: tea.String(domain),
|
DomainName: tea.String(domain),
|
||||||
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
CertType: tea.String("upload"),
|
CertType: tea.String("upload"),
|
||||||
@ -83,7 +83,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunLive.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*alilive.Client, error) {
|
||||||
// 接入点一览 https://api.aliyun.com/product/live
|
// 接入点一览 https://api.aliyun.com/product/live
|
||||||
var endpoint string
|
var endpoint string
|
||||||
switch region {
|
switch region {
|
||||||
@ -100,13 +100,13 @@ func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunLive.C
|
|||||||
endpoint = fmt.Sprintf("live.%s.aliyuncs.com", region)
|
endpoint = fmt.Sprintf("live.%s.aliyuncs.com", region)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(endpoint),
|
Endpoint: tea.String(endpoint),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunLive.NewClient(config)
|
client, err := alilive.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
aliyunNlb "github.com/alibabacloud-go/nlb-20220430/v2/client"
|
alinlb "github.com/alibabacloud-go/nlb-20220430/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunNlb.Client
|
sdkClient *alinlb.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
|
|
||||||
// 查询负载均衡实例的详细信息
|
// 查询负载均衡实例的详细信息
|
||||||
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-getloadbalancerattribute
|
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-getloadbalancerattribute
|
||||||
getLoadBalancerAttributeReq := &aliyunNlb.GetLoadBalancerAttributeRequest{
|
getLoadBalancerAttributeReq := &alinlb.GetLoadBalancerAttributeRequest{
|
||||||
LoadBalancerId: tea.String(d.config.LoadbalancerId),
|
LoadBalancerId: tea.String(d.config.LoadbalancerId),
|
||||||
}
|
}
|
||||||
getLoadBalancerAttributeResp, err := d.sdkClient.GetLoadBalancerAttribute(getLoadBalancerAttributeReq)
|
getLoadBalancerAttributeResp, err := d.sdkClient.GetLoadBalancerAttribute(getLoadBalancerAttributeReq)
|
||||||
@ -126,7 +126,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
listListenersLimit := int32(100)
|
listListenersLimit := int32(100)
|
||||||
var listListenersToken *string = nil
|
var listListenersToken *string = nil
|
||||||
for {
|
for {
|
||||||
listListenersReq := &aliyunNlb.ListListenersRequest{
|
listListenersReq := &alinlb.ListListenersRequest{
|
||||||
MaxResults: tea.Int32(listListenersLimit),
|
MaxResults: tea.Int32(listListenersLimit),
|
||||||
NextToken: listListenersToken,
|
NextToken: listListenersToken,
|
||||||
LoadBalancerIds: []*string{tea.String(d.config.LoadbalancerId)},
|
LoadBalancerIds: []*string{tea.String(d.config.LoadbalancerId)},
|
||||||
@ -188,7 +188,7 @@ func (d *DeployerProvider) deployToListener(ctx context.Context, cloudCertId str
|
|||||||
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
||||||
// 查询监听的属性
|
// 查询监听的属性
|
||||||
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-getlistenerattribute
|
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-getlistenerattribute
|
||||||
getListenerAttributeReq := &aliyunNlb.GetListenerAttributeRequest{
|
getListenerAttributeReq := &alinlb.GetListenerAttributeRequest{
|
||||||
ListenerId: tea.String(cloudListenerId),
|
ListenerId: tea.String(cloudListenerId),
|
||||||
}
|
}
|
||||||
getListenerAttributeResp, err := d.sdkClient.GetListenerAttribute(getListenerAttributeReq)
|
getListenerAttributeResp, err := d.sdkClient.GetListenerAttribute(getListenerAttributeReq)
|
||||||
@ -199,7 +199,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 修改监听的属性
|
// 修改监听的属性
|
||||||
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-updatelistenerattribute
|
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-updatelistenerattribute
|
||||||
updateListenerAttributeReq := &aliyunNlb.UpdateListenerAttributeRequest{
|
updateListenerAttributeReq := &alinlb.UpdateListenerAttributeRequest{
|
||||||
ListenerId: tea.String(cloudListenerId),
|
ListenerId: tea.String(cloudListenerId),
|
||||||
CertificateIds: []*string{tea.String(cloudCertId)},
|
CertificateIds: []*string{tea.String(cloudCertId)},
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunNlb.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*alinlb.Client, error) {
|
||||||
// 接入点一览 https://api.aliyun.com/product/Nlb
|
// 接入点一览 https://api.aliyun.com/product/Nlb
|
||||||
var endpoint string
|
var endpoint string
|
||||||
switch region {
|
switch region {
|
||||||
@ -220,13 +220,13 @@ func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunNlb.Cl
|
|||||||
endpoint = fmt.Sprintf("nlb.%s.aliyuncs.com", region)
|
endpoint = fmt.Sprintf("nlb.%s.aliyuncs.com", region)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(endpoint),
|
Endpoint: tea.String(endpoint),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunNlb.NewClient(config)
|
client, err := alinlb.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
aliyunVod "github.com/alibabacloud-go/vod-20170321/v4/client"
|
alivod "github.com/alibabacloud-go/vod-20170321/v4/client"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -28,7 +28,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunVod.Client
|
sdkClient *alivod.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
@ -62,7 +62,7 @@ func (d *DeployerProvider) WithLogger(logger *slog.Logger) deployer.Deployer {
|
|||||||
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||||
// 设置域名证书
|
// 设置域名证书
|
||||||
// REF: https://help.aliyun.com/zh/vod/developer-reference/api-vod-2017-03-21-setvoddomainsslcertificate
|
// REF: https://help.aliyun.com/zh/vod/developer-reference/api-vod-2017-03-21-setvoddomainsslcertificate
|
||||||
setVodDomainSSLCertificateReq := &aliyunVod.SetVodDomainSSLCertificateRequest{
|
setVodDomainSSLCertificateReq := &alivod.SetVodDomainSSLCertificateRequest{
|
||||||
DomainName: tea.String(d.config.Domain),
|
DomainName: tea.String(d.config.Domain),
|
||||||
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
CertType: tea.String("upload"),
|
CertType: tea.String("upload"),
|
||||||
@ -79,17 +79,17 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunVod.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*alivod.Client, error) {
|
||||||
// 接入点一览 https://api.aliyun.com/product/vod
|
// 接入点一览 https://api.aliyun.com/product/vod
|
||||||
endpoint := fmt.Sprintf("vod.%s.aliyuncs.com", region)
|
endpoint := fmt.Sprintf("vod.%s.aliyuncs.com", region)
|
||||||
|
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(endpoint),
|
Endpoint: tea.String(endpoint),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunVod.NewClient(config)
|
client, err := alivod.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
aliyunWaf "github.com/alibabacloud-go/waf-openapi-20211001/v5/client"
|
aliwaf "github.com/alibabacloud-go/waf-openapi-20211001/v5/client"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -35,7 +35,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *aliyunWaf.Client
|
sdkClient *aliwaf.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func (d *DeployerProvider) deployToWAF3(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 查询默认 SSL/TLS 设置
|
// 查询默认 SSL/TLS 设置
|
||||||
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-describedefaulthttps
|
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-describedefaulthttps
|
||||||
describeDefaultHttpsReq := &aliyunWaf.DescribeDefaultHttpsRequest{
|
describeDefaultHttpsReq := &aliwaf.DescribeDefaultHttpsRequest{
|
||||||
InstanceId: tea.String(d.config.InstanceId),
|
InstanceId: tea.String(d.config.InstanceId),
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ func (d *DeployerProvider) deployToWAF3(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 修改默认 SSL/TLS 设置
|
// 修改默认 SSL/TLS 设置
|
||||||
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-modifydefaulthttps
|
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-modifydefaulthttps
|
||||||
modifyDefaultHttpsReq := &aliyunWaf.ModifyDefaultHttpsRequest{
|
modifyDefaultHttpsReq := &aliwaf.ModifyDefaultHttpsRequest{
|
||||||
InstanceId: tea.String(d.config.InstanceId),
|
InstanceId: tea.String(d.config.InstanceId),
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
CertId: tea.String(upres.CertId),
|
CertId: tea.String(upres.CertId),
|
||||||
@ -139,7 +139,7 @@ func (d *DeployerProvider) deployToWAF3(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 查询 CNAME 接入详情
|
// 查询 CNAME 接入详情
|
||||||
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-describedomaindetail
|
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-describedomaindetail
|
||||||
describeDomainDetailReq := &aliyunWaf.DescribeDomainDetailRequest{
|
describeDomainDetailReq := &aliwaf.DescribeDomainDetailRequest{
|
||||||
InstanceId: tea.String(d.config.InstanceId),
|
InstanceId: tea.String(d.config.InstanceId),
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
Domain: tea.String(d.config.Domain),
|
Domain: tea.String(d.config.Domain),
|
||||||
@ -152,16 +152,16 @@ func (d *DeployerProvider) deployToWAF3(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 修改 CNAME 接入资源
|
// 修改 CNAME 接入资源
|
||||||
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-modifydomain
|
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-modifydomain
|
||||||
modifyDomainReq := &aliyunWaf.ModifyDomainRequest{
|
modifyDomainReq := &aliwaf.ModifyDomainRequest{
|
||||||
InstanceId: tea.String(d.config.InstanceId),
|
InstanceId: tea.String(d.config.InstanceId),
|
||||||
RegionId: tea.String(d.config.Region),
|
RegionId: tea.String(d.config.Region),
|
||||||
Domain: tea.String(d.config.Domain),
|
Domain: tea.String(d.config.Domain),
|
||||||
Listen: &aliyunWaf.ModifyDomainRequestListen{
|
Listen: &aliwaf.ModifyDomainRequestListen{
|
||||||
CertId: tea.String(upres.CertId),
|
CertId: tea.String(upres.CertId),
|
||||||
TLSVersion: tea.String("tlsv1"),
|
TLSVersion: tea.String("tlsv1"),
|
||||||
EnableTLSv3: tea.Bool(false),
|
EnableTLSv3: tea.Bool(false),
|
||||||
},
|
},
|
||||||
Redirect: &aliyunWaf.ModifyDomainRequestRedirect{
|
Redirect: &aliwaf.ModifyDomainRequestRedirect{
|
||||||
Loadbalance: tea.String("iphash"),
|
Loadbalance: tea.String("iphash"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -186,15 +186,15 @@ func (d *DeployerProvider) deployToWAF3(ctx context.Context, certPem string, pri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunWaf.Client, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliwaf.Client, error) {
|
||||||
// 接入点一览:https://api.aliyun.com/product/waf-openapi
|
// 接入点一览:https://api.aliyun.com/product/waf-openapi
|
||||||
config := &aliyunOpen.Config{
|
config := &aliopen.Config{
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
Endpoint: tea.String(fmt.Sprintf("wafopenapi.%s.aliyuncs.com", region)),
|
Endpoint: tea.String(fmt.Sprintf("wafopenapi.%s.aliyuncs.com", region)),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := aliyunWaf.NewClient(config)
|
client, err := aliwaf.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
aws "github.com/aws/aws-sdk-go-v2/aws"
|
aws "github.com/aws/aws-sdk-go-v2/aws"
|
||||||
awsCfg "github.com/aws/aws-sdk-go-v2/config"
|
awscfg "github.com/aws/aws-sdk-go-v2/config"
|
||||||
awsCred "github.com/aws/aws-sdk-go-v2/credentials"
|
awscred "github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
awsCf "github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||||
awsCfTypes "github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
|
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -31,7 +31,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *awsCf.Client
|
sdkClient *cloudfront.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 获取分配配置
|
// 获取分配配置
|
||||||
// REF: https://docs.aws.amazon.com/en_us/cloudfront/latest/APIReference/API_GetDistributionConfig.html
|
// REF: https://docs.aws.amazon.com/en_us/cloudfront/latest/APIReference/API_GetDistributionConfig.html
|
||||||
getDistributionConfigReq := &awsCf.GetDistributionConfigInput{
|
getDistributionConfigReq := &cloudfront.GetDistributionConfigInput{
|
||||||
Id: aws.String(d.config.DistributionId),
|
Id: aws.String(d.config.DistributionId),
|
||||||
}
|
}
|
||||||
getDistributionConfigResp, err := d.sdkClient.GetDistributionConfig(context.TODO(), getDistributionConfigReq)
|
getDistributionConfigResp, err := d.sdkClient.GetDistributionConfig(context.TODO(), getDistributionConfigReq)
|
||||||
@ -100,13 +100,13 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 更新分配配置
|
// 更新分配配置
|
||||||
// REF: https://docs.aws.amazon.com/zh_cn/cloudfront/latest/APIReference/API_UpdateDistribution.html
|
// REF: https://docs.aws.amazon.com/zh_cn/cloudfront/latest/APIReference/API_UpdateDistribution.html
|
||||||
updateDistributionReq := &awsCf.UpdateDistributionInput{
|
updateDistributionReq := &cloudfront.UpdateDistributionInput{
|
||||||
Id: aws.String(d.config.DistributionId),
|
Id: aws.String(d.config.DistributionId),
|
||||||
DistributionConfig: getDistributionConfigResp.DistributionConfig,
|
DistributionConfig: getDistributionConfigResp.DistributionConfig,
|
||||||
IfMatch: getDistributionConfigResp.ETag,
|
IfMatch: getDistributionConfigResp.ETag,
|
||||||
}
|
}
|
||||||
if updateDistributionReq.DistributionConfig.ViewerCertificate == nil {
|
if updateDistributionReq.DistributionConfig.ViewerCertificate == nil {
|
||||||
updateDistributionReq.DistributionConfig.ViewerCertificate = &awsCfTypes.ViewerCertificate{}
|
updateDistributionReq.DistributionConfig.ViewerCertificate = &types.ViewerCertificate{}
|
||||||
}
|
}
|
||||||
updateDistributionReq.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate = aws.Bool(false)
|
updateDistributionReq.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate = aws.Bool(false)
|
||||||
updateDistributionReq.DistributionConfig.ViewerCertificate.ACMCertificateArn = aws.String(upres.CertId)
|
updateDistributionReq.DistributionConfig.ViewerCertificate.ACMCertificateArn = aws.String(upres.CertId)
|
||||||
@ -119,15 +119,15 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*awsCf.Client, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*cloudfront.Client, error) {
|
||||||
cfg, err := awsCfg.LoadDefaultConfig(context.TODO())
|
cfg, err := awscfg.LoadDefaultConfig(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := awsCf.NewFromConfig(cfg, func(o *awsCf.Options) {
|
client := cloudfront.NewFromConfig(cfg, func(o *cloudfront.Options) {
|
||||||
o.Region = region
|
o.Region = region
|
||||||
o.Credentials = aws.NewCredentialsCache(awsCred.NewStaticCredentialsProvider(accessKeyId, secretAccessKey, ""))
|
o.Credentials = aws.NewCredentialsCache(awscred.NewStaticCredentialsProvider(accessKeyId, secretAccessKey, ""))
|
||||||
})
|
})
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bceCdn "github.com/baidubce/bce-sdk-go/services/cdn"
|
bcecdn "github.com/baidubce/bce-sdk-go/services/cdn"
|
||||||
bceCdnApi "github.com/baidubce/bce-sdk-go/services/cdn/api"
|
bcecdnapi "github.com/baidubce/bce-sdk-go/services/cdn/api"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -25,7 +25,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *bceCdn.Client
|
sdkClient *bcecdn.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
@ -61,7 +61,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
// REF: https://cloud.baidu.com/doc/CDN/s/qjzuz2hp8
|
// REF: https://cloud.baidu.com/doc/CDN/s/qjzuz2hp8
|
||||||
putCertResp, err := d.sdkClient.PutCert(
|
putCertResp, err := d.sdkClient.PutCert(
|
||||||
d.config.Domain,
|
d.config.Domain,
|
||||||
&bceCdnApi.UserCertificate{
|
&bcecdnapi.UserCertificate{
|
||||||
CertName: fmt.Sprintf("certimate-%d", time.Now().UnixMilli()),
|
CertName: fmt.Sprintf("certimate-%d", time.Now().UnixMilli()),
|
||||||
ServerData: certPem,
|
ServerData: certPem,
|
||||||
PrivateData: privkeyPem,
|
PrivateData: privkeyPem,
|
||||||
@ -76,8 +76,8 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, secretAccessKey string) (*bceCdn.Client, error) {
|
func createSdkClient(accessKeyId, secretAccessKey string) (*bcecdn.Client, error) {
|
||||||
client, err := bceCdn.NewClient(accessKeyId, secretAccessKey, "")
|
client, err := bcecdn.NewClient(accessKeyId, secretAccessKey, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
bpCdn "github.com/byteplus-sdk/byteplus-sdk-golang/service/cdn"
|
bpcdn "github.com/byteplus-sdk/byteplus-sdk-golang/service/cdn"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -26,7 +26,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *bpCdn.CDN
|
sdkClient *bpcdn.CDN
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
|||||||
panic("config is nil")
|
panic("config is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
client := bpCdn.NewInstance()
|
client := bpcdn.NewInstance()
|
||||||
client.Client.SetAccessKey(config.AccessKey)
|
client.Client.SetAccessKey(config.AccessKey)
|
||||||
client.Client.SetSecretKey(config.SecretKey)
|
client.Client.SetSecretKey(config.SecretKey)
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
if strings.HasPrefix(d.config.Domain, "*.") {
|
if strings.HasPrefix(d.config.Domain, "*.") {
|
||||||
// 获取指定证书可关联的域名
|
// 获取指定证书可关联的域名
|
||||||
// REF: https://docs.byteplus.com/en/docs/byteplus-cdn/reference-describecertconfig-9ea17
|
// REF: https://docs.byteplus.com/en/docs/byteplus-cdn/reference-describecertconfig-9ea17
|
||||||
describeCertConfigReq := &bpCdn.DescribeCertConfigRequest{
|
describeCertConfigReq := &bpcdn.DescribeCertConfigRequest{
|
||||||
CertId: upres.CertId,
|
CertId: upres.CertId,
|
||||||
}
|
}
|
||||||
describeCertConfigResp, err := d.sdkClient.DescribeCertConfig(describeCertConfigReq)
|
describeCertConfigResp, err := d.sdkClient.DescribeCertConfig(describeCertConfigReq)
|
||||||
@ -119,7 +119,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
for _, domain := range domains {
|
for _, domain := range domains {
|
||||||
// 关联证书与加速域名
|
// 关联证书与加速域名
|
||||||
// REF: https://docs.byteplus.com/en/docs/byteplus-cdn/reference-batchdeploycert
|
// REF: https://docs.byteplus.com/en/docs/byteplus-cdn/reference-batchdeploycert
|
||||||
batchDeployCertReq := &bpCdn.BatchDeployCertRequest{
|
batchDeployCertReq := &bpcdn.BatchDeployCertRequest{
|
||||||
CertId: upres.CertId,
|
CertId: upres.CertId,
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/certutil"
|
"github.com/usual2970/certimate/internal/pkg/utils/certutil"
|
||||||
edgsdk "github.com/usual2970/certimate/internal/pkg/vendors/edgio-sdk/applications/v7"
|
edgsdk "github.com/usual2970/certimate/internal/pkg/vendors/edgio-sdk/applications/v7"
|
||||||
edgsdkDtos "github.com/usual2970/certimate/internal/pkg/vendors/edgio-sdk/applications/v7/dtos"
|
edgsdkdtos "github.com/usual2970/certimate/internal/pkg/vendors/edgio-sdk/applications/v7/dtos"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeployerConfig struct {
|
type DeployerConfig struct {
|
||||||
@ -64,7 +64,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 上传 TLS 证书
|
// 上传 TLS 证书
|
||||||
// REF: https://docs.edg.io/rest_api/#tag/tls-certs/operation/postConfigV01TlsCerts
|
// REF: https://docs.edg.io/rest_api/#tag/tls-certs/operation/postConfigV01TlsCerts
|
||||||
uploadTlsCertReq := edgsdkDtos.UploadTlsCertRequest{
|
uploadTlsCertReq := edgsdkdtos.UploadTlsCertRequest{
|
||||||
EnvironmentID: d.config.EnvironmentId,
|
EnvironmentID: d.config.EnvironmentId,
|
||||||
PrimaryCert: privateCertPem,
|
PrimaryCert: privateCertPem,
|
||||||
IntermediateCert: intermediateCertPem,
|
IntermediateCert: intermediateCertPem,
|
||||||
|
@ -5,9 +5,9 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
|
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
|
||||||
hcCdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
|
hccdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
|
||||||
hcCdnModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
|
hccdnmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
|
||||||
hcCdnRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
|
hccdnregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -30,7 +30,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *hcCdn.CdnClient
|
sdkClient *hccdn.CdnClient
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 查询加速域名配置
|
// 查询加速域名配置
|
||||||
// REF: https://support.huaweicloud.com/api-cdn/ShowDomainFullConfig.html
|
// REF: https://support.huaweicloud.com/api-cdn/ShowDomainFullConfig.html
|
||||||
showDomainFullConfigReq := &hcCdnModel.ShowDomainFullConfigRequest{
|
showDomainFullConfigReq := &hccdnmodel.ShowDomainFullConfigRequest{
|
||||||
DomainName: d.config.Domain,
|
DomainName: d.config.Domain,
|
||||||
}
|
}
|
||||||
showDomainFullConfigResp, err := d.sdkClient.ShowDomainFullConfig(showDomainFullConfigReq)
|
showDomainFullConfigResp, err := d.sdkClient.ShowDomainFullConfig(showDomainFullConfigReq)
|
||||||
@ -99,15 +99,15 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
// 更新加速域名配置
|
// 更新加速域名配置
|
||||||
// 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 := &hcCdnModel.UpdateDomainMultiCertificatesRequestBodyContent{}
|
updateDomainMultiCertificatesReqBodyContent := &hccdnmodel.UpdateDomainMultiCertificatesRequestBodyContent{}
|
||||||
updateDomainMultiCertificatesReqBodyContent.DomainName = d.config.Domain
|
updateDomainMultiCertificatesReqBodyContent.DomainName = d.config.Domain
|
||||||
updateDomainMultiCertificatesReqBodyContent.HttpsSwitch = 1
|
updateDomainMultiCertificatesReqBodyContent.HttpsSwitch = 1
|
||||||
updateDomainMultiCertificatesReqBodyContent.CertificateType = hwsdk.Int32Ptr(2)
|
updateDomainMultiCertificatesReqBodyContent.CertificateType = hwsdk.Int32Ptr(2)
|
||||||
updateDomainMultiCertificatesReqBodyContent.ScmCertificateId = hwsdk.StringPtr(upres.CertId)
|
updateDomainMultiCertificatesReqBodyContent.ScmCertificateId = hwsdk.StringPtr(upres.CertId)
|
||||||
updateDomainMultiCertificatesReqBodyContent.CertName = hwsdk.StringPtr(upres.CertName)
|
updateDomainMultiCertificatesReqBodyContent.CertName = hwsdk.StringPtr(upres.CertName)
|
||||||
updateDomainMultiCertificatesReqBodyContent = assign(updateDomainMultiCertificatesReqBodyContent, showDomainFullConfigResp.Configs)
|
updateDomainMultiCertificatesReqBodyContent = assign(updateDomainMultiCertificatesReqBodyContent, showDomainFullConfigResp.Configs)
|
||||||
updateDomainMultiCertificatesReq := &hcCdnModel.UpdateDomainMultiCertificatesRequest{
|
updateDomainMultiCertificatesReq := &hccdnmodel.UpdateDomainMultiCertificatesRequest{
|
||||||
Body: &hcCdnModel.UpdateDomainMultiCertificatesRequestBody{
|
Body: &hccdnmodel.UpdateDomainMultiCertificatesRequestBody{
|
||||||
Https: updateDomainMultiCertificatesReqBodyContent,
|
Https: updateDomainMultiCertificatesReqBodyContent,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcCdn.CdnClient, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hccdn.CdnClient, error) {
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "cn-north-1" // CDN 服务默认区域:华北一北京
|
region = "cn-north-1" // CDN 服务默认区域:华北一北京
|
||||||
}
|
}
|
||||||
@ -133,12 +133,12 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcCdn.CdnCli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcRegion, err := hcCdnRegion.SafeValueOf(region)
|
hcRegion, err := hccdnregion.SafeValueOf(region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcClient, err := hcCdn.CdnClientBuilder().
|
hcClient, err := hccdn.CdnClientBuilder().
|
||||||
WithRegion(hcRegion).
|
WithRegion(hcRegion).
|
||||||
WithCredential(auth).
|
WithCredential(auth).
|
||||||
SafeBuild()
|
SafeBuild()
|
||||||
@ -146,11 +146,11 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcCdn.CdnCli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := hcCdn.NewCdnClient(hcClient)
|
client := hccdn.NewCdnClient(hcClient)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func assign(reqContent *hcCdnModel.UpdateDomainMultiCertificatesRequestBodyContent, target *hcCdnModel.ConfigsGetBody) *hcCdnModel.UpdateDomainMultiCertificatesRequestBodyContent {
|
func assign(reqContent *hccdnmodel.UpdateDomainMultiCertificatesRequestBodyContent, target *hccdnmodel.ConfigsGetBody) *hccdnmodel.UpdateDomainMultiCertificatesRequestBodyContent {
|
||||||
if target == nil {
|
if target == nil {
|
||||||
return reqContent
|
return reqContent
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ func assign(reqContent *hcCdnModel.UpdateDomainMultiCertificatesRequestBodyConte
|
|||||||
}
|
}
|
||||||
|
|
||||||
if target.ForceRedirect != nil {
|
if target.ForceRedirect != nil {
|
||||||
reqContent.ForceRedirectConfig = &hcCdnModel.ForceRedirect{}
|
reqContent.ForceRedirectConfig = &hccdnmodel.ForceRedirect{}
|
||||||
|
|
||||||
if target.ForceRedirect.Status == "on" {
|
if target.ForceRedirect.Status == "on" {
|
||||||
reqContent.ForceRedirectConfig.Switch = 1
|
reqContent.ForceRedirectConfig.Switch = 1
|
||||||
|
@ -8,12 +8,12 @@ import (
|
|||||||
|
|
||||||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
|
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
|
||||||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
|
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
|
||||||
hcElb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
|
hcelb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
|
||||||
hcElbModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
|
hcelbmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
|
||||||
hcElbRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region"
|
hcelbregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region"
|
||||||
hcIam "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3"
|
hciam "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3"
|
||||||
hcIamModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/model"
|
hciammodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/model"
|
||||||
hcIamRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
hciamregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *hcElb.ElbClient
|
sdkClient *hcelb.ElbClient
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +121,10 @@ func (d *DeployerProvider) deployToCertificate(ctx context.Context, certPem stri
|
|||||||
|
|
||||||
// 更新证书
|
// 更新证书
|
||||||
// REF: https://support.huaweicloud.com/api-elb/UpdateCertificate.html
|
// REF: https://support.huaweicloud.com/api-elb/UpdateCertificate.html
|
||||||
updateCertificateReq := &hcElbModel.UpdateCertificateRequest{
|
updateCertificateReq := &hcelbmodel.UpdateCertificateRequest{
|
||||||
CertificateId: d.config.CertificateId,
|
CertificateId: d.config.CertificateId,
|
||||||
Body: &hcElbModel.UpdateCertificateRequestBody{
|
Body: &hcelbmodel.UpdateCertificateRequestBody{
|
||||||
Certificate: &hcElbModel.UpdateCertificateOption{
|
Certificate: &hcelbmodel.UpdateCertificateOption{
|
||||||
Certificate: hwsdk.StringPtr(certPem),
|
Certificate: hwsdk.StringPtr(certPem),
|
||||||
PrivateKey: hwsdk.StringPtr(privkeyPem),
|
PrivateKey: hwsdk.StringPtr(privkeyPem),
|
||||||
},
|
},
|
||||||
@ -146,7 +146,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, certPem str
|
|||||||
|
|
||||||
// 查询负载均衡器详情
|
// 查询负载均衡器详情
|
||||||
// REF: https://support.huaweicloud.com/api-elb/ShowLoadBalancer.html
|
// REF: https://support.huaweicloud.com/api-elb/ShowLoadBalancer.html
|
||||||
showLoadBalancerReq := &hcElbModel.ShowLoadBalancerRequest{
|
showLoadBalancerReq := &hcelbmodel.ShowLoadBalancerRequest{
|
||||||
LoadbalancerId: d.config.LoadbalancerId,
|
LoadbalancerId: d.config.LoadbalancerId,
|
||||||
}
|
}
|
||||||
showLoadBalancerResp, err := d.sdkClient.ShowLoadBalancer(showLoadBalancerReq)
|
showLoadBalancerResp, err := d.sdkClient.ShowLoadBalancer(showLoadBalancerReq)
|
||||||
@ -161,7 +161,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, certPem str
|
|||||||
listListenersLimit := int32(2000)
|
listListenersLimit := int32(2000)
|
||||||
var listListenersMarker *string = nil
|
var listListenersMarker *string = nil
|
||||||
for {
|
for {
|
||||||
listListenersReq := &hcElbModel.ListListenersRequest{
|
listListenersReq := &hcelbmodel.ListListenersRequest{
|
||||||
Limit: hwsdk.Int32Ptr(listListenersLimit),
|
Limit: hwsdk.Int32Ptr(listListenersLimit),
|
||||||
Marker: listListenersMarker,
|
Marker: listListenersMarker,
|
||||||
Protocol: &[]string{"HTTPS", "TERMINATED_HTTPS"},
|
Protocol: &[]string{"HTTPS", "TERMINATED_HTTPS"},
|
||||||
@ -239,7 +239,7 @@ func (d *DeployerProvider) deployToListener(ctx context.Context, certPem string,
|
|||||||
func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
||||||
// 查询监听器详情
|
// 查询监听器详情
|
||||||
// REF: https://support.huaweicloud.com/api-elb/ShowListener.html
|
// REF: https://support.huaweicloud.com/api-elb/ShowListener.html
|
||||||
showListenerReq := &hcElbModel.ShowListenerRequest{
|
showListenerReq := &hcelbmodel.ShowListenerRequest{
|
||||||
ListenerId: cloudListenerId,
|
ListenerId: cloudListenerId,
|
||||||
}
|
}
|
||||||
showListenerResp, err := d.sdkClient.ShowListener(showListenerReq)
|
showListenerResp, err := d.sdkClient.ShowListener(showListenerReq)
|
||||||
@ -250,10 +250,10 @@ func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 更新监听器
|
// 更新监听器
|
||||||
// REF: https://support.huaweicloud.com/api-elb/UpdateListener.html
|
// REF: https://support.huaweicloud.com/api-elb/UpdateListener.html
|
||||||
updateListenerReq := &hcElbModel.UpdateListenerRequest{
|
updateListenerReq := &hcelbmodel.UpdateListenerRequest{
|
||||||
ListenerId: cloudListenerId,
|
ListenerId: cloudListenerId,
|
||||||
Body: &hcElbModel.UpdateListenerRequestBody{
|
Body: &hcelbmodel.UpdateListenerRequestBody{
|
||||||
Listener: &hcElbModel.UpdateListenerOption{
|
Listener: &hcelbmodel.UpdateListenerOption{
|
||||||
DefaultTlsContainerRef: hwsdk.StringPtr(cloudCertId),
|
DefaultTlsContainerRef: hwsdk.StringPtr(cloudCertId),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -264,7 +264,7 @@ func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudL
|
|||||||
sniCertIds := make([]string, 0)
|
sniCertIds := make([]string, 0)
|
||||||
sniCertIds = append(sniCertIds, cloudCertId)
|
sniCertIds = append(sniCertIds, cloudCertId)
|
||||||
|
|
||||||
listOldCertificateReq := &hcElbModel.ListCertificatesRequest{
|
listOldCertificateReq := &hcelbmodel.ListCertificatesRequest{
|
||||||
Id: &showListenerResp.Listener.SniContainerRefs,
|
Id: &showListenerResp.Listener.SniContainerRefs,
|
||||||
}
|
}
|
||||||
listOldCertificateResp, err := d.sdkClient.ListCertificates(listOldCertificateReq)
|
listOldCertificateResp, err := d.sdkClient.ListCertificates(listOldCertificateReq)
|
||||||
@ -273,7 +273,7 @@ func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudL
|
|||||||
return xerrors.Wrap(err, "failed to execute sdk request 'elb.ListCertificates'")
|
return xerrors.Wrap(err, "failed to execute sdk request 'elb.ListCertificates'")
|
||||||
}
|
}
|
||||||
|
|
||||||
showNewCertificateReq := &hcElbModel.ShowCertificateRequest{
|
showNewCertificateReq := &hcelbmodel.ShowCertificateRequest{
|
||||||
CertificateId: cloudCertId,
|
CertificateId: cloudCertId,
|
||||||
}
|
}
|
||||||
showNewCertificateResp, err := d.sdkClient.ShowCertificate(showNewCertificateReq)
|
showNewCertificateResp, err := d.sdkClient.ShowCertificate(showNewCertificateReq)
|
||||||
@ -315,7 +315,7 @@ func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudL
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbClient, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcelb.ElbClient, error) {
|
||||||
projectId, err := getSdkProjectId(accessKeyId, secretAccessKey, region)
|
projectId, err := getSdkProjectId(accessKeyId, secretAccessKey, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -330,12 +330,12 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbCli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcRegion, err := hcElbRegion.SafeValueOf(region)
|
hcRegion, err := hcelbregion.SafeValueOf(region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcClient, err := hcElb.ElbClientBuilder().
|
hcClient, err := hcelb.ElbClientBuilder().
|
||||||
WithRegion(hcRegion).
|
WithRegion(hcRegion).
|
||||||
WithCredential(auth).
|
WithCredential(auth).
|
||||||
SafeBuild()
|
SafeBuild()
|
||||||
@ -343,7 +343,7 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbCli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := hcElb.NewElbClient(hcClient)
|
client := hcelb.NewElbClient(hcClient)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,12 +360,12 @@ func getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcRegion, err := hcIamRegion.SafeValueOf(region)
|
hcRegion, err := hciamregion.SafeValueOf(region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcClient, err := hcIam.IamClientBuilder().
|
hcClient, err := hciam.IamClientBuilder().
|
||||||
WithRegion(hcRegion).
|
WithRegion(hcRegion).
|
||||||
WithCredential(auth).
|
WithCredential(auth).
|
||||||
SafeBuild()
|
SafeBuild()
|
||||||
@ -373,9 +373,9 @@ func getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := hcIam.NewIamClient(hcClient)
|
client := hciam.NewIamClient(hcClient)
|
||||||
|
|
||||||
request := &hcIamModel.KeystoneListProjectsRequest{
|
request := &hciammodel.KeystoneListProjectsRequest{
|
||||||
Name: ®ion,
|
Name: ®ion,
|
||||||
}
|
}
|
||||||
response, err := client.KeystoneListProjects(request)
|
response, err := client.KeystoneListProjects(request)
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
|
|
||||||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
|
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
|
||||||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
|
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
|
||||||
hcIam "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3"
|
hciam "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3"
|
||||||
hcIamModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/model"
|
hciamModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/model"
|
||||||
hcIamRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
hciamregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
||||||
hcWaf "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1"
|
hcwaf "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1"
|
||||||
hcWafModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/model"
|
hcwafmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/model"
|
||||||
hcWafRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/region"
|
hcwafregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/region"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -43,7 +43,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *hcWaf.WafClient
|
sdkClient *hcwaf.WafClient
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ func (d *DeployerProvider) deployToCertificate(ctx context.Context, certPem stri
|
|||||||
|
|
||||||
// 查询证书
|
// 查询证书
|
||||||
// REF: https://support.huaweicloud.com/api-waf/ShowCertificate.html
|
// REF: https://support.huaweicloud.com/api-waf/ShowCertificate.html
|
||||||
showCertificateReq := &hcWafModel.ShowCertificateRequest{
|
showCertificateReq := &hcwafmodel.ShowCertificateRequest{
|
||||||
CertificateId: d.config.CertificateId,
|
CertificateId: d.config.CertificateId,
|
||||||
}
|
}
|
||||||
showCertificateResp, err := d.sdkClient.ShowCertificate(showCertificateReq)
|
showCertificateResp, err := d.sdkClient.ShowCertificate(showCertificateReq)
|
||||||
@ -137,9 +137,9 @@ func (d *DeployerProvider) deployToCertificate(ctx context.Context, certPem stri
|
|||||||
|
|
||||||
// 更新证书
|
// 更新证书
|
||||||
// REF: https://support.huaweicloud.com/api-waf/UpdateCertificate.html
|
// REF: https://support.huaweicloud.com/api-waf/UpdateCertificate.html
|
||||||
updateCertificateReq := &hcWafModel.UpdateCertificateRequest{
|
updateCertificateReq := &hcwafmodel.UpdateCertificateRequest{
|
||||||
CertificateId: d.config.CertificateId,
|
CertificateId: d.config.CertificateId,
|
||||||
Body: &hcWafModel.UpdateCertificateRequestBody{
|
Body: &hcwafmodel.UpdateCertificateRequestBody{
|
||||||
Name: *showCertificateResp.Name,
|
Name: *showCertificateResp.Name,
|
||||||
Content: hwsdk.StringPtr(certPem),
|
Content: hwsdk.StringPtr(certPem),
|
||||||
Key: hwsdk.StringPtr(privkeyPem),
|
Key: hwsdk.StringPtr(privkeyPem),
|
||||||
@ -173,7 +173,7 @@ func (d *DeployerProvider) deployToCloudServer(ctx context.Context, certPem stri
|
|||||||
listHostPage := int32(1)
|
listHostPage := int32(1)
|
||||||
listHostPageSize := int32(100)
|
listHostPageSize := int32(100)
|
||||||
for {
|
for {
|
||||||
listHostReq := &hcWafModel.ListHostRequest{
|
listHostReq := &hcwafmodel.ListHostRequest{
|
||||||
Hostname: hwsdk.StringPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
Hostname: hwsdk.StringPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
||||||
Page: hwsdk.Int32Ptr(listHostPage),
|
Page: hwsdk.Int32Ptr(listHostPage),
|
||||||
Pagesize: hwsdk.Int32Ptr(listHostPageSize),
|
Pagesize: hwsdk.Int32Ptr(listHostPageSize),
|
||||||
@ -205,9 +205,9 @@ func (d *DeployerProvider) deployToCloudServer(ctx context.Context, certPem stri
|
|||||||
|
|
||||||
// 更新云模式防护域名的配置
|
// 更新云模式防护域名的配置
|
||||||
// REF: https://support.huaweicloud.com/api-waf/UpdateHost.html
|
// REF: https://support.huaweicloud.com/api-waf/UpdateHost.html
|
||||||
updateHostReq := &hcWafModel.UpdateHostRequest{
|
updateHostReq := &hcwafmodel.UpdateHostRequest{
|
||||||
InstanceId: hostId,
|
InstanceId: hostId,
|
||||||
Body: &hcWafModel.UpdateHostRequestBody{
|
Body: &hcwafmodel.UpdateHostRequestBody{
|
||||||
Certificateid: hwsdk.StringPtr(upres.CertId),
|
Certificateid: hwsdk.StringPtr(upres.CertId),
|
||||||
Certificatename: hwsdk.StringPtr(upres.CertName),
|
Certificatename: hwsdk.StringPtr(upres.CertName),
|
||||||
},
|
},
|
||||||
@ -240,7 +240,7 @@ func (d *DeployerProvider) deployToPremiumHost(ctx context.Context, certPem stri
|
|||||||
listPremiumHostPage := int32(1)
|
listPremiumHostPage := int32(1)
|
||||||
listPremiumHostPageSize := int32(100)
|
listPremiumHostPageSize := int32(100)
|
||||||
for {
|
for {
|
||||||
listPremiumHostReq := &hcWafModel.ListPremiumHostRequest{
|
listPremiumHostReq := &hcwafmodel.ListPremiumHostRequest{
|
||||||
Hostname: hwsdk.StringPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
Hostname: hwsdk.StringPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
||||||
Page: hwsdk.StringPtr(fmt.Sprintf("%d", listPremiumHostPage)),
|
Page: hwsdk.StringPtr(fmt.Sprintf("%d", listPremiumHostPage)),
|
||||||
Pagesize: hwsdk.StringPtr(fmt.Sprintf("%d", listPremiumHostPageSize)),
|
Pagesize: hwsdk.StringPtr(fmt.Sprintf("%d", listPremiumHostPageSize)),
|
||||||
@ -272,9 +272,9 @@ func (d *DeployerProvider) deployToPremiumHost(ctx context.Context, certPem stri
|
|||||||
|
|
||||||
// 修改独享模式域名配置
|
// 修改独享模式域名配置
|
||||||
// REF: https://support.huaweicloud.com/api-waf/UpdatePremiumHost.html
|
// REF: https://support.huaweicloud.com/api-waf/UpdatePremiumHost.html
|
||||||
updatePremiumHostReq := &hcWafModel.UpdatePremiumHostRequest{
|
updatePremiumHostReq := &hcwafmodel.UpdatePremiumHostRequest{
|
||||||
HostId: hostId,
|
HostId: hostId,
|
||||||
Body: &hcWafModel.UpdatePremiumHostRequestBody{
|
Body: &hcwafmodel.UpdatePremiumHostRequestBody{
|
||||||
Certificateid: hwsdk.StringPtr(upres.CertId),
|
Certificateid: hwsdk.StringPtr(upres.CertId),
|
||||||
Certificatename: hwsdk.StringPtr(upres.CertName),
|
Certificatename: hwsdk.StringPtr(upres.CertName),
|
||||||
},
|
},
|
||||||
@ -288,7 +288,7 @@ func (d *DeployerProvider) deployToPremiumHost(ctx context.Context, certPem stri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcWaf.WafClient, error) {
|
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcwaf.WafClient, error) {
|
||||||
projectId, err := getSdkProjectId(accessKeyId, secretAccessKey, region)
|
projectId, err := getSdkProjectId(accessKeyId, secretAccessKey, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -303,12 +303,12 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcWaf.WafCli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcRegion, err := hcWafRegion.SafeValueOf(region)
|
hcRegion, err := hcwafregion.SafeValueOf(region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcClient, err := hcWaf.WafClientBuilder().
|
hcClient, err := hcwaf.WafClientBuilder().
|
||||||
WithRegion(hcRegion).
|
WithRegion(hcRegion).
|
||||||
WithCredential(auth).
|
WithCredential(auth).
|
||||||
SafeBuild()
|
SafeBuild()
|
||||||
@ -316,7 +316,7 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcWaf.WafCli
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := hcWaf.NewWafClient(hcClient)
|
client := hcwaf.NewWafClient(hcClient)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,12 +329,12 @@ func getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcRegion, err := hcIamRegion.SafeValueOf(region)
|
hcRegion, err := hciamregion.SafeValueOf(region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
hcClient, err := hcIam.IamClientBuilder().
|
hcClient, err := hciam.IamClientBuilder().
|
||||||
WithRegion(hcRegion).
|
WithRegion(hcRegion).
|
||||||
WithCredential(auth).
|
WithCredential(auth).
|
||||||
SafeBuild()
|
SafeBuild()
|
||||||
@ -342,9 +342,9 @@ func getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := hcIam.NewIamClient(hcClient)
|
client := hciam.NewIamClient(hcClient)
|
||||||
|
|
||||||
request := &hcIamModel.KeystoneListProjectsRequest{
|
request := &hciamModel.KeystoneListProjectsRequest{
|
||||||
Name: ®ion,
|
Name: ®ion,
|
||||||
}
|
}
|
||||||
response, err := client.KeystoneListProjects(request)
|
response, err := client.KeystoneListProjects(request)
|
||||||
|
@ -7,11 +7,11 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
jdCore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
jdcore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
||||||
jdCommon "github.com/jdcloud-api/jdcloud-sdk-go/services/common/models"
|
jdcommon "github.com/jdcloud-api/jdcloud-sdk-go/services/common/models"
|
||||||
jdLbApi "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/apis"
|
jdlbapi "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/apis"
|
||||||
jdLbClient "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/client"
|
jdlbclient "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/client"
|
||||||
jdLbModel "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/models"
|
jdlbmodel "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/models"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -43,7 +43,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *jdLbClient.LbClient
|
sdkClient *jdlbclient.LbClient
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
|
|
||||||
// 查询负载均衡器详情
|
// 查询负载均衡器详情
|
||||||
// REF: https://docs.jdcloud.com/cn/load-balancer/api/describeloadbalancer
|
// REF: https://docs.jdcloud.com/cn/load-balancer/api/describeloadbalancer
|
||||||
describeLoadBalancerReq := jdLbApi.NewDescribeLoadBalancerRequest(d.config.RegionId, d.config.LoadbalancerId)
|
describeLoadBalancerReq := jdlbapi.NewDescribeLoadBalancerRequest(d.config.RegionId, d.config.LoadbalancerId)
|
||||||
describeLoadBalancerResp, err := d.sdkClient.DescribeLoadBalancer(describeLoadBalancerReq)
|
describeLoadBalancerResp, err := d.sdkClient.DescribeLoadBalancer(describeLoadBalancerReq)
|
||||||
d.logger.Debug("sdk request 'lb.DescribeLoadBalancer'", slog.Any("request", describeLoadBalancerReq), slog.Any("response", describeLoadBalancerResp))
|
d.logger.Debug("sdk request 'lb.DescribeLoadBalancer'", slog.Any("request", describeLoadBalancerReq), slog.Any("response", describeLoadBalancerResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -133,8 +133,8 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
describeListenersPageNumber := 1
|
describeListenersPageNumber := 1
|
||||||
describeListenersPageSize := 100
|
describeListenersPageSize := 100
|
||||||
for {
|
for {
|
||||||
describeListenersReq := jdLbApi.NewDescribeListenersRequest(d.config.RegionId)
|
describeListenersReq := jdlbapi.NewDescribeListenersRequest(d.config.RegionId)
|
||||||
describeListenersReq.SetFilters([]jdCommon.Filter{{Name: "loadBalancerId", Values: []string{d.config.LoadbalancerId}}})
|
describeListenersReq.SetFilters([]jdcommon.Filter{{Name: "loadBalancerId", Values: []string{d.config.LoadbalancerId}}})
|
||||||
describeListenersReq.SetPageSize(describeListenersPageNumber)
|
describeListenersReq.SetPageSize(describeListenersPageNumber)
|
||||||
describeListenersReq.SetPageSize(describeListenersPageSize)
|
describeListenersReq.SetPageSize(describeListenersPageSize)
|
||||||
describeListenersResp, err := d.sdkClient.DescribeListeners(describeListenersReq)
|
describeListenersResp, err := d.sdkClient.DescribeListeners(describeListenersReq)
|
||||||
@ -194,7 +194,7 @@ func (d *DeployerProvider) deployToListener(ctx context.Context, cloudCertId str
|
|||||||
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudListenerId string, cloudCertId string) error {
|
||||||
// 查询监听器详情
|
// 查询监听器详情
|
||||||
// REF: https://docs.jdcloud.com/cn/load-balancer/api/describelistener
|
// REF: https://docs.jdcloud.com/cn/load-balancer/api/describelistener
|
||||||
describeListenerReq := jdLbApi.NewDescribeListenerRequest(d.config.RegionId, cloudListenerId)
|
describeListenerReq := jdlbapi.NewDescribeListenerRequest(d.config.RegionId, cloudListenerId)
|
||||||
describeListenerResp, err := d.sdkClient.DescribeListener(describeListenerReq)
|
describeListenerResp, err := d.sdkClient.DescribeListener(describeListenerReq)
|
||||||
d.logger.Debug("sdk request 'lb.DescribeListener'", slog.Any("request", describeListenerReq), slog.Any("response", describeListenerResp))
|
d.logger.Debug("sdk request 'lb.DescribeListener'", slog.Any("request", describeListenerReq), slog.Any("response", describeListenerResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -206,8 +206,8 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 修改监听器信息
|
// 修改监听器信息
|
||||||
// REF: https://docs.jdcloud.com/cn/load-balancer/api/updatelistener
|
// REF: https://docs.jdcloud.com/cn/load-balancer/api/updatelistener
|
||||||
updateListenerReq := jdLbApi.NewUpdateListenerRequest(d.config.RegionId, cloudListenerId)
|
updateListenerReq := jdlbapi.NewUpdateListenerRequest(d.config.RegionId, cloudListenerId)
|
||||||
updateListenerReq.SetCertificateSpecs([]jdLbModel.CertificateSpec{{CertificateId: cloudCertId}})
|
updateListenerReq.SetCertificateSpecs([]jdlbmodel.CertificateSpec{{CertificateId: cloudCertId}})
|
||||||
updateListenerResp, err := d.sdkClient.UpdateListener(updateListenerReq)
|
updateListenerResp, err := d.sdkClient.UpdateListener(updateListenerReq)
|
||||||
d.logger.Debug("sdk request 'lb.UpdateListener'", slog.Any("request", updateListenerReq), slog.Any("response", updateListenerResp))
|
d.logger.Debug("sdk request 'lb.UpdateListener'", slog.Any("request", updateListenerReq), slog.Any("response", updateListenerResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -216,7 +216,7 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
} else {
|
} else {
|
||||||
// 指定 SNI,需部署到扩展证书
|
// 指定 SNI,需部署到扩展证书
|
||||||
|
|
||||||
extCertSpecs := sliceutil.Filter(describeListenerResp.Result.Listener.ExtensionCertificateSpecs, func(extCertSpec jdLbModel.ExtensionCertificateSpec) bool {
|
extCertSpecs := sliceutil.Filter(describeListenerResp.Result.Listener.ExtensionCertificateSpecs, func(extCertSpec jdlbmodel.ExtensionCertificateSpec) bool {
|
||||||
return extCertSpec.Domain == d.config.Domain
|
return extCertSpec.Domain == d.config.Domain
|
||||||
})
|
})
|
||||||
if len(extCertSpecs) == 0 {
|
if len(extCertSpecs) == 0 {
|
||||||
@ -225,11 +225,11 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 批量修改扩展证书
|
// 批量修改扩展证书
|
||||||
// REF: https://docs.jdcloud.com/cn/load-balancer/api/updatelistenercertificates
|
// REF: https://docs.jdcloud.com/cn/load-balancer/api/updatelistenercertificates
|
||||||
updateListenerCertificatesReq := jdLbApi.NewUpdateListenerCertificatesRequest(
|
updateListenerCertificatesReq := jdlbapi.NewUpdateListenerCertificatesRequest(
|
||||||
d.config.RegionId,
|
d.config.RegionId,
|
||||||
cloudListenerId,
|
cloudListenerId,
|
||||||
sliceutil.Map(extCertSpecs, func(extCertSpec jdLbModel.ExtensionCertificateSpec) jdLbModel.ExtCertificateUpdateSpec {
|
sliceutil.Map(extCertSpecs, func(extCertSpec jdlbmodel.ExtensionCertificateSpec) jdlbmodel.ExtCertificateUpdateSpec {
|
||||||
return jdLbModel.ExtCertificateUpdateSpec{
|
return jdlbmodel.ExtCertificateUpdateSpec{
|
||||||
CertificateBindId: extCertSpec.CertificateBindId,
|
CertificateBindId: extCertSpec.CertificateBindId,
|
||||||
CertificateId: &cloudCertId,
|
CertificateId: &cloudCertId,
|
||||||
Domain: &extCertSpec.Domain,
|
Domain: &extCertSpec.Domain,
|
||||||
@ -246,9 +246,9 @@ func (d *DeployerProvider) updateListenerCertificate(ctx context.Context, cloudL
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret string) (*jdLbClient.LbClient, error) {
|
func createSdkClient(accessKeyId, accessKeySecret string) (*jdlbclient.LbClient, error) {
|
||||||
clientCredentials := jdCore.NewCredentials(accessKeyId, accessKeySecret)
|
clientCredentials := jdcore.NewCredentials(accessKeyId, accessKeySecret)
|
||||||
client := jdLbClient.NewLbClient(clientCredentials)
|
client := jdlbclient.NewLbClient(clientCredentials)
|
||||||
client.SetLogger(jdCore.NewDefaultLogger(jdCore.LogWarn))
|
client.SetLogger(jdcore.NewDefaultLogger(jdcore.LogWarn))
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
jdCore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
jdcore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
||||||
jdCdnApi "github.com/jdcloud-api/jdcloud-sdk-go/services/cdn/apis"
|
jdcdnapi "github.com/jdcloud-api/jdcloud-sdk-go/services/cdn/apis"
|
||||||
jdCdnClient "github.com/jdcloud-api/jdcloud-sdk-go/services/cdn/client"
|
jdcdnclient "github.com/jdcloud-api/jdcloud-sdk-go/services/cdn/client"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -26,7 +26,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *jdCdnClient.CdnClient
|
sdkClient *jdcdnclient.CdnClient
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ func (d *DeployerProvider) WithLogger(logger *slog.Logger) deployer.Deployer {
|
|||||||
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||||
// 查询域名配置信息
|
// 查询域名配置信息
|
||||||
// REF: https://docs.jdcloud.com/cn/cdn/api/querydomainconfig
|
// REF: https://docs.jdcloud.com/cn/cdn/api/querydomainconfig
|
||||||
queryDomainConfigReq := jdCdnApi.NewQueryDomainConfigRequest(d.config.Domain)
|
queryDomainConfigReq := jdcdnapi.NewQueryDomainConfigRequest(d.config.Domain)
|
||||||
queryDomainConfigResp, err := d.sdkClient.QueryDomainConfig(queryDomainConfigReq)
|
queryDomainConfigResp, err := d.sdkClient.QueryDomainConfig(queryDomainConfigReq)
|
||||||
d.logger.Debug("sdk request 'cdn.QueryDomainConfig'", slog.Any("request", queryDomainConfigReq), slog.Any("response", queryDomainConfigResp))
|
d.logger.Debug("sdk request 'cdn.QueryDomainConfig'", slog.Any("request", queryDomainConfigReq), slog.Any("response", queryDomainConfigResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -88,7 +88,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 设置通讯协议
|
// 设置通讯协议
|
||||||
// REF: https://docs.jdcloud.com/cn/cdn/api/sethttptype
|
// REF: https://docs.jdcloud.com/cn/cdn/api/sethttptype
|
||||||
setHttpTypeReq := jdCdnApi.NewSetHttpTypeRequest(d.config.Domain)
|
setHttpTypeReq := jdcdnapi.NewSetHttpTypeRequest(d.config.Domain)
|
||||||
setHttpTypeReq.SetHttpType("https")
|
setHttpTypeReq.SetHttpType("https")
|
||||||
setHttpTypeReq.SetCertificate(certPem)
|
setHttpTypeReq.SetCertificate(certPem)
|
||||||
setHttpTypeReq.SetRsaKey(privkeyPem)
|
setHttpTypeReq.SetRsaKey(privkeyPem)
|
||||||
@ -104,9 +104,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret string) (*jdCdnClient.CdnClient, error) {
|
func createSdkClient(accessKeyId, accessKeySecret string) (*jdcdnclient.CdnClient, error) {
|
||||||
clientCredentials := jdCore.NewCredentials(accessKeyId, accessKeySecret)
|
clientCredentials := jdcore.NewCredentials(accessKeyId, accessKeySecret)
|
||||||
client := jdCdnClient.NewCdnClient(clientCredentials)
|
client := jdcdnclient.NewCdnClient(clientCredentials)
|
||||||
client.SetLogger(jdCore.NewDefaultLogger(jdCore.LogWarn))
|
client.SetLogger(jdcore.NewDefaultLogger(jdcore.LogWarn))
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
jdCore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
jdcore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
||||||
jdLiveApi "github.com/jdcloud-api/jdcloud-sdk-go/services/live/apis"
|
jdliveapi "github.com/jdcloud-api/jdcloud-sdk-go/services/live/apis"
|
||||||
jdLiveClient "github.com/jdcloud-api/jdcloud-sdk-go/services/live/client"
|
jdliveclient "github.com/jdcloud-api/jdcloud-sdk-go/services/live/client"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -24,7 +24,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *jdLiveClient.LiveClient
|
sdkClient *jdliveclient.LiveClient
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
@ -58,7 +58,7 @@ func (d *DeployerProvider) WithLogger(logger *slog.Logger) deployer.Deployer {
|
|||||||
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||||
// 设置直播证书
|
// 设置直播证书
|
||||||
// REF: https://docs.jdcloud.com/cn/live-video/api/setlivedomaincertificate
|
// REF: https://docs.jdcloud.com/cn/live-video/api/setlivedomaincertificate
|
||||||
setLiveDomainCertificateReq := jdLiveApi.NewSetLiveDomainCertificateRequest(d.config.Domain, "on")
|
setLiveDomainCertificateReq := jdliveapi.NewSetLiveDomainCertificateRequest(d.config.Domain, "on")
|
||||||
setLiveDomainCertificateReq.SetCert(certPem)
|
setLiveDomainCertificateReq.SetCert(certPem)
|
||||||
setLiveDomainCertificateReq.SetKey(privkeyPem)
|
setLiveDomainCertificateReq.SetKey(privkeyPem)
|
||||||
setLiveDomainCertificateResp, err := d.sdkClient.SetLiveDomainCertificate(setLiveDomainCertificateReq)
|
setLiveDomainCertificateResp, err := d.sdkClient.SetLiveDomainCertificate(setLiveDomainCertificateReq)
|
||||||
@ -70,9 +70,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret string) (*jdLiveClient.LiveClient, error) {
|
func createSdkClient(accessKeyId, accessKeySecret string) (*jdliveclient.LiveClient, error) {
|
||||||
clientCredentials := jdCore.NewCredentials(accessKeyId, accessKeySecret)
|
clientCredentials := jdcore.NewCredentials(accessKeyId, accessKeySecret)
|
||||||
client := jdLiveClient.NewLiveClient(clientCredentials)
|
client := jdliveclient.NewLiveClient(clientCredentials)
|
||||||
client.SetLogger(jdCore.NewDefaultLogger(jdCore.LogWarn))
|
client.SetLogger(jdcore.NewDefaultLogger(jdcore.LogWarn))
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
jdCore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
jdcore "github.com/jdcloud-api/jdcloud-sdk-go/core"
|
||||||
jdVodApi "github.com/jdcloud-api/jdcloud-sdk-go/services/vod/apis"
|
jdvodapi "github.com/jdcloud-api/jdcloud-sdk-go/services/vod/apis"
|
||||||
jdVodClient "github.com/jdcloud-api/jdcloud-sdk-go/services/vod/client"
|
jdvodclient "github.com/jdcloud-api/jdcloud-sdk-go/services/vod/client"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -27,7 +27,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *jdVodClient.VodClient
|
sdkClient *jdvodclient.VodClient
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
@ -65,7 +65,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
listDomainsPageNumber := 1
|
listDomainsPageNumber := 1
|
||||||
listDomainsPageSize := 100
|
listDomainsPageSize := 100
|
||||||
for {
|
for {
|
||||||
listDomainsReq := jdVodApi.NewListDomainsRequest()
|
listDomainsReq := jdvodapi.NewListDomainsRequest()
|
||||||
listDomainsReq.SetPageNumber(1)
|
listDomainsReq.SetPageNumber(1)
|
||||||
listDomainsReq.SetPageSize(100)
|
listDomainsReq.SetPageSize(100)
|
||||||
listDomainsResp, err := d.sdkClient.ListDomains(listDomainsReq)
|
listDomainsResp, err := d.sdkClient.ListDomains(listDomainsReq)
|
||||||
@ -93,7 +93,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 查询域名 SSL 配置
|
// 查询域名 SSL 配置
|
||||||
// REF: https://docs.jdcloud.com/cn/video-on-demand/api/gethttpssl
|
// REF: https://docs.jdcloud.com/cn/video-on-demand/api/gethttpssl
|
||||||
getHttpSslReq := jdVodApi.NewGetHttpSslRequest(domainId)
|
getHttpSslReq := jdvodapi.NewGetHttpSslRequest(domainId)
|
||||||
getHttpSslResp, err := d.sdkClient.GetHttpSsl(getHttpSslReq)
|
getHttpSslResp, err := d.sdkClient.GetHttpSsl(getHttpSslReq)
|
||||||
d.logger.Debug("sdk request 'vod.GetHttpSsl'", slog.Any("request", getHttpSslReq), slog.Any("response", getHttpSslResp))
|
d.logger.Debug("sdk request 'vod.GetHttpSsl'", slog.Any("request", getHttpSslReq), slog.Any("response", getHttpSslResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -102,7 +102,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 设置域名 SSL 配置
|
// 设置域名 SSL 配置
|
||||||
// REF: https://docs.jdcloud.com/cn/video-on-demand/api/sethttpssl
|
// REF: https://docs.jdcloud.com/cn/video-on-demand/api/sethttpssl
|
||||||
setHttpSslReq := jdVodApi.NewSetHttpSslRequest(domainId)
|
setHttpSslReq := jdvodapi.NewSetHttpSslRequest(domainId)
|
||||||
setHttpSslReq.SetTitle(fmt.Sprintf("certimate-%d", time.Now().UnixMilli()))
|
setHttpSslReq.SetTitle(fmt.Sprintf("certimate-%d", time.Now().UnixMilli()))
|
||||||
setHttpSslReq.SetSslCert(certPem)
|
setHttpSslReq.SetSslCert(certPem)
|
||||||
setHttpSslReq.SetSslKey(privkeyPem)
|
setHttpSslReq.SetSslKey(privkeyPem)
|
||||||
@ -118,9 +118,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret string) (*jdVodClient.VodClient, error) {
|
func createSdkClient(accessKeyId, accessKeySecret string) (*jdvodclient.VodClient, error) {
|
||||||
clientCredentials := jdCore.NewCredentials(accessKeyId, accessKeySecret)
|
clientCredentials := jdcore.NewCredentials(accessKeyId, accessKeySecret)
|
||||||
client := jdVodClient.NewVodClient(clientCredentials)
|
client := jdvodclient.NewVodClient(clientCredentials)
|
||||||
client.SetLogger(jdCore.NewDefaultLogger(jdCore.LogWarn))
|
client.SetLogger(jdcore.NewDefaultLogger(jdcore.LogWarn))
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
k8sCore "k8s.io/api/core/v1"
|
k8score "k8s.io/api/core/v1"
|
||||||
k8sMeta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
k8smeta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
@ -87,7 +87,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return nil, xerrors.Wrap(err, "failed to create k8s client")
|
return nil, xerrors.Wrap(err, "failed to create k8s client")
|
||||||
}
|
}
|
||||||
|
|
||||||
var secretPayload *k8sCore.Secret
|
var secretPayload *k8score.Secret
|
||||||
secretAnnotations := map[string]string{
|
secretAnnotations := map[string]string{
|
||||||
"certimate/common-name": certX509.Subject.CommonName,
|
"certimate/common-name": certX509.Subject.CommonName,
|
||||||
"certimate/subject-sn": certX509.Subject.SerialNumber,
|
"certimate/subject-sn": certX509.Subject.SerialNumber,
|
||||||
@ -97,24 +97,24 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取 Secret 实例,如果不存在则创建
|
// 获取 Secret 实例,如果不存在则创建
|
||||||
secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Get(context.TODO(), d.config.SecretName, k8sMeta.GetOptions{})
|
secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Get(context.TODO(), d.config.SecretName, k8smeta.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
secretPayload = &k8sCore.Secret{
|
secretPayload = &k8score.Secret{
|
||||||
TypeMeta: k8sMeta.TypeMeta{
|
TypeMeta: k8smeta.TypeMeta{
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: k8sMeta.ObjectMeta{
|
ObjectMeta: k8smeta.ObjectMeta{
|
||||||
Name: d.config.SecretName,
|
Name: d.config.SecretName,
|
||||||
Annotations: secretAnnotations,
|
Annotations: secretAnnotations,
|
||||||
},
|
},
|
||||||
Type: k8sCore.SecretType(d.config.SecretType),
|
Type: k8score.SecretType(d.config.SecretType),
|
||||||
}
|
}
|
||||||
secretPayload.Data = make(map[string][]byte)
|
secretPayload.Data = make(map[string][]byte)
|
||||||
secretPayload.Data[d.config.SecretDataKeyForCrt] = []byte(certPem)
|
secretPayload.Data[d.config.SecretDataKeyForCrt] = []byte(certPem)
|
||||||
secretPayload.Data[d.config.SecretDataKeyForKey] = []byte(privkeyPem)
|
secretPayload.Data[d.config.SecretDataKeyForKey] = []byte(privkeyPem)
|
||||||
|
|
||||||
secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Create(context.TODO(), secretPayload, k8sMeta.CreateOptions{})
|
secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Create(context.TODO(), secretPayload, k8smeta.CreateOptions{})
|
||||||
d.logger.Debug("k8s operate 'Secrets.Create'", slog.String("namespace", d.config.Namespace), slog.Any("secret", secretPayload))
|
d.logger.Debug("k8s operate 'Secrets.Create'", slog.String("namespace", d.config.Namespace), slog.Any("secret", secretPayload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Wrap(err, "failed to create k8s secret")
|
return nil, xerrors.Wrap(err, "failed to create k8s secret")
|
||||||
@ -124,7 +124,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新 Secret 实例
|
// 更新 Secret 实例
|
||||||
secretPayload.Type = k8sCore.SecretType(d.config.SecretType)
|
secretPayload.Type = k8score.SecretType(d.config.SecretType)
|
||||||
if secretPayload.ObjectMeta.Annotations == nil {
|
if secretPayload.ObjectMeta.Annotations == nil {
|
||||||
secretPayload.ObjectMeta.Annotations = secretAnnotations
|
secretPayload.ObjectMeta.Annotations = secretAnnotations
|
||||||
} else {
|
} else {
|
||||||
@ -137,7 +137,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
}
|
}
|
||||||
secretPayload.Data[d.config.SecretDataKeyForCrt] = []byte(certPem)
|
secretPayload.Data[d.config.SecretDataKeyForCrt] = []byte(certPem)
|
||||||
secretPayload.Data[d.config.SecretDataKeyForKey] = []byte(privkeyPem)
|
secretPayload.Data[d.config.SecretDataKeyForKey] = []byte(privkeyPem)
|
||||||
secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Update(context.TODO(), secretPayload, k8sMeta.UpdateOptions{})
|
secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Update(context.TODO(), secretPayload, k8smeta.UpdateOptions{})
|
||||||
d.logger.Debug("k8s operate 'Secrets.Update'", slog.String("namespace", d.config.Namespace), slog.Any("secret", secretPayload))
|
d.logger.Debug("k8s operate 'Secrets.Update'", slog.String("namespace", d.config.Namespace), slog.Any("secret", secretPayload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Wrap(err, "failed to update k8s secret")
|
return nil, xerrors.Wrap(err, "failed to update k8s secret")
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
tcCdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
|
tccdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
tcssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -36,8 +36,8 @@ type DeployerProvider struct {
|
|||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
|
|
||||||
type wSdkClients struct {
|
type wSdkClients struct {
|
||||||
ssl *tcSsl.Client
|
ssl *tcssl.Client
|
||||||
cdn *tcCdn.Client
|
cdn *tccdn.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||||
@ -122,7 +122,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 证书部署到 CDN 实例
|
// 证书部署到 CDN 实例
|
||||||
// REF: https://cloud.tencent.com/document/product/400/91667
|
// REF: https://cloud.tencent.com/document/product/400/91667
|
||||||
deployCertificateInstanceReq := tcSsl.NewDeployCertificateInstanceRequest()
|
deployCertificateInstanceReq := tcssl.NewDeployCertificateInstanceRequest()
|
||||||
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
||||||
deployCertificateInstanceReq.ResourceType = common.StringPtr("cdn")
|
deployCertificateInstanceReq.ResourceType = common.StringPtr("cdn")
|
||||||
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
||||||
@ -140,7 +140,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
func (d *DeployerProvider) getDomainsByCertificateId(cloudCertId string) ([]string, error) {
|
func (d *DeployerProvider) getDomainsByCertificateId(cloudCertId string) ([]string, error) {
|
||||||
// 获取证书中的可用域名
|
// 获取证书中的可用域名
|
||||||
// REF: https://cloud.tencent.com/document/product/228/42491
|
// REF: https://cloud.tencent.com/document/product/228/42491
|
||||||
describeCertDomainsReq := tcCdn.NewDescribeCertDomainsRequest()
|
describeCertDomainsReq := tccdn.NewDescribeCertDomainsRequest()
|
||||||
describeCertDomainsReq.CertId = common.StringPtr(cloudCertId)
|
describeCertDomainsReq.CertId = common.StringPtr(cloudCertId)
|
||||||
describeCertDomainsReq.Product = common.StringPtr("cdn")
|
describeCertDomainsReq.Product = common.StringPtr("cdn")
|
||||||
describeCertDomainsResp, err := d.sdkClients.cdn.DescribeCertDomains(describeCertDomainsReq)
|
describeCertDomainsResp, err := d.sdkClients.cdn.DescribeCertDomains(describeCertDomainsReq)
|
||||||
@ -162,7 +162,7 @@ func (d *DeployerProvider) getDomainsByCertificateId(cloudCertId string) ([]stri
|
|||||||
func (d *DeployerProvider) getDeployedDomainsByCertificateId(cloudCertId string) ([]string, error) {
|
func (d *DeployerProvider) getDeployedDomainsByCertificateId(cloudCertId string) ([]string, error) {
|
||||||
// 根据证书查询关联 CDN 域名
|
// 根据证书查询关联 CDN 域名
|
||||||
// REF: https://cloud.tencent.com/document/product/400/62674
|
// REF: https://cloud.tencent.com/document/product/400/62674
|
||||||
describeDeployedResourcesReq := tcSsl.NewDescribeDeployedResourcesRequest()
|
describeDeployedResourcesReq := tcssl.NewDescribeDeployedResourcesRequest()
|
||||||
describeDeployedResourcesReq.CertificateIds = common.StringPtrs([]string{cloudCertId})
|
describeDeployedResourcesReq.CertificateIds = common.StringPtrs([]string{cloudCertId})
|
||||||
describeDeployedResourcesReq.ResourceType = common.StringPtr("cdn")
|
describeDeployedResourcesReq.ResourceType = common.StringPtr("cdn")
|
||||||
describeDeployedResourcesResp, err := d.sdkClients.ssl.DescribeDeployedResources(describeDeployedResourcesReq)
|
describeDeployedResourcesResp, err := d.sdkClients.ssl.DescribeDeployedResources(describeDeployedResourcesReq)
|
||||||
@ -186,12 +186,12 @@ func (d *DeployerProvider) getDeployedDomainsByCertificateId(cloudCertId string)
|
|||||||
func createSdkClients(secretId, secretKey string) (*wSdkClients, 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())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cdnClient, err := tcCdn.NewClient(credential, "", profile.NewClientProfile())
|
cdnClient, err := tccdn.NewClient(credential, "", profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
tcClb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
|
tcclb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
tcssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -47,8 +47,8 @@ type DeployerProvider struct {
|
|||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
|
|
||||||
type wSdkClients struct {
|
type wSdkClients struct {
|
||||||
ssl *tcSsl.Client
|
ssl *tcssl.Client
|
||||||
clb *tcClb.Client
|
clb *tcclb.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||||
@ -135,7 +135,7 @@ func (d *DeployerProvider) deployViaSslService(ctx context.Context, cloudCertId
|
|||||||
|
|
||||||
// 证书部署到 CLB 实例
|
// 证书部署到 CLB 实例
|
||||||
// REF: https://cloud.tencent.com/document/product/400/91667
|
// REF: https://cloud.tencent.com/document/product/400/91667
|
||||||
deployCertificateInstanceReq := tcSsl.NewDeployCertificateInstanceRequest()
|
deployCertificateInstanceReq := tcssl.NewDeployCertificateInstanceRequest()
|
||||||
deployCertificateInstanceReq.CertificateId = common.StringPtr(cloudCertId)
|
deployCertificateInstanceReq.CertificateId = common.StringPtr(cloudCertId)
|
||||||
deployCertificateInstanceReq.ResourceType = common.StringPtr("clb")
|
deployCertificateInstanceReq.ResourceType = common.StringPtr("clb")
|
||||||
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
||||||
@ -163,7 +163,7 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
|||||||
// 查询监听器列表
|
// 查询监听器列表
|
||||||
// REF: https://cloud.tencent.com/document/api/214/30686
|
// REF: https://cloud.tencent.com/document/api/214/30686
|
||||||
listenerIds := make([]string, 0)
|
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)
|
||||||
d.logger.Debug("sdk request 'clb.DescribeListeners'", slog.Any("request", describeListenersReq), slog.Any("response", describeListenersResp))
|
d.logger.Debug("sdk request 'clb.DescribeListeners'", slog.Any("request", describeListenersReq), slog.Any("response", describeListenersResp))
|
||||||
@ -231,11 +231,11 @@ func (d *DeployerProvider) deployToRuleDomain(ctx context.Context, cloudCertId s
|
|||||||
|
|
||||||
// 修改负载均衡七层监听器转发规则的域名级别属性
|
// 修改负载均衡七层监听器转发规则的域名级别属性
|
||||||
// REF: https://cloud.tencent.com/document/api/214/38092
|
// REF: https://cloud.tencent.com/document/api/214/38092
|
||||||
modifyDomainAttributesReq := tcClb.NewModifyDomainAttributesRequest()
|
modifyDomainAttributesReq := tcclb.NewModifyDomainAttributesRequest()
|
||||||
modifyDomainAttributesReq.LoadBalancerId = common.StringPtr(d.config.LoadbalancerId)
|
modifyDomainAttributesReq.LoadBalancerId = common.StringPtr(d.config.LoadbalancerId)
|
||||||
modifyDomainAttributesReq.ListenerId = common.StringPtr(d.config.ListenerId)
|
modifyDomainAttributesReq.ListenerId = common.StringPtr(d.config.ListenerId)
|
||||||
modifyDomainAttributesReq.Domain = common.StringPtr(d.config.Domain)
|
modifyDomainAttributesReq.Domain = common.StringPtr(d.config.Domain)
|
||||||
modifyDomainAttributesReq.Certificate = &tcClb.CertificateInput{
|
modifyDomainAttributesReq.Certificate = &tcclb.CertificateInput{
|
||||||
SSLMode: common.StringPtr("UNIDIRECTIONAL"),
|
SSLMode: common.StringPtr("UNIDIRECTIONAL"),
|
||||||
CertId: common.StringPtr(cloudCertId),
|
CertId: common.StringPtr(cloudCertId),
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ func (d *DeployerProvider) deployToRuleDomain(ctx context.Context, cloudCertId s
|
|||||||
func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudLoadbalancerId, cloudListenerId, cloudCertId string) error {
|
func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudLoadbalancerId, cloudListenerId, cloudCertId string) error {
|
||||||
// 查询监听器列表
|
// 查询监听器列表
|
||||||
// REF: https://cloud.tencent.com/document/api/214/30686
|
// REF: https://cloud.tencent.com/document/api/214/30686
|
||||||
describeListenersReq := tcClb.NewDescribeListenersRequest()
|
describeListenersReq := tcclb.NewDescribeListenersRequest()
|
||||||
describeListenersReq.LoadBalancerId = common.StringPtr(cloudLoadbalancerId)
|
describeListenersReq.LoadBalancerId = common.StringPtr(cloudLoadbalancerId)
|
||||||
describeListenersReq.ListenerIds = common.StringPtrs([]string{cloudListenerId})
|
describeListenersReq.ListenerIds = common.StringPtrs([]string{cloudListenerId})
|
||||||
describeListenersResp, err := d.sdkClients.clb.DescribeListeners(describeListenersReq)
|
describeListenersResp, err := d.sdkClients.clb.DescribeListeners(describeListenersReq)
|
||||||
@ -264,10 +264,10 @@ func (d *DeployerProvider) modifyListenerCertificate(ctx context.Context, cloudL
|
|||||||
|
|
||||||
// 修改监听器属性
|
// 修改监听器属性
|
||||||
// REF: https://cloud.tencent.com/document/product/214/30681
|
// REF: https://cloud.tencent.com/document/product/214/30681
|
||||||
modifyListenerReq := tcClb.NewModifyListenerRequest()
|
modifyListenerReq := tcclb.NewModifyListenerRequest()
|
||||||
modifyListenerReq.LoadBalancerId = common.StringPtr(cloudLoadbalancerId)
|
modifyListenerReq.LoadBalancerId = common.StringPtr(cloudLoadbalancerId)
|
||||||
modifyListenerReq.ListenerId = common.StringPtr(cloudListenerId)
|
modifyListenerReq.ListenerId = common.StringPtr(cloudListenerId)
|
||||||
modifyListenerReq.Certificate = &tcClb.CertificateInput{CertId: common.StringPtr(cloudCertId)}
|
modifyListenerReq.Certificate = &tcclb.CertificateInput{CertId: common.StringPtr(cloudCertId)}
|
||||||
if describeListenersResp.Response.Listeners[0].Certificate != nil && describeListenersResp.Response.Listeners[0].Certificate.SSLMode != nil {
|
if describeListenersResp.Response.Listeners[0].Certificate != nil && describeListenersResp.Response.Listeners[0].Certificate.SSLMode != nil {
|
||||||
modifyListenerReq.Certificate.SSLMode = describeListenersResp.Response.Listeners[0].Certificate.SSLMode
|
modifyListenerReq.Certificate.SSLMode = describeListenersResp.Response.Listeners[0].Certificate.SSLMode
|
||||||
modifyListenerReq.Certificate.CertCaId = describeListenersResp.Response.Listeners[0].Certificate.CertCaId
|
modifyListenerReq.Certificate.CertCaId = describeListenersResp.Response.Listeners[0].Certificate.CertCaId
|
||||||
@ -287,12 +287,12 @@ func createSdkClients(secretId, secretKey, region string) (*wSdkClients, error)
|
|||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
|
|
||||||
// 注意虽然官方文档中地域无需指定,但实际需要部署到 CLB 时必传
|
// 注意虽然官方文档中地域无需指定,但实际需要部署到 CLB 时必传
|
||||||
sslClient, err := tcSsl.NewClient(credential, region, profile.NewClientProfile())
|
sslClient, err := tcssl.NewClient(credential, region, profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
clbClient, err := tcClb.NewClient(credential, region, profile.NewClientProfile())
|
clbClient, err := tcclb.NewClient(credential, region, profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
tcssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -32,7 +32,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *tcSsl.Client
|
sdkClient *tcssl.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 证书部署到 COS 实例
|
// 证书部署到 COS 实例
|
||||||
// REF: https://cloud.tencent.com/document/product/400/91667
|
// REF: https://cloud.tencent.com/document/product/400/91667
|
||||||
deployCertificateInstanceReq := tcSsl.NewDeployCertificateInstanceRequest()
|
deployCertificateInstanceReq := tcssl.NewDeployCertificateInstanceRequest()
|
||||||
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
||||||
deployCertificateInstanceReq.ResourceType = common.StringPtr("cos")
|
deployCertificateInstanceReq.ResourceType = common.StringPtr("cos")
|
||||||
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
||||||
@ -106,9 +106,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(secretId, secretKey, region string) (*tcSsl.Client, error) {
|
func createSdkClient(secretId, secretKey, region string) (*tcssl.Client, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
client, err := tcSsl.NewClient(credential, region, profile.NewClientProfile())
|
client, err := tcssl.NewClient(credential, region, profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcLive "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live/v20180801"
|
tclive "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live/v20180801"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -26,7 +26,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *tcLive.Client
|
sdkClient *tclive.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,8 +79,8 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 绑定证书对应的播放域名
|
// 绑定证书对应的播放域名
|
||||||
// REF: https://cloud.tencent.com/document/product/267/78655
|
// REF: https://cloud.tencent.com/document/product/267/78655
|
||||||
modifyLiveDomainCertBindingsReq := &tcLive.ModifyLiveDomainCertBindingsRequest{
|
modifyLiveDomainCertBindingsReq := &tclive.ModifyLiveDomainCertBindingsRequest{
|
||||||
DomainInfos: []*tcLive.LiveCertDomainInfo{
|
DomainInfos: []*tclive.LiveCertDomainInfo{
|
||||||
{
|
{
|
||||||
DomainName: common.StringPtr(d.config.Domain),
|
DomainName: common.StringPtr(d.config.Domain),
|
||||||
Status: common.Int64Ptr(1),
|
Status: common.Int64Ptr(1),
|
||||||
@ -97,10 +97,10 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(secretId, secretKey string) (*tcLive.Client, error) {
|
func createSdkClient(secretId, secretKey string) (*tclive.Client, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
|
|
||||||
client, err := tcLive.NewClient(credential, "", profile.NewClientProfile())
|
client, err := tclive.NewClient(credential, "", profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
tcCdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
|
tccdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
tcssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -35,8 +35,8 @@ type DeployerProvider struct {
|
|||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
|
|
||||||
type wSdkClients struct {
|
type wSdkClients struct {
|
||||||
ssl *tcSsl.Client
|
ssl *tcssl.Client
|
||||||
cdn *tcCdn.Client
|
cdn *tccdn.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||||
@ -105,7 +105,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 证书部署到 ECDN 实例
|
// 证书部署到 ECDN 实例
|
||||||
// REF: https://cloud.tencent.com/document/product/400/91667
|
// REF: https://cloud.tencent.com/document/product/400/91667
|
||||||
deployCertificateInstanceReq := tcSsl.NewDeployCertificateInstanceRequest()
|
deployCertificateInstanceReq := tcssl.NewDeployCertificateInstanceRequest()
|
||||||
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
||||||
deployCertificateInstanceReq.ResourceType = common.StringPtr("ecdn")
|
deployCertificateInstanceReq.ResourceType = common.StringPtr("ecdn")
|
||||||
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
deployCertificateInstanceReq.Status = common.Int64Ptr(1)
|
||||||
@ -123,7 +123,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
func (d *DeployerProvider) getDomainsByCertificateId(cloudCertId string) ([]string, error) {
|
func (d *DeployerProvider) getDomainsByCertificateId(cloudCertId string) ([]string, error) {
|
||||||
// 获取证书中的可用域名
|
// 获取证书中的可用域名
|
||||||
// REF: https://cloud.tencent.com/document/product/228/42491
|
// REF: https://cloud.tencent.com/document/product/228/42491
|
||||||
describeCertDomainsReq := tcCdn.NewDescribeCertDomainsRequest()
|
describeCertDomainsReq := tccdn.NewDescribeCertDomainsRequest()
|
||||||
describeCertDomainsReq.CertId = common.StringPtr(cloudCertId)
|
describeCertDomainsReq.CertId = common.StringPtr(cloudCertId)
|
||||||
describeCertDomainsReq.Product = common.StringPtr("ecdn")
|
describeCertDomainsReq.Product = common.StringPtr("ecdn")
|
||||||
describeCertDomainsResp, err := d.sdkClients.cdn.DescribeCertDomains(describeCertDomainsReq)
|
describeCertDomainsResp, err := d.sdkClients.cdn.DescribeCertDomains(describeCertDomainsReq)
|
||||||
@ -145,12 +145,12 @@ func (d *DeployerProvider) getDomainsByCertificateId(cloudCertId string) ([]stri
|
|||||||
func createSdkClients(secretId, secretKey string) (*wSdkClients, 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())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cdnClient, err := tcCdn.NewClient(credential, "", profile.NewClientProfile())
|
cdnClient, err := tccdn.NewClient(credential, "", profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
tcssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
||||||
tcTeo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901"
|
tcteo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -37,8 +37,8 @@ type DeployerProvider struct {
|
|||||||
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
var _ deployer.Deployer = (*DeployerProvider)(nil)
|
||||||
|
|
||||||
type wSdkClients struct {
|
type wSdkClients struct {
|
||||||
ssl *tcSsl.Client
|
ssl *tcssl.Client
|
||||||
teo *tcTeo.Client
|
teo *tcteo.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||||
@ -92,11 +92,11 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 配置域名证书
|
// 配置域名证书
|
||||||
// REF: https://cloud.tencent.com/document/product/1552/80764
|
// REF: https://cloud.tencent.com/document/product/1552/80764
|
||||||
modifyHostsCertificateReq := tcTeo.NewModifyHostsCertificateRequest()
|
modifyHostsCertificateReq := tcteo.NewModifyHostsCertificateRequest()
|
||||||
modifyHostsCertificateReq.ZoneId = common.StringPtr(d.config.ZoneId)
|
modifyHostsCertificateReq.ZoneId = common.StringPtr(d.config.ZoneId)
|
||||||
modifyHostsCertificateReq.Mode = common.StringPtr("sslcert")
|
modifyHostsCertificateReq.Mode = common.StringPtr("sslcert")
|
||||||
modifyHostsCertificateReq.Hosts = common.StringPtrs([]string{d.config.Domain})
|
modifyHostsCertificateReq.Hosts = common.StringPtrs([]string{d.config.Domain})
|
||||||
modifyHostsCertificateReq.ServerCertInfo = []*tcTeo.ServerCertInfo{{CertId: common.StringPtr(upres.CertId)}}
|
modifyHostsCertificateReq.ServerCertInfo = []*tcteo.ServerCertInfo{{CertId: common.StringPtr(upres.CertId)}}
|
||||||
modifyHostsCertificateResp, err := d.sdkClients.teo.ModifyHostsCertificate(modifyHostsCertificateReq)
|
modifyHostsCertificateResp, err := d.sdkClients.teo.ModifyHostsCertificate(modifyHostsCertificateReq)
|
||||||
d.logger.Debug("sdk request 'teo.ModifyHostsCertificate'", slog.Any("request", modifyHostsCertificateReq), slog.Any("response", modifyHostsCertificateResp))
|
d.logger.Debug("sdk request 'teo.ModifyHostsCertificate'", slog.Any("request", modifyHostsCertificateReq), slog.Any("response", modifyHostsCertificateResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -109,12 +109,12 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
func createSdkClients(secretId, secretKey string) (*wSdkClients, 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())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
teoClient, err := tcTeo.NewClient(credential, "", profile.NewClientProfile())
|
teoClient, err := tcteo.NewClient(credential, "", profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcScf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
|
tcscf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -28,7 +28,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *tcScf.Client
|
sdkClient *tcscf.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ func (d *DeployerProvider) WithLogger(logger *slog.Logger) deployer.Deployer {
|
|||||||
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||||
// 查看云函数自定义域名详情
|
// 查看云函数自定义域名详情
|
||||||
// REF: https://cloud.tencent.com/document/product/583/111924
|
// REF: https://cloud.tencent.com/document/product/583/111924
|
||||||
getCustomDomainReq := tcScf.NewGetCustomDomainRequest()
|
getCustomDomainReq := tcscf.NewGetCustomDomainRequest()
|
||||||
getCustomDomainReq.Domain = common.StringPtr(d.config.Domain)
|
getCustomDomainReq.Domain = common.StringPtr(d.config.Domain)
|
||||||
getCustomDomainResp, err := d.sdkClient.GetCustomDomain(getCustomDomainReq)
|
getCustomDomainResp, err := d.sdkClient.GetCustomDomain(getCustomDomainReq)
|
||||||
d.logger.Debug("sdk request 'scf.GetCustomDomain'", slog.Any("request", getCustomDomainReq), slog.Any("response", getCustomDomainResp))
|
d.logger.Debug("sdk request 'scf.GetCustomDomain'", slog.Any("request", getCustomDomainReq), slog.Any("response", getCustomDomainResp))
|
||||||
@ -91,9 +91,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 更新云函数自定义域名
|
// 更新云函数自定义域名
|
||||||
// REF: https://cloud.tencent.com/document/product/583/111922
|
// REF: https://cloud.tencent.com/document/product/583/111922
|
||||||
updateCustomDomainReq := tcScf.NewUpdateCustomDomainRequest()
|
updateCustomDomainReq := tcscf.NewUpdateCustomDomainRequest()
|
||||||
updateCustomDomainReq.Domain = common.StringPtr(d.config.Domain)
|
updateCustomDomainReq.Domain = common.StringPtr(d.config.Domain)
|
||||||
updateCustomDomainReq.CertConfig = &tcScf.CertConf{
|
updateCustomDomainReq.CertConfig = &tcscf.CertConf{
|
||||||
CertificateId: common.StringPtr(upres.CertId),
|
CertificateId: common.StringPtr(upres.CertId),
|
||||||
}
|
}
|
||||||
updateCustomDomainReq.Protocol = getCustomDomainResp.Response.Protocol
|
updateCustomDomainReq.Protocol = getCustomDomainResp.Response.Protocol
|
||||||
@ -106,9 +106,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(secretId, secretKey, region string) (*tcScf.Client, error) {
|
func createSdkClient(secretId, secretKey, region string) (*tcscf.Client, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
client, err := tcScf.NewClient(credential, region, profile.NewClientProfile())
|
client, err := tcscf.NewClient(credential, region, profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
tcssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -33,7 +33,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *tcSsl.Client
|
sdkClient *tcssl.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 证书部署到云资源实例列表
|
// 证书部署到云资源实例列表
|
||||||
// REF: https://cloud.tencent.com/document/product/400/91667
|
// REF: https://cloud.tencent.com/document/product/400/91667
|
||||||
deployCertificateInstanceReq := tcSsl.NewDeployCertificateInstanceRequest()
|
deployCertificateInstanceReq := tcssl.NewDeployCertificateInstanceRequest()
|
||||||
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
deployCertificateInstanceReq.CertificateId = common.StringPtr(upres.CertId)
|
||||||
deployCertificateInstanceReq.ResourceType = common.StringPtr(d.config.ResourceType)
|
deployCertificateInstanceReq.ResourceType = common.StringPtr(d.config.ResourceType)
|
||||||
deployCertificateInstanceReq.InstanceIdList = common.StringPtrs(d.config.ResourceIds)
|
deployCertificateInstanceReq.InstanceIdList = common.StringPtrs(d.config.ResourceIds)
|
||||||
@ -113,7 +113,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
describeHostDeployRecordDetailReq := tcSsl.NewDescribeHostDeployRecordDetailRequest()
|
describeHostDeployRecordDetailReq := tcssl.NewDescribeHostDeployRecordDetailRequest()
|
||||||
describeHostDeployRecordDetailReq.DeployRecordId = common.StringPtr(fmt.Sprintf("%d", *deployCertificateInstanceResp.Response.DeployRecordId))
|
describeHostDeployRecordDetailReq.DeployRecordId = common.StringPtr(fmt.Sprintf("%d", *deployCertificateInstanceResp.Response.DeployRecordId))
|
||||||
describeHostDeployRecordDetailReq.Limit = common.Uint64Ptr(100)
|
describeHostDeployRecordDetailReq.Limit = common.Uint64Ptr(100)
|
||||||
describeHostDeployRecordDetailResp, err := d.sdkClient.DescribeHostDeployRecordDetail(describeHostDeployRecordDetailReq)
|
describeHostDeployRecordDetailResp, err := d.sdkClient.DescribeHostDeployRecordDetail(describeHostDeployRecordDetailReq)
|
||||||
@ -145,10 +145,10 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(secretId, secretKey, region string) (*tcSsl.Client, error) {
|
func createSdkClient(secretId, secretKey, region string) (*tcssl.Client, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
|
|
||||||
client, err := tcSsl.NewClient(credential, region, profile.NewClientProfile())
|
client, err := tcssl.NewClient(credential, region, profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcVod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717"
|
tcvod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -28,7 +28,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *tcVod.Client
|
sdkClient *tcvod.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 设置点播域名 HTTPS 证书
|
// 设置点播域名 HTTPS 证书
|
||||||
// REF: https://cloud.tencent.com/document/api/266/102015
|
// REF: https://cloud.tencent.com/document/api/266/102015
|
||||||
setVodDomainCertificateReq := tcVod.NewSetVodDomainCertificateRequest()
|
setVodDomainCertificateReq := tcvod.NewSetVodDomainCertificateRequest()
|
||||||
setVodDomainCertificateReq.Domain = common.StringPtr(d.config.Domain)
|
setVodDomainCertificateReq.Domain = common.StringPtr(d.config.Domain)
|
||||||
setVodDomainCertificateReq.Operation = common.StringPtr("Set")
|
setVodDomainCertificateReq.Operation = common.StringPtr("Set")
|
||||||
setVodDomainCertificateReq.CertID = common.StringPtr(upres.CertId)
|
setVodDomainCertificateReq.CertID = common.StringPtr(upres.CertId)
|
||||||
@ -97,9 +97,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(secretId, secretKey string) (*tcVod.Client, error) {
|
func createSdkClient(secretId, secretKey string) (*tcvod.Client, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
client, err := tcVod.NewClient(credential, "", profile.NewClientProfile())
|
client, err := tcvod.NewClient(credential, "", profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcWaf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"
|
tcwaf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -33,7 +33,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *tcWaf.Client
|
sdkClient *tcwaf.Client
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 查询单个 SaaS 型 WAF 域名详情
|
// 查询单个 SaaS 型 WAF 域名详情
|
||||||
// REF: https://cloud.tencent.com/document/api/627/82938
|
// REF: https://cloud.tencent.com/document/api/627/82938
|
||||||
describeDomainDetailsSaasReq := tcWaf.NewDescribeDomainDetailsSaasRequest()
|
describeDomainDetailsSaasReq := tcwaf.NewDescribeDomainDetailsSaasRequest()
|
||||||
describeDomainDetailsSaasReq.Domain = common.StringPtr(d.config.Domain)
|
describeDomainDetailsSaasReq.Domain = common.StringPtr(d.config.Domain)
|
||||||
describeDomainDetailsSaasReq.DomainId = common.StringPtr(d.config.DomainId)
|
describeDomainDetailsSaasReq.DomainId = common.StringPtr(d.config.DomainId)
|
||||||
describeDomainDetailsSaasReq.InstanceId = common.StringPtr(d.config.InstanceId)
|
describeDomainDetailsSaasReq.InstanceId = common.StringPtr(d.config.InstanceId)
|
||||||
@ -108,7 +108,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 编辑 SaaS 型 WAF 域名
|
// 编辑 SaaS 型 WAF 域名
|
||||||
// REF: https://cloud.tencent.com/document/api/627/94309
|
// REF: https://cloud.tencent.com/document/api/627/94309
|
||||||
modifySpartaProtectionReq := tcWaf.NewModifySpartaProtectionRequest()
|
modifySpartaProtectionReq := tcwaf.NewModifySpartaProtectionRequest()
|
||||||
modifySpartaProtectionReq.Domain = common.StringPtr(d.config.Domain)
|
modifySpartaProtectionReq.Domain = common.StringPtr(d.config.Domain)
|
||||||
modifySpartaProtectionReq.DomainId = common.StringPtr(d.config.DomainId)
|
modifySpartaProtectionReq.DomainId = common.StringPtr(d.config.DomainId)
|
||||||
modifySpartaProtectionReq.InstanceID = common.StringPtr(d.config.InstanceId)
|
modifySpartaProtectionReq.InstanceID = common.StringPtr(d.config.InstanceId)
|
||||||
@ -123,9 +123,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(secretId, secretKey, region string) (*tcWaf.Client, error) {
|
func createSdkClient(secretId, secretKey, region string) (*tcwaf.Client, error) {
|
||||||
credential := common.NewCredential(secretId, secretKey)
|
credential := common.NewCredential(secretId, secretKey)
|
||||||
client, err := tcWaf.NewClient(credential, region, profile.NewClientProfile())
|
client, err := tcwaf.NewClient(credential, region, profile.NewClientProfile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
uCdn "github.com/ucloud/ucloud-sdk-go/services/ucdn"
|
"github.com/ucloud/ucloud-sdk-go/services/ucdn"
|
||||||
usdk "github.com/ucloud/ucloud-sdk-go/ucloud"
|
"github.com/ucloud/ucloud-sdk-go/ucloud"
|
||||||
uAuth "github.com/ucloud/ucloud-sdk-go/ucloud/auth"
|
"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -30,7 +30,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *uCdn.UCDNClient
|
sdkClient *ucdn.UCDNClient
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
getUcdnDomainConfigReq := d.sdkClient.NewGetUcdnDomainConfigRequest()
|
getUcdnDomainConfigReq := d.sdkClient.NewGetUcdnDomainConfigRequest()
|
||||||
getUcdnDomainConfigReq.DomainId = []string{d.config.DomainId}
|
getUcdnDomainConfigReq.DomainId = []string{d.config.DomainId}
|
||||||
if d.config.ProjectId != "" {
|
if d.config.ProjectId != "" {
|
||||||
getUcdnDomainConfigReq.ProjectId = usdk.String(d.config.ProjectId)
|
getUcdnDomainConfigReq.ProjectId = ucloud.String(d.config.ProjectId)
|
||||||
}
|
}
|
||||||
getUcdnDomainConfigResp, err := d.sdkClient.GetUcdnDomainConfig(getUcdnDomainConfigReq)
|
getUcdnDomainConfigResp, err := d.sdkClient.GetUcdnDomainConfig(getUcdnDomainConfigReq)
|
||||||
d.logger.Debug("sdk request 'ucdn.GetUcdnDomainConfig'", slog.Any("request", getUcdnDomainConfigReq), slog.Any("response", getUcdnDomainConfigResp))
|
d.logger.Debug("sdk request 'ucdn.GetUcdnDomainConfig'", slog.Any("request", getUcdnDomainConfigReq), slog.Any("response", getUcdnDomainConfigResp))
|
||||||
@ -101,15 +101,15 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
// REF: https://docs.ucloud.cn/api/ucdn-api/update_ucdn_domain_https_config_v2
|
// REF: https://docs.ucloud.cn/api/ucdn-api/update_ucdn_domain_https_config_v2
|
||||||
certId, _ := strconv.Atoi(upres.CertId)
|
certId, _ := strconv.Atoi(upres.CertId)
|
||||||
updateUcdnDomainHttpsConfigV2Req := d.sdkClient.NewUpdateUcdnDomainHttpsConfigV2Request()
|
updateUcdnDomainHttpsConfigV2Req := d.sdkClient.NewUpdateUcdnDomainHttpsConfigV2Request()
|
||||||
updateUcdnDomainHttpsConfigV2Req.DomainId = usdk.String(d.config.DomainId)
|
updateUcdnDomainHttpsConfigV2Req.DomainId = ucloud.String(d.config.DomainId)
|
||||||
updateUcdnDomainHttpsConfigV2Req.HttpsStatusCn = usdk.String(getUcdnDomainConfigResp.DomainList[0].HttpsStatusCn)
|
updateUcdnDomainHttpsConfigV2Req.HttpsStatusCn = ucloud.String(getUcdnDomainConfigResp.DomainList[0].HttpsStatusCn)
|
||||||
updateUcdnDomainHttpsConfigV2Req.HttpsStatusAbroad = usdk.String(getUcdnDomainConfigResp.DomainList[0].HttpsStatusAbroad)
|
updateUcdnDomainHttpsConfigV2Req.HttpsStatusAbroad = ucloud.String(getUcdnDomainConfigResp.DomainList[0].HttpsStatusAbroad)
|
||||||
updateUcdnDomainHttpsConfigV2Req.HttpsStatusAbroad = usdk.String(getUcdnDomainConfigResp.DomainList[0].HttpsStatusAbroad)
|
updateUcdnDomainHttpsConfigV2Req.HttpsStatusAbroad = ucloud.String(getUcdnDomainConfigResp.DomainList[0].HttpsStatusAbroad)
|
||||||
updateUcdnDomainHttpsConfigV2Req.CertId = usdk.Int(certId)
|
updateUcdnDomainHttpsConfigV2Req.CertId = ucloud.Int(certId)
|
||||||
updateUcdnDomainHttpsConfigV2Req.CertName = usdk.String(upres.CertName)
|
updateUcdnDomainHttpsConfigV2Req.CertName = ucloud.String(upres.CertName)
|
||||||
updateUcdnDomainHttpsConfigV2Req.CertType = usdk.String("ussl")
|
updateUcdnDomainHttpsConfigV2Req.CertType = ucloud.String("ussl")
|
||||||
if d.config.ProjectId != "" {
|
if d.config.ProjectId != "" {
|
||||||
updateUcdnDomainHttpsConfigV2Req.ProjectId = usdk.String(d.config.ProjectId)
|
updateUcdnDomainHttpsConfigV2Req.ProjectId = ucloud.String(d.config.ProjectId)
|
||||||
}
|
}
|
||||||
updateUcdnDomainHttpsConfigV2Resp, err := d.sdkClient.UpdateUcdnDomainHttpsConfigV2(updateUcdnDomainHttpsConfigV2Req)
|
updateUcdnDomainHttpsConfigV2Resp, err := d.sdkClient.UpdateUcdnDomainHttpsConfigV2(updateUcdnDomainHttpsConfigV2Req)
|
||||||
d.logger.Debug("sdk request 'ucdn.UpdateUcdnDomainHttpsConfigV2'", slog.Any("request", updateUcdnDomainHttpsConfigV2Req), slog.Any("response", updateUcdnDomainHttpsConfigV2Resp))
|
d.logger.Debug("sdk request 'ucdn.UpdateUcdnDomainHttpsConfigV2'", slog.Any("request", updateUcdnDomainHttpsConfigV2Req), slog.Any("response", updateUcdnDomainHttpsConfigV2Resp))
|
||||||
@ -120,13 +120,13 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(privateKey, publicKey string) (*uCdn.UCDNClient, error) {
|
func createSdkClient(privateKey, publicKey string) (*ucdn.UCDNClient, error) {
|
||||||
cfg := usdk.NewConfig()
|
cfg := ucloud.NewConfig()
|
||||||
|
|
||||||
credential := uAuth.NewCredential()
|
credential := auth.NewCredential()
|
||||||
credential.PrivateKey = privateKey
|
credential.PrivateKey = privateKey
|
||||||
credential.PublicKey = publicKey
|
credential.PublicKey = publicKey
|
||||||
|
|
||||||
client := uCdn.NewClient(&cfg, &credential)
|
client := ucdn.NewClient(&cfg, &credential)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
usdk "github.com/ucloud/ucloud-sdk-go/ucloud"
|
"github.com/ucloud/ucloud-sdk-go/ucloud"
|
||||||
uAuth "github.com/ucloud/ucloud-sdk-go/ucloud/auth"
|
"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -87,12 +87,12 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
// 添加 SSL 证书
|
// 添加 SSL 证书
|
||||||
// REF: https://docs.ucloud.cn/api/ufile-api/add_ufile_ssl_cert
|
// REF: https://docs.ucloud.cn/api/ufile-api/add_ufile_ssl_cert
|
||||||
addUFileSSLCertReq := d.sdkClient.NewAddUFileSSLCertRequest()
|
addUFileSSLCertReq := d.sdkClient.NewAddUFileSSLCertRequest()
|
||||||
addUFileSSLCertReq.BucketName = usdk.String(d.config.Bucket)
|
addUFileSSLCertReq.BucketName = ucloud.String(d.config.Bucket)
|
||||||
addUFileSSLCertReq.Domain = usdk.String(d.config.Domain)
|
addUFileSSLCertReq.Domain = ucloud.String(d.config.Domain)
|
||||||
addUFileSSLCertReq.USSLId = usdk.String(upres.CertId)
|
addUFileSSLCertReq.USSLId = ucloud.String(upres.CertId)
|
||||||
addUFileSSLCertReq.CertificateName = usdk.String(upres.CertName)
|
addUFileSSLCertReq.CertificateName = ucloud.String(upres.CertName)
|
||||||
if d.config.ProjectId != "" {
|
if d.config.ProjectId != "" {
|
||||||
addUFileSSLCertReq.ProjectId = usdk.String(d.config.ProjectId)
|
addUFileSSLCertReq.ProjectId = ucloud.String(d.config.ProjectId)
|
||||||
}
|
}
|
||||||
addUFileSSLCertResp, err := d.sdkClient.AddUFileSSLCert(addUFileSSLCertReq)
|
addUFileSSLCertResp, err := d.sdkClient.AddUFileSSLCert(addUFileSSLCertReq)
|
||||||
d.logger.Debug("sdk request 'us3.AddUFileSSLCert'", slog.Any("request", addUFileSSLCertReq), slog.Any("response", addUFileSSLCertResp))
|
d.logger.Debug("sdk request 'us3.AddUFileSSLCert'", slog.Any("request", addUFileSSLCertReq), slog.Any("response", addUFileSSLCertResp))
|
||||||
@ -104,10 +104,10 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(privateKey, publicKey, region string) (*usdkFile.UFileClient, error) {
|
func createSdkClient(privateKey, publicKey, region string) (*usdkFile.UFileClient, error) {
|
||||||
cfg := usdk.NewConfig()
|
cfg := ucloud.NewConfig()
|
||||||
cfg.Region = region
|
cfg.Region = region
|
||||||
|
|
||||||
credential := uAuth.NewCredential()
|
credential := auth.NewCredential()
|
||||||
credential.PrivateKey = privateKey
|
credential.PrivateKey = privateKey
|
||||||
credential.PublicKey = publicKey
|
credential.PublicKey = publicKey
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -26,7 +26,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *veCdn.CDN
|
sdkClient *vecdn.CDN
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
|||||||
panic("config is nil")
|
panic("config is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
client := veCdn.NewInstance()
|
client := vecdn.NewInstance()
|
||||||
client.Client.SetAccessKey(config.AccessKeyId)
|
client.Client.SetAccessKey(config.AccessKeyId)
|
||||||
client.Client.SetSecretKey(config.AccessKeySecret)
|
client.Client.SetSecretKey(config.AccessKeySecret)
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
if strings.HasPrefix(d.config.Domain, "*.") {
|
if strings.HasPrefix(d.config.Domain, "*.") {
|
||||||
// 获取指定证书可关联的域名
|
// 获取指定证书可关联的域名
|
||||||
// REF: https://www.volcengine.com/docs/6454/125711
|
// REF: https://www.volcengine.com/docs/6454/125711
|
||||||
describeCertConfigReq := &veCdn.DescribeCertConfigRequest{
|
describeCertConfigReq := &vecdn.DescribeCertConfigRequest{
|
||||||
CertId: upres.CertId,
|
CertId: upres.CertId,
|
||||||
}
|
}
|
||||||
describeCertConfigResp, err := d.sdkClient.DescribeCertConfig(describeCertConfigReq)
|
describeCertConfigResp, err := d.sdkClient.DescribeCertConfig(describeCertConfigReq)
|
||||||
@ -119,7 +119,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
for _, domain := range domains {
|
for _, domain := range domains {
|
||||||
// 关联证书与加速域名
|
// 关联证书与加速域名
|
||||||
// REF: https://www.volcengine.com/docs/6454/125712
|
// REF: https://www.volcengine.com/docs/6454/125712
|
||||||
batchDeployCertReq := &veCdn.BatchDeployCertRequest{
|
batchDeployCertReq := &vecdn.BatchDeployCertRequest{
|
||||||
CertId: upres.CertId,
|
CertId: upres.CertId,
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
veClb "github.com/volcengine/volcengine-go-sdk/service/clb"
|
veclb "github.com/volcengine/volcengine-go-sdk/service/clb"
|
||||||
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||||
veSession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
vesession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -33,7 +33,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *veClb.CLB
|
sdkClient *veclb.CLB
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func (d *DeployerProvider) deployToListener(ctx context.Context, cloudCertId str
|
|||||||
|
|
||||||
// 修改监听器
|
// 修改监听器
|
||||||
// REF: https://www.volcengine.com/docs/6406/71775
|
// REF: https://www.volcengine.com/docs/6406/71775
|
||||||
modifyListenerAttributesReq := &veClb.ModifyListenerAttributesInput{
|
modifyListenerAttributesReq := &veclb.ModifyListenerAttributesInput{
|
||||||
ListenerId: ve.String(d.config.ListenerId),
|
ListenerId: ve.String(d.config.ListenerId),
|
||||||
CertificateSource: ve.String("cert_center"),
|
CertificateSource: ve.String("cert_center"),
|
||||||
CertCenterCertificateId: ve.String(cloudCertId),
|
CertCenterCertificateId: ve.String(cloudCertId),
|
||||||
@ -120,14 +120,14 @@ func (d *DeployerProvider) deployToListener(ctx context.Context, cloudCertId str
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veClb.CLB, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veclb.CLB, error) {
|
||||||
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
||||||
|
|
||||||
session, err := veSession.NewSession(config)
|
session, err := vesession.NewSession(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := veClb.New(session)
|
client := veclb.New(session)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
veDcdn "github.com/volcengine/volcengine-go-sdk/service/dcdn"
|
vedcdn "github.com/volcengine/volcengine-go-sdk/service/dcdn"
|
||||||
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||||
veSession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
vesession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -29,7 +29,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *veDcdn.DCDN
|
sdkClient *vedcdn.DCDN
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 绑定证书
|
// 绑定证书
|
||||||
// REF: https://www.volcengine.com/docs/6559/1250189
|
// REF: https://www.volcengine.com/docs/6559/1250189
|
||||||
createCertBindReq := &veDcdn.CreateCertBindInput{
|
createCertBindReq := &vedcdn.CreateCertBindInput{
|
||||||
CertSource: ve.String("volc"),
|
CertSource: ve.String("volc"),
|
||||||
CertId: ve.String(upres.CertId),
|
CertId: ve.String(upres.CertId),
|
||||||
DomainNames: ve.StringSlice([]string{domain}),
|
DomainNames: ve.StringSlice([]string{domain}),
|
||||||
@ -100,18 +100,18 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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" // DCDN 服务默认区域:北京
|
region = "cn-beijing" // DCDN 服务默认区域:北京
|
||||||
}
|
}
|
||||||
|
|
||||||
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
||||||
|
|
||||||
session, err := veSession.NewSession(config)
|
session, err := vesession.NewSession(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := veDcdn.New(session)
|
client := vedcdn.New(session)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
veBase "github.com/volcengine/volc-sdk-golang/base"
|
vebase "github.com/volcengine/volc-sdk-golang/base"
|
||||||
veImageX "github.com/volcengine/volc-sdk-golang/service/imagex/v2"
|
veimagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -30,7 +30,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *veImageX.Imagex
|
sdkClient *veimagex.Imagex
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 获取域名配置
|
// 获取域名配置
|
||||||
// REF: https://www.volcengine.com/docs/508/9366
|
// REF: https://www.volcengine.com/docs/508/9366
|
||||||
getDomainConfigReq := &veImageX.GetDomainConfigQuery{
|
getDomainConfigReq := &veimagex.GetDomainConfigQuery{
|
||||||
ServiceID: d.config.ServiceId,
|
ServiceID: d.config.ServiceId,
|
||||||
DomainName: d.config.Domain,
|
DomainName: d.config.Domain,
|
||||||
}
|
}
|
||||||
@ -103,13 +103,13 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 更新 HTTPS 配置
|
// 更新 HTTPS 配置
|
||||||
// REF: https://www.volcengine.com/docs/508/66012
|
// REF: https://www.volcengine.com/docs/508/66012
|
||||||
updateHttpsReq := &veImageX.UpdateHTTPSReq{
|
updateHttpsReq := &veimagex.UpdateHTTPSReq{
|
||||||
UpdateHTTPSQuery: &veImageX.UpdateHTTPSQuery{
|
UpdateHTTPSQuery: &veimagex.UpdateHTTPSQuery{
|
||||||
ServiceID: d.config.ServiceId,
|
ServiceID: d.config.ServiceId,
|
||||||
},
|
},
|
||||||
UpdateHTTPSBody: &veImageX.UpdateHTTPSBody{
|
UpdateHTTPSBody: &veimagex.UpdateHTTPSBody{
|
||||||
Domain: d.config.Domain,
|
Domain: d.config.Domain,
|
||||||
HTTPS: &veImageX.UpdateHTTPSBodyHTTPS{
|
HTTPS: &veimagex.UpdateHTTPSBodyHTTPS{
|
||||||
CertID: upres.CertId,
|
CertID: upres.CertId,
|
||||||
EnableHTTPS: true,
|
EnableHTTPS: true,
|
||||||
},
|
},
|
||||||
@ -133,15 +133,15 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veImageX.Imagex, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veimagex.Imagex, error) {
|
||||||
var instance *veImageX.Imagex
|
var instance *veimagex.Imagex
|
||||||
if region == "" {
|
if region == "" {
|
||||||
instance = veImageX.NewInstance()
|
instance = veimagex.NewInstance()
|
||||||
} else {
|
} else {
|
||||||
instance = veImageX.NewInstanceWithRegion(region)
|
instance = veimagex.NewInstanceWithRegion(region)
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.SetCredential(veBase.Credentials{
|
instance.SetCredential(vebase.Credentials{
|
||||||
AccessKeyID: accessKeyId,
|
AccessKeyID: accessKeyId,
|
||||||
SecretAccessKey: accessKeySecret,
|
SecretAccessKey: accessKeySecret,
|
||||||
})
|
})
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
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"
|
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
@ -27,7 +27,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *veLive.Live
|
sdkClient *velive.Live
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
|||||||
panic("config is nil")
|
panic("config is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
client := veLive.NewInstance()
|
client := velive.NewInstance()
|
||||||
client.SetAccessKey(config.AccessKeyId)
|
client.SetAccessKey(config.AccessKeyId)
|
||||||
client.SetSecretKey(config.AccessKeySecret)
|
client.SetSecretKey(config.AccessKeySecret)
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
for {
|
for {
|
||||||
// 查询域名列表
|
// 查询域名列表
|
||||||
// REF: https://www.volcengine.com/docs/6469/1186277#%E6%9F%A5%E8%AF%A2%E5%9F%9F%E5%90%8D%E5%88%97%E8%A1%A8
|
// REF: https://www.volcengine.com/docs/6469/1186277#%E6%9F%A5%E8%AF%A2%E5%9F%9F%E5%90%8D%E5%88%97%E8%A1%A8
|
||||||
listDomainDetailReq := &veLive.ListDomainDetailBody{
|
listDomainDetailReq := &velive.ListDomainDetailBody{
|
||||||
PageNum: listDomainDetailPageNum,
|
PageNum: listDomainDetailPageNum,
|
||||||
PageSize: listDomainDetailPageSize,
|
PageSize: listDomainDetailPageSize,
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
for _, domain := range domains {
|
for _, domain := range domains {
|
||||||
// 绑定证书
|
// 绑定证书
|
||||||
// REF: https://www.volcengine.com/docs/6469/1186278#%E7%BB%91%E5%AE%9A%E8%AF%81%E4%B9%A6
|
// REF: https://www.volcengine.com/docs/6469/1186278#%E7%BB%91%E5%AE%9A%E8%AF%81%E4%B9%A6
|
||||||
bindCertReq := &veLive.BindCertBody{
|
bindCertReq := &velive.BindCertBody{
|
||||||
ChainID: upres.CertId,
|
ChainID: upres.CertId,
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
HTTPS: ve.Bool(true),
|
HTTPS: ve.Bool(true),
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
veTos "github.com/volcengine/ve-tos-golang-sdk/v2/tos"
|
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
@ -30,7 +30,7 @@ type DeployerConfig struct {
|
|||||||
type DeployerProvider struct {
|
type DeployerProvider struct {
|
||||||
config *DeployerConfig
|
config *DeployerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
sdkClient *veTos.ClientV2
|
sdkClient *tos.ClientV2
|
||||||
sslUploader uploader.Uploader
|
sslUploader uploader.Uploader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,9 +91,9 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 设置自定义域名
|
// 设置自定义域名
|
||||||
// REF: https://www.volcengine.com/docs/6559/1250189
|
// REF: https://www.volcengine.com/docs/6559/1250189
|
||||||
putBucketCustomDomainReq := &veTos.PutBucketCustomDomainInput{
|
putBucketCustomDomainReq := &tos.PutBucketCustomDomainInput{
|
||||||
Bucket: d.config.Bucket,
|
Bucket: d.config.Bucket,
|
||||||
Rule: veTos.CustomDomainRule{
|
Rule: tos.CustomDomainRule{
|
||||||
Domain: d.config.Domain,
|
Domain: d.config.Domain,
|
||||||
CertID: upres.CertId,
|
CertID: upres.CertId,
|
||||||
},
|
},
|
||||||
@ -107,13 +107,13 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veTos.ClientV2, error) {
|
func createSdkClient(accessKeyId, accessKeySecret, region string) (*tos.ClientV2, error) {
|
||||||
endpoint := fmt.Sprintf("tos-%s.ivolces.com", region)
|
endpoint := fmt.Sprintf("tos-%s.ivolces.com", region)
|
||||||
|
|
||||||
client, err := veTos.NewClientV2(
|
client, err := tos.NewClientV2(
|
||||||
endpoint,
|
endpoint,
|
||||||
veTos.WithRegion(region),
|
tos.WithRegion(region),
|
||||||
veTos.WithCredentials(veTos.NewStaticCredentials(accessKeyId, accessKeySecret)),
|
tos.WithCredentials(tos.NewStaticCredentials(accessKeyId, accessKeySecret)),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user