mirror of
https://github.com/certimate-go/certimate.git
synced 2026-09-03 06:23:54 +08:00
fix: #1367
This commit is contained in:
@@ -104,12 +104,11 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
switch d.config.DomainMatchPattern {
|
||||
case "", DOMAIN_MATCH_PATTERN_EXACT:
|
||||
{
|
||||
if d.config.Domain == "" {
|
||||
domain := normalizeDomain(d.config.Domain)
|
||||
if domain == "" {
|
||||
return nil, fmt.Errorf("config `domain` is required")
|
||||
}
|
||||
|
||||
// "*.example.com" → ".example.com",适配阿里云 CDN 要求的泛域名格式
|
||||
domain := strings.TrimPrefix(d.config.Domain, "*")
|
||||
domains = []string{domain}
|
||||
}
|
||||
|
||||
@@ -270,3 +269,11 @@ func createSDKClient(accessKeyId, accessKeySecret string) (*alicdn.Client, error
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func normalizeDomain(domain string) string {
|
||||
// "*.example.com" → ".example.com",适配阿里云 CDN 的泛域名参数要求
|
||||
if strings.HasPrefix(domain, "*.") {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
@@ -104,12 +104,11 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
switch d.config.DomainMatchPattern {
|
||||
case "", DOMAIN_MATCH_PATTERN_EXACT:
|
||||
{
|
||||
if d.config.Domain == "" {
|
||||
domain := normalizeDomain(d.config.Domain)
|
||||
if domain == "" {
|
||||
return nil, fmt.Errorf("config `domain` is required")
|
||||
}
|
||||
|
||||
// "*.example.com" → ".example.com",适配阿里云 DCDN 要求的泛域名格式
|
||||
domain := strings.TrimPrefix(d.config.Domain, "*")
|
||||
domains = []string{domain}
|
||||
}
|
||||
|
||||
@@ -271,3 +270,11 @@ func createSDKClient(accessKeyId, accessKeySecret string) (*alidcdn.Client, erro
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func normalizeDomain(domain string) string {
|
||||
// "*.example.com" → ".example.com",适配阿里云 DCDN 的泛域名参数要求
|
||||
if strings.HasPrefix(domain, "*.") {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
@@ -79,12 +79,11 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
switch d.config.DomainMatchPattern {
|
||||
case "", DOMAIN_MATCH_PATTERN_EXACT:
|
||||
{
|
||||
if d.config.Domain == "" {
|
||||
domain := normalizeDomain(d.config.Domain)
|
||||
if domain == "" {
|
||||
return nil, fmt.Errorf("config `domain` is required")
|
||||
}
|
||||
|
||||
// "*.example.com" → ".example.com",适配阿里云 Live 要求的泛域名格式
|
||||
domain := strings.TrimPrefix(d.config.Domain, "*")
|
||||
domains = []string{domain}
|
||||
}
|
||||
|
||||
@@ -251,3 +250,11 @@ func createSDKClient(accessKeyId, accessKeySecret, region string) (*alilive.Clie
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func normalizeDomain(domain string) string {
|
||||
// "*.example.com" → ".example.com",适配阿里云 Live 的泛域名参数要求
|
||||
if strings.HasPrefix(domain, "*.") {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
@@ -98,7 +99,8 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
}
|
||||
|
||||
func (d *Deployer) deployToDomain(ctx context.Context, certPEM, privkeyPEM string) error {
|
||||
if d.config.Domain == "" {
|
||||
domain := normalizeDomain(d.config.Domain)
|
||||
if domain == "" {
|
||||
return fmt.Errorf("config `domain` is required")
|
||||
}
|
||||
|
||||
@@ -113,7 +115,7 @@ func (d *Deployer) deployToDomain(ctx context.Context, certPEM, privkeyPEM strin
|
||||
// 查询域名配置
|
||||
// REF: https://portal.baishancloud.com/track/document/api/1/1065
|
||||
getDomainConfigReq := &baishansdk.GetDomainConfigRequest{
|
||||
Domains: lo.ToPtr(d.config.Domain),
|
||||
Domains: lo.ToPtr(domain),
|
||||
Config: []*string{lo.ToPtr("https")},
|
||||
}
|
||||
getDomainConfigResp, err := d.sdkClient.GetDomainConfigWithContext(ctx, getDomainConfigReq)
|
||||
@@ -121,13 +123,13 @@ func (d *Deployer) deployToDomain(ctx context.Context, certPEM, privkeyPEM strin
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute sdk request 'cdn.GetDomainConfig': %w", err)
|
||||
} else if len(getDomainConfigResp.Data) == 0 {
|
||||
return fmt.Errorf("could not find domain '%s'", d.config.Domain)
|
||||
return fmt.Errorf("could not find domain '%s'", domain)
|
||||
}
|
||||
|
||||
// 设置域名配置
|
||||
// REF: https://portal.baishancloud.com/track/document/api/1/1045
|
||||
setDomainConfigReq := &baishansdk.SetDomainConfigRequest{
|
||||
Domains: lo.ToPtr(d.config.Domain),
|
||||
Domains: lo.ToPtr(domain),
|
||||
Config: &baishansdk.DomainConfig{
|
||||
Https: &baishansdk.DomainConfigHttps{
|
||||
CertId: json.Number(upres.CertId),
|
||||
@@ -172,3 +174,11 @@ func createSDKClient(apiToken string) (*baishansdk.Client, error) {
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func normalizeDomain(domain string) string {
|
||||
// "*.example.com" → ".example.com",适配白山云 CDN 的泛域名参数要求
|
||||
if strings.HasPrefix(domain, "*.") {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
@@ -89,12 +89,11 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
switch d.config.DomainMatchPattern {
|
||||
case "", DOMAIN_MATCH_PATTERN_EXACT:
|
||||
{
|
||||
if d.config.Domain == "" {
|
||||
domain := normalizeDomain(d.config.Domain)
|
||||
if domain == "" {
|
||||
return nil, fmt.Errorf("config `domain` is required")
|
||||
}
|
||||
|
||||
// "*.example.com" → ".example.com",适配七牛云 CDN 要求的泛域名格式
|
||||
domain := strings.TrimPrefix(d.config.Domain, "*")
|
||||
domains = []string{domain}
|
||||
}
|
||||
|
||||
@@ -232,3 +231,11 @@ func (d *Deployer) updateDomainCertificate(ctx context.Context, domain string, c
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeDomain(domain string) string {
|
||||
// "*.example.com" → ".example.com",适配七牛云 CDN 的泛域名参数要求
|
||||
if strings.HasPrefix(domain, "*.") {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
@@ -99,12 +99,11 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
switch d.config.DomainMatchPattern {
|
||||
case "", DOMAIN_MATCH_PATTERN_EXACT:
|
||||
{
|
||||
if d.config.Domain == "" {
|
||||
domain := normalizeDomain(d.config.Domain)
|
||||
if domain == "" {
|
||||
return nil, fmt.Errorf("config `domain` is required")
|
||||
}
|
||||
|
||||
// "*.example.com" → ".example.com",适配火山引擎 DCDN 要求的泛域名格式
|
||||
domain := strings.TrimPrefix(d.config.Domain, "*")
|
||||
domains = []string{domain}
|
||||
}
|
||||
|
||||
@@ -227,3 +226,11 @@ func createSDKClient(accessKeyId, secretAccessKey, region string) (*vedcdn.DCDN,
|
||||
client := vedcdn.New(session)
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func normalizeDomain(domain string) string {
|
||||
// "*.example.com" → ".example.com",适配火山引擎 DCDN 的泛域名参数要求
|
||||
if strings.HasPrefix(domain, "*.") {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
@@ -94,9 +94,8 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
return nil, fmt.Errorf("config `domains` is required")
|
||||
}
|
||||
|
||||
// "*.example.com" → ".example.com",适配网宿云 CDN 要求的泛域名格式
|
||||
domains = lo.Map(d.config.Domains, func(domain string, _ int) string {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
return normalizeDomain(domain)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -130,3 +129,11 @@ func createSDKClient(accessKeyId, accessKeySecret string) (*wangsucdn.Client, er
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func normalizeDomain(domain string) string {
|
||||
// "*.example.com" → ".example.com",适配网宿云 CDN 的泛域名参数要求
|
||||
if strings.HasPrefix(domain, "*.") {
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user