mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-07 21:19:51 +00:00
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package cdn
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/go-resty/resty/v2"
|
|
)
|
|
|
|
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
|
resp := &CreateCertificateResponse{}
|
|
r, err := c.client.SendRequestWithResult(http.MethodPost, "/cdn/certificates", req, resp, func(r *resty.Request) {
|
|
r.SetHeader("x-cnc-timestamp", fmt.Sprintf("%d", req.Timestamp))
|
|
})
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
|
|
resp.CertificateUrl = r.Header().Get("Location")
|
|
return resp, err
|
|
}
|
|
|
|
func (c *Client) UpdateCertificate(certificateId string, req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
|
if certificateId == "" {
|
|
return nil, fmt.Errorf("invalid parameter: certificateId")
|
|
}
|
|
|
|
resp := &UpdateCertificateResponse{}
|
|
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))
|
|
})
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
|
|
resp.CertificateUrl = r.Header().Get("Location")
|
|
return resp, err
|
|
}
|
|
|
|
func (c *Client) GetHostnameDetail(hostname string) (*GetHostnameDetailResponse, error) {
|
|
if hostname == "" {
|
|
return nil, fmt.Errorf("invalid parameter: hostname")
|
|
}
|
|
|
|
resp := &GetHostnameDetailResponse{}
|
|
_, err := c.client.SendRequestWithResult(http.MethodGet, fmt.Sprintf("/cdn/hostnames/%s", url.PathEscape(hostname)), nil, resp)
|
|
return resp, err
|
|
}
|
|
|
|
func (c *Client) CreateDeploymentTask(req *CreateDeploymentTaskRequest) (*CreateDeploymentTaskResponse, error) {
|
|
resp := &CreateDeploymentTaskResponse{}
|
|
r, err := c.client.SendRequestWithResult(http.MethodPost, "/cdn/deploymentTasks", req, resp)
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
|
|
resp.DeploymentTaskUrl = r.Header().Get("Location")
|
|
return resp, err
|
|
}
|
|
|
|
func (c *Client) GetDeploymentTaskDetail(deploymentTaskId string) (*GetDeploymentTaskDetailResponse, error) {
|
|
if deploymentTaskId == "" {
|
|
return nil, fmt.Errorf("invalid parameter: deploymentTaskId")
|
|
}
|
|
|
|
resp := &GetDeploymentTaskDetailResponse{}
|
|
_, err := c.client.SendRequestWithResult(http.MethodGet, fmt.Sprintf("/cdn/deploymentTasks/%s", url.PathEscape(deploymentTaskId)), nil, resp)
|
|
return resp, err
|
|
}
|