mirror of
https://github.com/usual2970/certimate.git
synced 2025-09-06 16:31:45 +00:00
feat: new deployment provider: ctcccloud cdn
This commit is contained in:
41
internal/pkg/sdk3rd/ctyun/cdn/api_create_cert.go
Normal file
41
internal/pkg/sdk3rd/ctyun/cdn/api_create_cert.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CreateCertRequest struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Certs *string `json:"certs,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
}
|
||||
|
||||
type CreateCertResponse struct {
|
||||
baseResult
|
||||
|
||||
ReturnObj *struct {
|
||||
Id int32 `json:"id"`
|
||||
} `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateCert(req *CreateCertRequest) (*CreateCertResponse, error) {
|
||||
return c.CreateCertWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) CreateCertWithContext(ctx context.Context, req *CreateCertRequest) (*CreateCertResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/v1/cert/creat-cert")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &CreateCertResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
51
internal/pkg/sdk3rd/ctyun/cdn/api_query_cert_detail.go
Normal file
51
internal/pkg/sdk3rd/ctyun/cdn/api_query_cert_detail.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type QueryCertDetailRequest struct {
|
||||
Id *int32 `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
UsageMode *int32 `json:"usage_mode,omitempty"`
|
||||
}
|
||||
|
||||
type QueryCertDetailResponse struct {
|
||||
baseResult
|
||||
|
||||
ReturnObj *struct {
|
||||
Result *CertDetail `json:"result,omitempty"`
|
||||
} `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) QueryCertDetail(req *QueryCertDetailRequest) (*QueryCertDetailResponse, error) {
|
||||
return c.QueryCertDetailWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) QueryCertDetailWithContext(ctx context.Context, req *QueryCertDetailRequest) (*QueryCertDetailResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/v1/cert/query-cert-detail")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if req.Id != nil {
|
||||
httpreq.SetQueryParam("id", strconv.Itoa(int(*req.Id)))
|
||||
}
|
||||
if req.Name != nil {
|
||||
httpreq.SetQueryParam("name", *req.Name)
|
||||
}
|
||||
if req.UsageMode != nil {
|
||||
httpreq.SetQueryParam("usage_mode", strconv.Itoa(int(*req.UsageMode)))
|
||||
}
|
||||
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &QueryCertDetailResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
55
internal/pkg/sdk3rd/ctyun/cdn/api_query_cert_list.go
Normal file
55
internal/pkg/sdk3rd/ctyun/cdn/api_query_cert_list.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type QueryCertListRequest struct {
|
||||
Page *int32 `json:"page,omitempty"`
|
||||
PerPage *int32 `json:"per_page,omitempty"`
|
||||
UsageMode *int32 `json:"usage_mode,omitempty"`
|
||||
}
|
||||
|
||||
type QueryCertListResponse struct {
|
||||
baseResult
|
||||
|
||||
ReturnObj *struct {
|
||||
Results []*CertRecord `json:"result,omitempty"`
|
||||
Page int32 `json:"page,omitempty"`
|
||||
PerPage int32 `json:"per_page,omitempty"`
|
||||
TotalPage int32 `json:"total_page,omitempty"`
|
||||
TotalRecords int32 `json:"total_records,omitempty"`
|
||||
} `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) QueryCertList(req *QueryCertListRequest) (*QueryCertListResponse, error) {
|
||||
return c.QueryCertListWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) QueryCertListWithContext(ctx context.Context, req *QueryCertListRequest) (*QueryCertListResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/v1/cert/query-cert-list")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if req.Page != nil {
|
||||
httpreq.SetQueryParam("page", strconv.Itoa(int(*req.Page)))
|
||||
}
|
||||
if req.PerPage != nil {
|
||||
httpreq.SetQueryParam("per_page", strconv.Itoa(int(*req.PerPage)))
|
||||
}
|
||||
if req.UsageMode != nil {
|
||||
httpreq.SetQueryParam("usage_mode", strconv.Itoa(int(*req.UsageMode)))
|
||||
}
|
||||
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &QueryCertListResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
64
internal/pkg/sdk3rd/ctyun/cdn/api_query_domain_detail.go
Normal file
64
internal/pkg/sdk3rd/ctyun/cdn/api_query_domain_detail.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type QueryDomainDetailRequest struct {
|
||||
Domain *string `json:"domain,omitempty"`
|
||||
ProductCode *string `json:"product_code,omitempty"`
|
||||
FunctionNames *string `json:"function_names,omitempty"`
|
||||
}
|
||||
|
||||
type QueryDomainDetailResponse struct {
|
||||
baseResult
|
||||
|
||||
ReturnObj *struct {
|
||||
Domain string `json:"domain"`
|
||||
ProductCode string `json:"product_code"`
|
||||
Status int32 `json:"status"`
|
||||
AreaScope int32 `json:"area_scope"`
|
||||
Cname string `json:"cname"`
|
||||
HttpsStatus string `json:"https_status"`
|
||||
HttpsBasic *struct {
|
||||
HttpsForce string `json:"https_force"`
|
||||
HttpForce string `json:"http_force"`
|
||||
ForceStatus string `json:"force_status"`
|
||||
OriginProtocol string `json:"origin_protocol"`
|
||||
} `json:"https_basic,omitempty"`
|
||||
CertName string `json:"cert_name"`
|
||||
Ssl string `json:"ssl"`
|
||||
SslStapling string `json:"ssl_stapling"`
|
||||
} `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) QueryDomainDetail(req *QueryDomainDetailRequest) (*QueryDomainDetailResponse, error) {
|
||||
return c.QueryDomainDetailWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) QueryDomainDetailWithContext(ctx context.Context, req *QueryDomainDetailRequest) (*QueryDomainDetailResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/v1/domain/query-domain-detail")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if req.Domain != nil {
|
||||
httpreq.SetQueryParam("domain", *req.Domain)
|
||||
}
|
||||
if req.ProductCode != nil {
|
||||
httpreq.SetQueryParam("product_code", *req.ProductCode)
|
||||
}
|
||||
if req.FunctionNames != nil {
|
||||
httpreq.SetQueryParam("function_names", *req.FunctionNames)
|
||||
}
|
||||
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &QueryDomainDetailResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
37
internal/pkg/sdk3rd/ctyun/cdn/api_update_domain.go
Normal file
37
internal/pkg/sdk3rd/ctyun/cdn/api_update_domain.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UpdateDomainRequest struct {
|
||||
Domain *string `json:"domain,omitempty"`
|
||||
HttpsStatus *string `json:"https_status,omitempty"`
|
||||
CertName *string `json:"cert_name,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateDomainResponse struct {
|
||||
baseResult
|
||||
}
|
||||
|
||||
func (c *Client) UpdateDomain(req *UpdateDomainRequest) (*UpdateDomainResponse, error) {
|
||||
return c.UpdateDomainWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateDomainWithContext(ctx context.Context, req *UpdateDomainRequest) (*UpdateDomainResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/v1/domain/update-domain")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateDomainResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
40
internal/pkg/sdk3rd/ctyun/cdn/client.go
Normal file
40
internal/pkg/sdk3rd/ctyun/cdn/client.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/usual2970/certimate/internal/pkg/sdk3rd/ctyun/openapi"
|
||||
)
|
||||
|
||||
const endpoint = "https://ctcdn-global.ctapi.ctyun.cn"
|
||||
|
||||
type Client struct {
|
||||
client *openapi.Client
|
||||
}
|
||||
|
||||
func NewClient(accessKeyId, secretAccessKey string) (*Client, error) {
|
||||
client, err := openapi.NewClient(endpoint, accessKeyId, secretAccessKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{client: client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
return c.client.NewRequest(method, path)
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(request *resty.Request) (*resty.Response, error) {
|
||||
return c.client.DoRequest(request)
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(request *resty.Request, result any) (*resty.Response, error) {
|
||||
return c.client.DoRequestWithResult(request, result)
|
||||
}
|
30
internal/pkg/sdk3rd/ctyun/cdn/types.go
Normal file
30
internal/pkg/sdk3rd/ctyun/cdn/types.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package cdn
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type baseResult struct {
|
||||
StatusCode json.RawMessage `json:"statusCode,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
ErrorMessage *string `json:"errorMessage,omitempty"`
|
||||
RequestId *string `json:"requestId,omitempty"`
|
||||
}
|
||||
|
||||
type CertRecord struct {
|
||||
Id int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CN string `json:"cn"`
|
||||
SANs []string `json:"sans"`
|
||||
UsageMode int32 `json:"usage_mode"`
|
||||
State int32 `json:"state"`
|
||||
ExpiresTime int64 `json:"expires"`
|
||||
IssueTime int64 `json:"issue"`
|
||||
Issuer string `json:"issuer"`
|
||||
CreatedTime int64 `json:"created"`
|
||||
}
|
||||
|
||||
type CertDetail struct {
|
||||
CertRecord
|
||||
Certs string `json:"certs"`
|
||||
Key string `json:"key"`
|
||||
}
|
Reference in New Issue
Block a user