【调整】还原七牛云部署到第二次提交

This commit is contained in:
v-me-50
2026-01-19 15:54:23 +08:00
parent f588ba643b
commit f198dc46b4

View File

@@ -5,10 +5,11 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/qiniu/go-sdk/v7/auth"
"github.com/qiniu/go-sdk/v7/client"
"net/http"
"strconv"
"github.com/qiniu/go-sdk/v7/auth"
"github.com/qiniu/go-sdk/v7/client"
)
type commonResponse struct {
@@ -50,6 +51,7 @@ func requestQiniu(cfg map[string]any, path string, m map[string]any, method stri
return err
}
func DeployQiniuCdn(cfg map[string]any) error {
_, ok := cfg["certificate"].(map[string]any)
if !ok {
@@ -73,43 +75,6 @@ func DeployQiniuCdn(cfg map[string]any) error {
return err
}
func updateQiniuDomainCert(cfg map[string]any) error {
_, ok := cfg["certificate"].(map[string]any)
if !ok {
return fmt.Errorf("证书不存在")
}
domain, ok := cfg["domain"].(string)
if !ok {
return fmt.Errorf("参数错误domain")
}
forceHttps, ok := cfg["force_https"].(bool)
if !ok {
forceHttps = true
}
http2Enable, ok := cfg["http2_enable"].(bool)
if !ok {
http2Enable = true
}
certId, err := uploadQiniuCert(cfg)
if err != nil {
return err
}
m := map[string]any{
"certid": certId,
"domain": domain,
"forceHttps": forceHttps,
"http2Enable": http2Enable,
}
var response commonResponse
err = requestQiniu(cfg, fmt.Sprintf("domain/%s/httpsconf", domain), m, "PUT", &response)
return err
}
func DeployQiniuOss(cfg map[string]any) error {
_, ok := cfg["certificate"].(map[string]any)
if !ok {
@@ -120,38 +85,10 @@ func DeployQiniuOss(cfg map[string]any) error {
return fmt.Errorf("参数错误domain")
}
// 判断域名是否已开启HTTPS
// {
// "certId": <CertID>,
// "forceHttps": <ForceHttps>,
// "http2Enable": <Http2Enable>
// }
var httpsConfig struct {
Https struct {
CertID string `json:"certId"`
ForceHttps bool `json:"forceHttps"`
Http2Enable bool `json:"http2Enable"`
} `json:"https"`
}
err := requestQiniu(cfg, fmt.Sprintf("domain/%s", domain), nil, "GET", &httpsConfig)
if err != nil {
return fmt.Errorf("获取域名HTTPS配置失败: %v", err)
}
certId, err := uploadQiniuCert(cfg)
if err != nil {
return err
}
if httpsConfig.Https.CertID != "" {
// 如果已开启HTTPS则调用updateQiniuDomainCert更新证书
cfg["cert_id"] = certId
cfg["force_https"] = httpsConfig.Https.ForceHttps
cfg["http2_enable"] = httpsConfig.Https.Http2Enable
err = updateQiniuDomainCert(cfg)
return err
} else {
// 如果未开启HTTPS则使用POST请求绑定证书
m := map[string]any{
"certid": certId,
"domain": domain,
@@ -159,18 +96,6 @@ func DeployQiniuOss(cfg map[string]any) error {
var response commonResponse
err = requestQiniu(cfg, "cert/bind", m, "POST", &response)
return err
}
}
func delQiniuCert(cfg map[string]any) error {
certId, ok := cfg["old_cert_id"].(string)
if !ok {
return fmt.Errorf("参数错误cert_id")
}
m := map[string]any{}
var response commonResponse
err := requestQiniu(cfg, fmt.Sprintf("sslcert/%v", certId), m, "DELETE", &response)
return err
}
func uploadQiniuCert(cfg map[string]any) (string, error) {