mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
Merge pull request #273 from LeoChen98/enhance-tencent-cdn-dupe-deploy
enhance: resolve error on tencent cdn dupe deployment
This commit is contained in:
commit
feb851a3fc
5
go.mod
5
go.mod
@ -26,7 +26,9 @@ require (
|
|||||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.1017
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.1017
|
||||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1030
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1030
|
||||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.992
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.992
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.1030
|
||||||
golang.org/x/crypto v0.28.0
|
golang.org/x/crypto v0.28.0
|
||||||
|
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
||||||
k8s.io/api v0.31.1
|
k8s.io/api v0.31.1
|
||||||
k8s.io/apimachinery v0.31.1
|
k8s.io/apimachinery v0.31.1
|
||||||
k8s.io/client-go v0.31.1
|
k8s.io/client-go v0.31.1
|
||||||
@ -58,7 +60,6 @@ require (
|
|||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
|
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
|
||||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.1030 // indirect
|
|
||||||
github.com/x448/float16 v0.8.4 // indirect
|
github.com/x448/float16 v0.8.4 // indirect
|
||||||
go.mongodb.org/mongo-driver v1.12.0 // indirect
|
go.mongodb.org/mongo-driver v1.12.0 // indirect
|
||||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
@ -111,7 +112,7 @@ require (
|
|||||||
github.com/domodwyer/mailyak/v3 v3.6.2 // indirect
|
github.com/domodwyer/mailyak/v3 v3.6.2 // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/fatih/color v1.17.0 // indirect
|
github.com/fatih/color v1.17.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
|
||||||
github.com/ganigeorgiev/fexpr v0.4.1 // indirect
|
github.com/ganigeorgiev/fexpr v0.4.1 // indirect
|
||||||
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
|
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
|
||||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
|
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -206,6 +206,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
|
|||||||
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
|
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
|
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
|
||||||
github.com/gammazero/toposort v0.1.1/go.mod h1:H2cozTnNpMw0hg2VHAYsAxmkHXBYroNangj2NTBQDvw=
|
github.com/gammazero/toposort v0.1.1/go.mod h1:H2cozTnNpMw0hg2VHAYsAxmkHXBYroNangj2NTBQDvw=
|
||||||
github.com/ganigeorgiev/fexpr v0.4.1 h1:hpUgbUEEWIZhSDBtf4M9aUNfQQ0BZkGRaMePy7Gcx5k=
|
github.com/ganigeorgiev/fexpr v0.4.1 h1:hpUgbUEEWIZhSDBtf4M9aUNfQQ0BZkGRaMePy7Gcx5k=
|
||||||
github.com/ganigeorgiev/fexpr v0.4.1/go.mod h1:RyGiGqmeXhEQ6+mlGdnUleLHgtzzu/VGO2WtJkF5drE=
|
github.com/ganigeorgiev/fexpr v0.4.1/go.mod h1:RyGiGqmeXhEQ6+mlGdnUleLHgtzzu/VGO2WtJkF5drE=
|
||||||
@ -531,6 +533,8 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
|
|||||||
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||||
|
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
|
||||||
|
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
@ -194,4 +194,4 @@ func getDeployVariables(conf domain.DeployConfig) map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return rs
|
return rs
|
||||||
}
|
}
|
@ -2,10 +2,10 @@ package deployer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
|
cdn "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"
|
||||||
@ -100,16 +100,23 @@ func (d *TencentCDNDeployer) deploy(certId string) error {
|
|||||||
// 如果是泛域名就从cdn列表下获取SSL证书中的可用域名
|
// 如果是泛域名就从cdn列表下获取SSL证书中的可用域名
|
||||||
domain := getDeployString(d.option.DeployConfig, "domain")
|
domain := getDeployString(d.option.DeployConfig, "domain")
|
||||||
if strings.Contains(domain, "*") {
|
if strings.Contains(domain, "*") {
|
||||||
list, errGetList := d.getDomainList()
|
list, errGetList := d.getDomainList(certId)
|
||||||
if errGetList != nil {
|
if errGetList != nil {
|
||||||
return fmt.Errorf("failed to get certificate domain list: %w", errGetList)
|
return fmt.Errorf("failed to get certificate domain list: %w", errGetList)
|
||||||
}
|
}
|
||||||
if list == nil || len(list) == 0 {
|
if len(list) == 0 {
|
||||||
return fmt.Errorf("failed to get certificate domain list: empty list.")
|
d.infos = append(d.infos, "没有需要部署的实例")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
request.InstanceIdList = common.StringPtrs(list)
|
request.InstanceIdList = common.StringPtrs(list)
|
||||||
} else { // 否则直接使用传入的域名
|
} else { // 否则直接使用传入的域名
|
||||||
request.InstanceIdList = common.StringPtrs([]string{domain})
|
deployed, _ := d.isDomainDeployed(certId, domain)
|
||||||
|
if(deployed){
|
||||||
|
d.infos = append(d.infos, "域名已部署")
|
||||||
|
return nil
|
||||||
|
}else{
|
||||||
|
request.InstanceIdList = common.StringPtrs([]string{domain})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回的resp是一个DeployCertificateInstanceResponse的实例,与请求对象对应
|
// 返回的resp是一个DeployCertificateInstanceResponse的实例,与请求对象对应
|
||||||
@ -121,23 +128,61 @@ func (d *TencentCDNDeployer) deploy(certId string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *TencentCDNDeployer) getDomainList() ([]string, error) {
|
func (d *TencentCDNDeployer) getDomainList(certId string) ([]string, error) {
|
||||||
cpf := profile.NewClientProfile()
|
cpf := profile.NewClientProfile()
|
||||||
cpf.HttpProfile.Endpoint = "cdn.tencentcloudapi.com"
|
cpf.HttpProfile.Endpoint = "cdn.tencentcloudapi.com"
|
||||||
client, _ := cdn.NewClient(d.credential, "", cpf)
|
client, _ := cdn.NewClient(d.credential, "", cpf)
|
||||||
|
|
||||||
request := cdn.NewDescribeCertDomainsRequest()
|
request := cdn.NewDescribeCertDomainsRequest()
|
||||||
|
|
||||||
cert := base64.StdEncoding.EncodeToString([]byte(d.option.Certificate.Certificate))
|
request.CertId = common.StringPtr(certId)
|
||||||
request.Cert = &cert
|
|
||||||
|
|
||||||
response, err := client.DescribeCertDomains(request)
|
response, err := client.DescribeCertDomains(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get domain list: %w", err)
|
return nil, fmt.Errorf("failed to get domain list: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deployedDomains, err := d.getDeployedDomainList(certId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get deployed domain list: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
domains := make([]string, 0)
|
domains := make([]string, 0)
|
||||||
for _, domain := range response.Response.Domains {
|
for _, domain := range response.Response.Domains {
|
||||||
|
domainStr := *domain
|
||||||
|
if(slices.Contains(deployedDomains, domainStr)){
|
||||||
|
domains = append(domains, domainStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return domains, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *TencentCDNDeployer) isDomainDeployed(certId, domain string) (bool, error) {
|
||||||
|
deployedDomains, err := d.getDeployedDomainList(certId)
|
||||||
|
if(err != nil){
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return slices.Contains(deployedDomains, domain), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *TencentCDNDeployer) getDeployedDomainList(certId string) ([]string, error) {
|
||||||
|
cpf := profile.NewClientProfile()
|
||||||
|
cpf.HttpProfile.Endpoint = "ssl.tencentcloudapi.com"
|
||||||
|
client, _ := ssl.NewClient(d.credential, "", cpf)
|
||||||
|
|
||||||
|
request := ssl.NewDescribeDeployedResourcesRequest()
|
||||||
|
request.CertificateIds = common.StringPtrs([]string{certId})
|
||||||
|
request.ResourceType = common.StringPtr("cdn")
|
||||||
|
|
||||||
|
response, err := client.DescribeDeployedResources(request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get deployed domain list: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
domains := make([]string, 0)
|
||||||
|
for _, domain := range response.Response.DeployedResources[0].Resources {
|
||||||
domains = append(domains, *domain)
|
domains = append(domains, *domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user