diff --git a/internal/deployer/qiniu_cdn.go b/internal/deployer/qiniu_cdn.go index f6e6b167..fa74a0cb 100644 --- a/internal/deployer/qiniu_cdn.go +++ b/internal/deployer/qiniu_cdn.go @@ -76,7 +76,8 @@ func (d *QiniuCDNDeployer) Deploy(ctx context.Context) error { } func (d *QiniuCDNDeployer) enableHttps(certId string) error { - path := fmt.Sprintf("/domain/%s/sslize", getDeployString(d.option.DeployConfig, "domain")) + domain := d.option.DeployConfig.GetDomain() + path := fmt.Sprintf("/domain/%s/sslize", domain) body := &qiniuModifyDomainCertReq{ CertID: certId, @@ -102,7 +103,9 @@ type qiniuDomainInfo struct { } func (d *QiniuCDNDeployer) getDomainInfo() (*qiniuDomainInfo, error) { - path := fmt.Sprintf("/domain/%s", getDeployString(d.option.DeployConfig, "domain")) + domain := d.option.DeployConfig.GetDomain() + + path := fmt.Sprintf("/domain/%s", domain) res, err := d.req(qiniuGateway+path, http.MethodGet, nil) if err != nil { @@ -164,7 +167,8 @@ type qiniuModifyDomainCertReq struct { } func (d *QiniuCDNDeployer) modifyDomainCert(certId string) error { - path := fmt.Sprintf("/domain/%s/httpsconf", getDeployString(d.option.DeployConfig, "domain")) + domain := d.option.DeployConfig.GetDomain() + path := fmt.Sprintf("/domain/%s/httpsconf", domain) body := &qiniuModifyDomainCertReq{ CertID: certId, diff --git a/internal/domain/domains.go b/internal/domain/domains.go index 7aaa9051..d706a1c7 100644 --- a/internal/domain/domains.go +++ b/internal/domain/domains.go @@ -1,5 +1,7 @@ package domain +import "strings" + type ApplyConfig struct { Email string `json:"email"` Access string `json:"access"` @@ -16,6 +18,29 @@ type DeployConfig struct { Config map[string]any `json:"config"` } +// GetDomain returns the domain from the deploy config +// if the domain is a wildcard domain, and wildcard is true, return the wildcard domain +func (d *DeployConfig) GetDomain(wildcard ...bool) string { + if _, ok := d.Config["domain"]; !ok { + return "" + } + + val, ok := d.Config["domain"].(string) + if !ok { + return "" + } + + if !strings.HasPrefix(val, "*") { + return val + } + + if len(wildcard) > 0 && wildcard[0] { + return val + } + + return strings.TrimPrefix(val, "*") +} + type KV struct { Key string `json:"key"` Value string `json:"value"`