mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
fix: #544
This commit is contained in:
parent
892256c0b9
commit
39f8484b2a
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
@ -75,6 +78,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
// 新增证书
|
// 新增证书
|
||||||
// REF: https://portal.baishancloud.com/track/document/downloadPdf/1441
|
// REF: https://portal.baishancloud.com/track/document/downloadPdf/1441
|
||||||
|
certificateId := ""
|
||||||
createCertificateReq := &bssdk.CreateCertificateRequest{
|
createCertificateReq := &bssdk.CreateCertificateRequest{
|
||||||
Certificate: certPem,
|
Certificate: certPem,
|
||||||
Key: privkeyPem,
|
Key: privkeyPem,
|
||||||
@ -83,7 +87,19 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
createCertificateResp, err := d.sdkClient.CreateCertificate(createCertificateReq)
|
createCertificateResp, err := d.sdkClient.CreateCertificate(createCertificateReq)
|
||||||
d.logger.Debug("sdk request 'baishan.CreateCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
|
d.logger.Debug("sdk request 'baishan.CreateCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'baishan.CreateCertificate'")
|
if createCertificateResp != nil {
|
||||||
|
if createCertificateResp.GetCode() == 400699 && strings.Contains(createCertificateResp.GetMessage(), "this certificate is exists") {
|
||||||
|
// 证书已存在,忽略新增证书接口错误
|
||||||
|
re := regexp.MustCompile(`\d+`)
|
||||||
|
certificateId = re.FindString(createCertificateResp.GetMessage())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if certificateId == "" {
|
||||||
|
return nil, xerrors.Wrap(err, "failed to execute sdk request 'baishan.CreateCertificate'")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
certificateId = createCertificateResp.Data.CertId.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置域名配置
|
// 设置域名配置
|
||||||
@ -92,7 +108,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
Domains: d.config.Domain,
|
Domains: d.config.Domain,
|
||||||
Config: &bssdk.DomainConfig{
|
Config: &bssdk.DomainConfig{
|
||||||
Https: &bssdk.DomainConfigHttps{
|
Https: &bssdk.DomainConfigHttps{
|
||||||
CertId: createCertificateResp.Data.CertId,
|
CertId: json.Number(certificateId),
|
||||||
ForceHttps: getDomainConfigResp.Data[0].Config.Https.ForceHttps,
|
ForceHttps: getDomainConfigResp.Data[0].Config.Https.ForceHttps,
|
||||||
EnableHttp2: getDomainConfigResp.Data[0].Config.Https.EnableHttp2,
|
EnableHttp2: getDomainConfigResp.Data[0].Config.Https.EnableHttp2,
|
||||||
EnableOcsp: getDomainConfigResp.Data[0].Config.Https.EnableOcsp,
|
EnableOcsp: getDomainConfigResp.Data[0].Config.Https.EnableOcsp,
|
||||||
|
3
internal/pkg/vendors/baishan-sdk/client.go
vendored
3
internal/pkg/vendors/baishan-sdk/client.go
vendored
@ -84,6 +84,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
|||||||
func (c *Client) sendRequestWithResult(method string, path string, params interface{}, result BaseResponse) error {
|
func (c *Client) sendRequestWithResult(method string, path string, params interface{}, result BaseResponse) error {
|
||||||
resp, err := c.sendRequest(method, path, params)
|
resp, err := c.sendRequest(method, path, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp != nil {
|
||||||
|
json.Unmarshal(resp.Body(), &result)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user