mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
fix: wangsu api error
This commit is contained in:
parent
54ae378e30
commit
ff58b9a317
@ -13,6 +13,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
@ -113,7 +114,8 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
// http://open.chinanetcenter.com/cdn/certificates/5dca2205f9e9cc0001df7b33
|
// http://open.chinanetcenter.com/cdn/certificates/5dca2205f9e9cc0001df7b33
|
||||||
// http://open.chinanetcenter.com/cdn/certificates/329f12c1fe6708c23c31e91f/versions/5
|
// http://open.chinanetcenter.com/cdn/certificates/329f12c1fe6708c23c31e91f/versions/5
|
||||||
var wangsuCertUrl string
|
var wangsuCertUrl string
|
||||||
var wangsuCertId, wangsuCertVer string
|
var wangsuCertId string
|
||||||
|
var wangsuCertVer int32
|
||||||
|
|
||||||
// 如果原证书 ID 为空,则创建证书;否则更新证书。
|
// 如果原证书 ID 为空,则创建证书;否则更新证书。
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
@ -139,7 +141,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
wangsuCertId = wangsuCertIdMatches[1]
|
wangsuCertId = wangsuCertIdMatches[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
wangsuCertVer = "1"
|
wangsuCertVer = 1
|
||||||
} else {
|
} else {
|
||||||
// 更新证书
|
// 更新证书
|
||||||
updateCertificateReq := &wangsucdn.UpdateCertificateRequest{
|
updateCertificateReq := &wangsucdn.UpdateCertificateRequest{
|
||||||
@ -164,7 +166,8 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
|
|
||||||
wangsuCertVerMatches := regexp.MustCompile(`/versions/(\d+)`).FindStringSubmatch(wangsuCertUrl)
|
wangsuCertVerMatches := regexp.MustCompile(`/versions/(\d+)`).FindStringSubmatch(wangsuCertUrl)
|
||||||
if len(wangsuCertVerMatches) > 1 {
|
if len(wangsuCertVerMatches) > 1 {
|
||||||
wangsuCertVer = wangsuCertVerMatches[1]
|
n, _ := strconv.ParseInt(wangsuCertVerMatches[1], 10, 32)
|
||||||
|
wangsuCertVer = int32(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +180,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
{
|
{
|
||||||
Action: tea.String("deploy_cert"),
|
Action: tea.String("deploy_cert"),
|
||||||
CertificateId: tea.String(wangsuCertId),
|
CertificateId: tea.String(wangsuCertId),
|
||||||
Version: tea.String(wangsuCertVer),
|
Version: tea.Int32(wangsuCertVer),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -193,7 +196,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
// 循环获取部署任务详细信息,等待任务状态变更
|
// 循环获取部署任务详细信息,等待任务状态变更
|
||||||
// REF: https://www.wangsu.com/document/api-doc/27038
|
// REF: https://www.wangsu.com/document/api-doc/27038
|
||||||
var wangsuTaskId string
|
var wangsuTaskId string
|
||||||
wangsuTaskMatches := regexp.MustCompile(`/deploymentTasks/([a-zA-Z0-9-]+)`).FindStringSubmatch(wangsuCertUrl)
|
wangsuTaskMatches := regexp.MustCompile(`/deploymentTasks/([a-zA-Z0-9-]+)`).FindStringSubmatch(createDeploymentTaskResp.DeploymentTaskUrl)
|
||||||
if len(wangsuTaskMatches) > 1 {
|
if len(wangsuTaskMatches) > 1 {
|
||||||
wangsuTaskId = wangsuTaskMatches[1]
|
wangsuTaskId = wangsuTaskMatches[1]
|
||||||
}
|
}
|
||||||
@ -203,7 +206,7 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPe
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDeploymentTaskDetailResp, err := d.sdkClient.GetDeploymentTaskDetail(wangsuTaskId)
|
getDeploymentTaskDetailResp, err := d.sdkClient.GetDeploymentTaskDetail(wangsuTaskId)
|
||||||
d.logger.Debug("sdk request 'cdn.GetDeploymentTaskDetail'", slog.Any("taskId", wangsuTaskId), slog.Any("response", getDeploymentTaskDetailResp))
|
d.logger.Info("sdk request 'cdn.GetDeploymentTaskDetail'", slog.Any("taskId", wangsuTaskId), slog.Any("response", getDeploymentTaskDetailResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.GetDeploymentTaskDetail'")
|
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.GetDeploymentTaskDetail'")
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_APIKEY="your-api-key" \
|
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_APIKEY="your-api-key" \
|
||||||
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_ENVIRONMENT="production" \
|
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_ENVIRONMENT="production" \
|
||||||
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_DOMAIN="example.com" \
|
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_DOMAIN="example.com" \
|
||||||
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_CERTIFICATEID="your-certificate-id"\
|
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_CERTIFICATEID="your-certificate-id" \
|
||||||
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_WEBHOOKID="your-webhook-id"
|
--CERTIMATE_DEPLOYER_WANGSUCDNPRO_WEBHOOKID="your-webhook-id"
|
||||||
*/
|
*/
|
||||||
func TestDeploy(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
|
12
internal/pkg/vendors/wangsu-sdk/cdn/api.go
vendored
12
internal/pkg/vendors/wangsu-sdk/cdn/api.go
vendored
@ -22,6 +22,10 @@ func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertif
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateCertificate(certificateId string, req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
func (c *Client) UpdateCertificate(certificateId string, req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
||||||
|
if certificateId == "" {
|
||||||
|
return nil, fmt.Errorf("invalid parameter: certificateId")
|
||||||
|
}
|
||||||
|
|
||||||
resp := &UpdateCertificateResponse{}
|
resp := &UpdateCertificateResponse{}
|
||||||
r, err := c.client.SendRequestWithResult(http.MethodPatch, fmt.Sprintf("/cdn/certificates/%s", url.PathEscape(certificateId)), req, resp, func(r *resty.Request) {
|
r, err := c.client.SendRequestWithResult(http.MethodPatch, fmt.Sprintf("/cdn/certificates/%s", url.PathEscape(certificateId)), req, resp, func(r *resty.Request) {
|
||||||
r.SetHeader("x-cnc-timestamp", fmt.Sprintf("%d", req.Timestamp))
|
r.SetHeader("x-cnc-timestamp", fmt.Sprintf("%d", req.Timestamp))
|
||||||
@ -35,6 +39,10 @@ func (c *Client) UpdateCertificate(certificateId string, req *UpdateCertificateR
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetHostnameDetail(hostname string) (*GetHostnameDetailResponse, error) {
|
func (c *Client) GetHostnameDetail(hostname string) (*GetHostnameDetailResponse, error) {
|
||||||
|
if hostname == "" {
|
||||||
|
return nil, fmt.Errorf("invalid parameter: hostname")
|
||||||
|
}
|
||||||
|
|
||||||
resp := &GetHostnameDetailResponse{}
|
resp := &GetHostnameDetailResponse{}
|
||||||
_, err := c.client.SendRequestWithResult(http.MethodGet, fmt.Sprintf("/cdn/hostnames/%s", url.PathEscape(hostname)), nil, resp)
|
_, err := c.client.SendRequestWithResult(http.MethodGet, fmt.Sprintf("/cdn/hostnames/%s", url.PathEscape(hostname)), nil, resp)
|
||||||
return resp, err
|
return resp, err
|
||||||
@ -52,6 +60,10 @@ func (c *Client) CreateDeploymentTask(req *CreateDeploymentTaskRequest) (*Create
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetDeploymentTaskDetail(deploymentTaskId string) (*GetDeploymentTaskDetailResponse, error) {
|
func (c *Client) GetDeploymentTaskDetail(deploymentTaskId string) (*GetDeploymentTaskDetailResponse, error) {
|
||||||
|
if deploymentTaskId == "" {
|
||||||
|
return nil, fmt.Errorf("invalid parameter: deploymentTaskId")
|
||||||
|
}
|
||||||
|
|
||||||
resp := &GetDeploymentTaskDetailResponse{}
|
resp := &GetDeploymentTaskDetailResponse{}
|
||||||
_, err := c.client.SendRequestWithResult(http.MethodGet, fmt.Sprintf("/cdn/deploymentTasks/%s", url.PathEscape(deploymentTaskId)), nil, resp)
|
_, err := c.client.SendRequestWithResult(http.MethodGet, fmt.Sprintf("/cdn/deploymentTasks/%s", url.PathEscape(deploymentTaskId)), nil, resp)
|
||||||
return resp, err
|
return resp, err
|
||||||
|
@ -80,7 +80,7 @@ type DeploymentTaskAction struct {
|
|||||||
Action *string `json:"action,omitempty" required:"true"`
|
Action *string `json:"action,omitempty" required:"true"`
|
||||||
PropertyId *string `json:"propertyId,omitempty"`
|
PropertyId *string `json:"propertyId,omitempty"`
|
||||||
CertificateId *string `json:"certificateId,omitempty"`
|
CertificateId *string `json:"certificateId,omitempty"`
|
||||||
Version *string `json:"version,omitempty"`
|
Version *int32 `json:"version,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateDeploymentTaskRequest struct {
|
type CreateDeploymentTaskRequest struct {
|
||||||
@ -97,7 +97,6 @@ type CreateDeploymentTaskResponse struct {
|
|||||||
|
|
||||||
type GetDeploymentTaskDetailResponse struct {
|
type GetDeploymentTaskDetailResponse struct {
|
||||||
baseResponse
|
baseResponse
|
||||||
Id string `json:"id"`
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Target string `json:"target"`
|
Target string `json:"target"`
|
||||||
Actions []DeploymentTaskAction `json:"actions"`
|
Actions []DeploymentTaskAction `json:"actions"`
|
||||||
|
@ -111,7 +111,7 @@ func NewClient(accessKey, secretKey string) *Client {
|
|||||||
signHex := strings.ToLower(hex.EncodeToString(sign))
|
signHex := strings.ToLower(hex.EncodeToString(sign))
|
||||||
|
|
||||||
// Step 9: Add headers to request
|
// Step 9: Add headers to request
|
||||||
req.Header.Set("x-cnc-accessKey", accessKey)
|
req.Header.Set("x-cnc-accesskey", accessKey)
|
||||||
req.Header.Set("x-cnc-timestamp", timestampString)
|
req.Header.Set("x-cnc-timestamp", timestampString)
|
||||||
req.Header.Set("x-cnc-auth-method", "AKSK")
|
req.Header.Set("x-cnc-auth-method", "AKSK")
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("%s Credential=%s, SignedHeaders=%s, Signature=%s", SignAlgorithmHeader, accessKey, signedHeaders, signHex))
|
req.Header.Set("Authorization", fmt.Sprintf("%s Credential=%s, SignedHeaders=%s, Signature=%s", SignAlgorithmHeader, accessKey, signedHeaders, signHex))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user