Skip to content

Commit 39f8484

Browse files
committed
1 parent 892256c commit 39f8484

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

internal/pkg/core/deployer/providers/baishan-cdn/baishan_cdn.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"log/slog"
9+
"regexp"
10+
"strings"
811
"time"
912

1013
xerrors "github.com/pkg/errors"
@@ -75,6 +78,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
7578

7679
// 新增证书
7780
// REF: https://portal.baishancloud.com/track/document/downloadPdf/1441
81+
certificateId := ""
7882
createCertificateReq := &bssdk.CreateCertificateRequest{
7983
Certificate: certPem,
8084
Key: privkeyPem,
@@ -83,7 +87,19 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
8387
createCertificateResp, err := d.sdkClient.CreateCertificate(createCertificateReq)
8488
d.logger.Debug("sdk request 'baishan.CreateCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
8589
if err != nil {
86-
return nil, xerrors.Wrap(err, "failed to execute sdk request 'baishan.CreateCertificate'")
90+
if createCertificateResp != nil {
91+
if createCertificateResp.GetCode() == 400699 && strings.Contains(createCertificateResp.GetMessage(), "this certificate is exists") {
92+
// 证书已存在,忽略新增证书接口错误
93+
re := regexp.MustCompile(`\d+`)
94+
certificateId = re.FindString(createCertificateResp.GetMessage())
95+
}
96+
}
97+
98+
if certificateId == "" {
99+
return nil, xerrors.Wrap(err, "failed to execute sdk request 'baishan.CreateCertificate'")
100+
}
101+
} else {
102+
certificateId = createCertificateResp.Data.CertId.String()
87103
}
88104

89105
// 设置域名配置
@@ -92,7 +108,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
92108
Domains: d.config.Domain,
93109
Config: &bssdk.DomainConfig{
94110
Https: &bssdk.DomainConfigHttps{
95-
CertId: createCertificateResp.Data.CertId,
111+
CertId: json.Number(certificateId),
96112
ForceHttps: getDomainConfigResp.Data[0].Config.Https.ForceHttps,
97113
EnableHttp2: getDomainConfigResp.Data[0].Config.Https.EnableHttp2,
98114
EnableOcsp: getDomainConfigResp.Data[0].Config.Https.EnableOcsp,

internal/pkg/vendors/baishan-sdk/client.go

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
8484
func (c *Client) sendRequestWithResult(method string, path string, params interface{}, result BaseResponse) error {
8585
resp, err := c.sendRequest(method, path, params)
8686
if err != nil {
87+
if resp != nil {
88+
json.Unmarshal(resp.Body(), &result)
89+
}
8790
return err
8891
}
8992

0 commit comments

Comments
 (0)