mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-19 01:41:55 +08:00
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package cdnpro
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
type UpdateCertificateRequest struct {
|
|
Timestamp int64 `json:"-"`
|
|
Name *string `json:"name,omitempty"`
|
|
Description *string `json:"description,omitempty"`
|
|
AutoRenew *string `json:"autoRenew,omitempty"`
|
|
ForceRenew *bool `json:"forceRenew,omitempty"`
|
|
NewVersion *CertificateVersionInfo `json:"newVersion,omitempty"`
|
|
}
|
|
|
|
type UpdateCertificateResponse struct {
|
|
apiResponseBase
|
|
|
|
CertificateLocation string `json:"location,omitempty"`
|
|
}
|
|
|
|
func (c *Client) UpdateCertificate(certificateId string, req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
|
return c.UpdateCertificateWithContext(context.Background(), certificateId, req)
|
|
}
|
|
|
|
func (c *Client) UpdateCertificateWithContext(ctx context.Context, certificateId string, req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
|
if certificateId == "" {
|
|
return nil, fmt.Errorf("sdkerr: unset certificateId")
|
|
}
|
|
|
|
httpreq, err := c.newRequest(http.MethodPatch, fmt.Sprintf("/cdn/certificates/%s", url.PathEscape(certificateId)))
|
|
if err != nil {
|
|
return nil, err
|
|
} else {
|
|
httpreq.SetBody(req)
|
|
httpreq.SetHeader("X-CNC-Timestamp", fmt.Sprintf("%d", req.Timestamp))
|
|
httpreq.SetContext(ctx)
|
|
}
|
|
|
|
result := &UpdateCertificateResponse{}
|
|
if httpresp, err := c.doRequestWithResult(httpreq, result); err != nil {
|
|
return result, err
|
|
} else {
|
|
result.CertificateLocation = httpresp.Header().Get("Location")
|
|
}
|
|
|
|
return result, nil
|
|
}
|