mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
refactor: clean code
This commit is contained in:
parent
445541c38f
commit
12102ef641
@ -37,7 +37,7 @@ Shell command to run this test:
|
||||
--CERTIMATE_DEPLOYER_QINIUCDN_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_DEPLOYER_QINIUCDN_ACCESSKEY="your-access-key" \
|
||||
--CERTIMATE_DEPLOYER_QINIUCDN_SECRETKEY="your-secret-key" \
|
||||
--CERTIMATE_DEPLOYER_QINIUCDN_DOMAIN="example.com" \
|
||||
--CERTIMATE_DEPLOYER_QINIUCDN_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
|
@ -40,7 +40,7 @@ Shell command to run this test:
|
||||
--CERTIMATE_DEPLOYER_QINIUPILI_ACCESSKEY="your-access-key" \
|
||||
--CERTIMATE_DEPLOYER_QINIUPILI_SECRETKEY="your-secret-key" \
|
||||
--CERTIMATE_DEPLOYER_QINIUPILI_HUB="your-hub-name" \
|
||||
--CERTIMATE_DEPLOYER_QINIUPILI_DOMAIN="example.com" \
|
||||
--CERTIMATE_DEPLOYER_QINIUPILI_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
|
@ -37,7 +37,7 @@ Shell command to run this test:
|
||||
--CERTIMATE_DEPLOYER_UPYUNCDN_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_DEPLOYER_UPYUNCDN_USERNAME="your-username" \
|
||||
--CERTIMATE_DEPLOYER_UPYUNCDN_PASSWORD="your-password" \
|
||||
--CERTIMATE_DEPLOYER_UPYUNCDN_DOMAIN="example.com" \
|
||||
--CERTIMATE_DEPLOYER_UPYUNCDN_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
|
@ -59,9 +59,9 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPem string, privkeyPe
|
||||
PrivateKey: privkeyPem,
|
||||
}
|
||||
uploadHttpsCertificateResp, err := u.sdkClient.UploadHttpsCertificate(uploadHttpsCertificateReq)
|
||||
u.logger.Debug("sdk request 'ssl.UploadHttpsCertificate'", slog.Any("response", uploadHttpsCertificateResp))
|
||||
u.logger.Debug("sdk request 'console.UploadHttpsCertificate'", slog.Any("response", uploadHttpsCertificateResp))
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'ssl.UploadHttpsCertificate'")
|
||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'console.UploadHttpsCertificate'")
|
||||
}
|
||||
|
||||
return &uploader.UploadResult{
|
||||
|
25
internal/pkg/vendors/1panel-sdk/api.go
vendored
25
internal/pkg/vendors/1panel-sdk/api.go
vendored
@ -8,44 +8,29 @@ import (
|
||||
func (c *Client) UpdateSystemSSL(req *UpdateSystemSSLRequest) (*UpdateSystemSSLResponse, error) {
|
||||
resp := &UpdateSystemSSLResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/settings/ssl/update", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SearchWebsiteSSL(req *SearchWebsiteSSLRequest) (*SearchWebsiteSSLResponse, error) {
|
||||
resp := &SearchWebsiteSSLResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/websites/ssl/search", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UploadWebsiteSSL(req *UploadWebsiteSSLRequest) (*UploadWebsiteSSLResponse, error) {
|
||||
resp := &UploadWebsiteSSLResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/websites/ssl/upload", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsConf(req *GetHttpsConfRequest) (*GetHttpsConfResponse, error) {
|
||||
resp := &GetHttpsConfResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, fmt.Sprintf("/websites/%d/https", req.WebsiteID), req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsConf(req *UpdateHttpsConfRequest) (*UpdateHttpsConfResponse, error) {
|
||||
resp := &UpdateHttpsConfResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, fmt.Sprintf("/websites/%d/https", req.WebsiteID), req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
4
internal/pkg/vendors/1panel-sdk/client.go
vendored
4
internal/pkg/vendors/1panel-sdk/client.go
vendored
@ -77,9 +77,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("1panel api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("1panel api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("1panel api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("1panel api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
22
internal/pkg/vendors/1panel-sdk/models.go
vendored
22
internal/pkg/vendors/1panel-sdk/models.go
vendored
@ -6,16 +6,22 @@ type BaseResponse interface {
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Code int32 `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Code *int32 `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetCode() int32 {
|
||||
return r.Code
|
||||
if r.Code != nil {
|
||||
return *r.Code
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMessage() string {
|
||||
return r.Message
|
||||
if r.Message != nil {
|
||||
return *r.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type UpdateSystemSSLRequest struct {
|
||||
@ -38,7 +44,7 @@ type SearchWebsiteSSLRequest struct {
|
||||
|
||||
type SearchWebsiteSSLResponse struct {
|
||||
baseResponse
|
||||
Data struct {
|
||||
Data *struct {
|
||||
Items []*struct {
|
||||
ID int64 `json:"id"`
|
||||
PEM string `json:"pem"`
|
||||
@ -50,7 +56,7 @@ type SearchWebsiteSSLResponse struct {
|
||||
CreatedAt string `json:"createdAt"`
|
||||
} `json:"items"`
|
||||
Total int32 `json:"total"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type UploadWebsiteSSLRequest struct {
|
||||
@ -73,13 +79,13 @@ type GetHttpsConfRequest struct {
|
||||
|
||||
type GetHttpsConfResponse struct {
|
||||
baseResponse
|
||||
Data struct {
|
||||
Data *struct {
|
||||
Enable bool `json:"enable"`
|
||||
HttpConfig string `json:"httpConfig"`
|
||||
SSLProtocol []string `json:"SSLProtocol"`
|
||||
Algorithm string `json:"algorithm"`
|
||||
Hsts bool `json:"hsts"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateHttpsConfRequest struct {
|
||||
|
27
internal/pkg/vendors/baishan-sdk/api.go
vendored
27
internal/pkg/vendors/baishan-sdk/api.go
vendored
@ -5,28 +5,19 @@ import (
|
||||
)
|
||||
|
||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||
resp := CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/certificate", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/certificate", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
||||
resp := GetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/v2/domain/config", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &GetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/v2/domain/config", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SetDomainConfig(req *SetDomainConfigRequest) (*SetDomainConfigResponse, error) {
|
||||
resp := SetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/config", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &SetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/config", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
6
internal/pkg/vendors/baishan-sdk/client.go
vendored
6
internal/pkg/vendors/baishan-sdk/client.go
vendored
@ -63,7 +63,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
req = req.
|
||||
SetQueryParam("token", c.apiToken).
|
||||
SetQueryParamsFromValues(qs).SetDebug(true)
|
||||
SetQueryParamsFromValues(qs)
|
||||
} else {
|
||||
req = req.
|
||||
SetHeader("Content-Type", "application/json").
|
||||
@ -73,9 +73,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("baishan api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("baishan api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("baishan api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("baishan api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
20
internal/pkg/vendors/baishan-sdk/models.go
vendored
20
internal/pkg/vendors/baishan-sdk/models.go
vendored
@ -6,16 +6,22 @@ type BaseResponse interface {
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Code *int `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetCode() int {
|
||||
return r.Code
|
||||
if r.Code != nil {
|
||||
return *r.Code
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMessage() string {
|
||||
return r.Message
|
||||
if r.Message != nil {
|
||||
return *r.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type CreateCertificateRequest struct {
|
||||
@ -26,7 +32,7 @@ type CreateCertificateRequest struct {
|
||||
|
||||
type CreateCertificateResponse struct {
|
||||
baseResponse
|
||||
Data *DomainCertificate `json:"data"`
|
||||
Data *DomainCertificate `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type GetDomainConfigRequest struct {
|
||||
@ -39,7 +45,7 @@ type GetDomainConfigResponse struct {
|
||||
Data []*struct {
|
||||
Domain string `json:"domain"`
|
||||
Config *DomainConfig `json:"config"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type SetDomainConfigRequest struct {
|
||||
@ -51,7 +57,7 @@ type SetDomainConfigResponse struct {
|
||||
baseResponse
|
||||
Data *struct {
|
||||
Config *DomainConfig `json:"config"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type DomainCertificate struct {
|
||||
|
45
internal/pkg/vendors/btpanel-sdk/api.go
vendored
45
internal/pkg/vendors/btpanel-sdk/api.go
vendored
@ -1,46 +1,31 @@
|
||||
package btpanelsdk
|
||||
|
||||
func (c *Client) ConfigSavePanelSSL(req *ConfigSavePanelSSLRequest) (*ConfigSavePanelSSLResponse, error) {
|
||||
resp := ConfigSavePanelSSLResponse{}
|
||||
err := c.sendRequestWithResult("/config?action=SavePanelSSL", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &ConfigSavePanelSSLResponse{}
|
||||
err := c.sendRequestWithResult("/config?action=SavePanelSSL", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SiteSetSSL(req *SiteSetSSLRequest) (*SiteSetSSLResponse, error) {
|
||||
resp := SiteSetSSLResponse{}
|
||||
err := c.sendRequestWithResult("/site?action=SetSSL", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &SiteSetSSLResponse{}
|
||||
err := c.sendRequestWithResult("/site?action=SetSSL", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SystemServiceAdmin(req *SystemServiceAdminRequest) (*SystemServiceAdminResponse, error) {
|
||||
resp := SystemServiceAdminResponse{}
|
||||
err := c.sendRequestWithResult("/system?action=ServiceAdmin", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &SystemServiceAdminResponse{}
|
||||
err := c.sendRequestWithResult("/system?action=ServiceAdmin", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SSLCertSaveCert(req *SSLCertSaveCertRequest) (*SSLCertSaveCertResponse, error) {
|
||||
resp := SSLCertSaveCertResponse{}
|
||||
err := c.sendRequestWithResult("/ssl/cert/save_cert", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &SSLCertSaveCertResponse{}
|
||||
err := c.sendRequestWithResult("/ssl/cert/save_cert", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SSLSetBatchCertToSite(req *SSLSetBatchCertToSiteRequest) (*SSLSetBatchCertToSiteResponse, error) {
|
||||
resp := SSLSetBatchCertToSiteResponse{}
|
||||
err := c.sendRequestWithResult("/ssl?action=SetBatchCertToSite", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &SSLSetBatchCertToSiteResponse{}
|
||||
err := c.sendRequestWithResult("/ssl?action=SetBatchCertToSite", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
4
internal/pkg/vendors/btpanel-sdk/client.go
vendored
4
internal/pkg/vendors/btpanel-sdk/client.go
vendored
@ -84,9 +84,9 @@ func (c *Client) sendRequest(path string, params interface{}) (*resty.Response,
|
||||
SetFormData(data)
|
||||
resp, err := req.Post(url)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("baota api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("baota api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("baota api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("baota api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
9
internal/pkg/vendors/cachefly-sdk/api.go
vendored
9
internal/pkg/vendors/cachefly-sdk/api.go
vendored
@ -5,10 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||
resp := CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/certificates", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/certificates", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
4
internal/pkg/vendors/cachefly-sdk/client.go
vendored
4
internal/pkg/vendors/cachefly-sdk/client.go
vendored
@ -57,9 +57,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cachefly api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("cachefly api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("cachefly api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("cachefly api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
9
internal/pkg/vendors/cachefly-sdk/models.go
vendored
9
internal/pkg/vendors/cachefly-sdk/models.go
vendored
@ -1,15 +1,18 @@
|
||||
package cacheflysdk
|
||||
|
||||
type BaseResponse interface {
|
||||
GetMessage() *string
|
||||
GetMessage() string
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMessage() *string {
|
||||
return r.Message
|
||||
func (r *baseResponse) GetMessage() string {
|
||||
if r.Message != nil {
|
||||
return *r.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type CreateCertificateRequest struct {
|
||||
|
36
internal/pkg/vendors/cdnfly-sdk/api.go
vendored
36
internal/pkg/vendors/cdnfly-sdk/api.go
vendored
@ -6,37 +6,25 @@ import (
|
||||
)
|
||||
|
||||
func (c *Client) GetSite(req *GetSiteRequest) (*GetSiteResponse, error) {
|
||||
resp := GetSiteResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, fmt.Sprintf("/v1/sites/%s", req.Id), req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &GetSiteResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, fmt.Sprintf("/v1/sites/%s", req.Id), req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateSite(req *UpdateSiteRequest) (*UpdateSiteResponse, error) {
|
||||
resp := UpdateSiteResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/sites/%s", req.Id), req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UpdateSiteResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/sites/%s", req.Id), req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||
resp := CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v1/certs", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v1/certs", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
||||
resp := UpdateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/certs/%s", req.Id), req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UpdateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/certs/%s", req.Id), req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
4
internal/pkg/vendors/cdnfly-sdk/client.go
vendored
4
internal/pkg/vendors/cdnfly-sdk/client.go
vendored
@ -63,9 +63,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cdnfly api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("cdnfly api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("cdnfly api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("cdnfly api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
2
internal/pkg/vendors/cdnfly-sdk/models.go
vendored
2
internal/pkg/vendors/cdnfly-sdk/models.go
vendored
@ -31,7 +31,7 @@ type GetSiteResponse struct {
|
||||
Name string `json:"name"`
|
||||
Domain string `json:"domain"`
|
||||
HttpsListen string `json:"https_listen"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateSiteRequest struct {
|
||||
|
45
internal/pkg/vendors/dnsla-sdk/api.go
vendored
45
internal/pkg/vendors/dnsla-sdk/api.go
vendored
@ -7,46 +7,31 @@ import (
|
||||
)
|
||||
|
||||
func (c *Client) ListDomains(req *ListDomainsRequest) (*ListDomainsResponse, error) {
|
||||
resp := ListDomainsResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/domainList", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &ListDomainsResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/domainList", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) ListRecords(req *ListRecordsRequest) (*ListRecordsResponse, error) {
|
||||
resp := ListRecordsResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/recordList", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &ListRecordsResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/recordList", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateRecord(req *CreateRecordRequest) (*CreateRecordResponse, error) {
|
||||
resp := CreateRecordResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/record", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &CreateRecordResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/record", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateRecord(req *UpdateRecordRequest) (*UpdateRecordResponse, error) {
|
||||
resp := UpdateRecordResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPut, "/record", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UpdateRecordResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPut, "/record", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteRecord(req *DeleteRecordRequest) (*DeleteRecordResponse, error) {
|
||||
resp := DeleteRecordResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodDelete, fmt.Sprintf("/record?id=%s", url.QueryEscape(req.Id)), req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &DeleteRecordResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodDelete, fmt.Sprintf("/record?id=%s", url.QueryEscape(req.Id)), req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
4
internal/pkg/vendors/dnsla-sdk/client.go
vendored
4
internal/pkg/vendors/dnsla-sdk/client.go
vendored
@ -58,9 +58,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dnsla api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("dnsla api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("dnsla api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("dnsla api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
14
internal/pkg/vendors/dnsla-sdk/models.go
vendored
14
internal/pkg/vendors/dnsla-sdk/models.go
vendored
@ -6,16 +6,22 @@ type BaseResponse interface {
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Code *int `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetCode() int {
|
||||
return r.Code
|
||||
if r.Code != nil {
|
||||
return *r.Code
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMessage() string {
|
||||
return r.Message
|
||||
if r.Message != nil {
|
||||
return *r.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type DomainInfo struct {
|
||||
|
36
internal/pkg/vendors/gname-sdk/api.go
vendored
36
internal/pkg/vendors/gname-sdk/api.go
vendored
@ -1,37 +1,25 @@
|
||||
package gnamesdk
|
||||
|
||||
func (c *Client) AddDomainResolution(req *AddDomainResolutionRequest) (*AddDomainResolutionResponse, error) {
|
||||
result := AddDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/add", req, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
resp := &AddDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/add", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) ModifyDomainResolution(req *ModifyDomainResolutionRequest) (*ModifyDomainResolutionResponse, error) {
|
||||
resp := ModifyDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/edit", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &ModifyDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/edit", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteDomainResolution(req *DeleteDomainResolutionRequest) (*DeleteDomainResolutionResponse, error) {
|
||||
resp := DeleteDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/delete", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &DeleteDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/delete", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) ListDomainResolution(req *ListDomainResolutionRequest) (*ListDomainResolutionResponse, error) {
|
||||
resp := ListDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/list", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &ListDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/list", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
4
internal/pkg/vendors/gname-sdk/client.go
vendored
4
internal/pkg/vendors/gname-sdk/client.go
vendored
@ -80,9 +80,9 @@ func (c *Client) sendRequest(path string, params interface{}) (*resty.Response,
|
||||
SetFormData(data)
|
||||
resp, err := req.Post(url)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gname api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("gname api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("gname api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("gname api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
9
internal/pkg/vendors/safeline-sdk/api.go
vendored
9
internal/pkg/vendors/safeline-sdk/api.go
vendored
@ -1,10 +1,7 @@
|
||||
package safelinesdk
|
||||
|
||||
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
||||
resp := UpdateCertificateResponse{}
|
||||
err := c.sendRequestWithResult("/api/open/cert", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UpdateCertificateResponse{}
|
||||
err := c.sendRequestWithResult("/api/open/cert", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
4
internal/pkg/vendors/safeline-sdk/client.go
vendored
4
internal/pkg/vendors/safeline-sdk/client.go
vendored
@ -45,9 +45,9 @@ func (c *Client) sendRequest(path string, params interface{}) (*resty.Response,
|
||||
SetBody(params)
|
||||
resp, err := req.Post(url)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("safeline api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("safeline api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("safeline api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("safeline api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
49
internal/pkg/vendors/upyun-sdk/console/api.go
vendored
49
internal/pkg/vendors/upyun-sdk/console/api.go
vendored
@ -33,12 +33,9 @@ func (c *Client) UploadHttpsCertificate(req *UploadHttpsCertificateRequest) (*Up
|
||||
}
|
||||
}
|
||||
|
||||
resp := UploadHttpsCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UploadHttpsCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsCertificateManager(certificateId string) (*GetHttpsCertificateManagerResponse, error) {
|
||||
@ -48,13 +45,10 @@ func (c *Client) GetHttpsCertificateManager(certificateId string) (*GetHttpsCert
|
||||
}
|
||||
}
|
||||
|
||||
req := GetHttpsCertificateManagerRequest{CertificateId: certificateId}
|
||||
resp := GetHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/certificate/manager/", &req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
req := &GetHttpsCertificateManagerRequest{CertificateId: certificateId}
|
||||
resp := &GetHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/certificate/manager/", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsCertificateManager(req *UpdateHttpsCertificateManagerRequest) (*UpdateHttpsCertificateManagerResponse, error) {
|
||||
@ -64,12 +58,9 @@ func (c *Client) UpdateHttpsCertificateManager(req *UpdateHttpsCertificateManage
|
||||
}
|
||||
}
|
||||
|
||||
resp := UpdateHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/manager", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UpdateHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/manager", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsServiceManager(domain string) (*GetHttpsServiceManagerResponse, error) {
|
||||
@ -79,13 +70,10 @@ func (c *Client) GetHttpsServiceManager(domain string) (*GetHttpsServiceManagerR
|
||||
}
|
||||
}
|
||||
|
||||
req := GetHttpsServiceManagerRequest{Domain: domain}
|
||||
resp := GetHttpsServiceManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/services/manager", &req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
req := &GetHttpsServiceManagerRequest{Domain: domain}
|
||||
resp := &GetHttpsServiceManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/services/manager", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) MigrateHttpsDomain(req *MigrateHttpsDomainRequest) (*MigrateHttpsDomainResponse, error) {
|
||||
@ -95,10 +83,7 @@ func (c *Client) MigrateHttpsDomain(req *MigrateHttpsDomainRequest) (*MigrateHtt
|
||||
}
|
||||
}
|
||||
|
||||
resp := MigrateHttpsDomainResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/migrate/domain", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &MigrateHttpsDomainResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/migrate/domain", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
@ -60,12 +60,11 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
SetBody(params)
|
||||
}
|
||||
|
||||
req = req.SetDebug(true)
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("upyun api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("upyun api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("upyun api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("upyun api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
14
internal/pkg/vendors/upyun-sdk/console/models.go
vendored
14
internal/pkg/vendors/upyun-sdk/console/models.go
vendored
@ -41,10 +41,10 @@ type signinRequest struct {
|
||||
|
||||
type signinResponse struct {
|
||||
baseResponse
|
||||
Data struct {
|
||||
Data *struct {
|
||||
baseResponseData
|
||||
Result bool `json:"result"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type UploadHttpsCertificateRequest struct {
|
||||
@ -62,7 +62,7 @@ type UploadHttpsCertificateResponse struct {
|
||||
CommonName string `json:"commonName"`
|
||||
Serial string `json:"serial"`
|
||||
} `json:"result"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type GetHttpsCertificateManagerRequest struct {
|
||||
@ -76,7 +76,7 @@ type GetHttpsCertificateManagerResponse struct {
|
||||
AuthenticateNum int32 `json:"authenticate_num"`
|
||||
AuthenticateDomains []string `json:"authenticate_domain"`
|
||||
Domains []HttpsCertificateManagerDomain `json:"domains"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type HttpsCertificateManagerDomain struct {
|
||||
@ -98,7 +98,7 @@ type UpdateHttpsCertificateManagerResponse struct {
|
||||
Data *struct {
|
||||
baseResponseData
|
||||
Status bool `json:"status"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type GetHttpsServiceManagerRequest struct {
|
||||
@ -111,7 +111,7 @@ type GetHttpsServiceManagerResponse struct {
|
||||
baseResponseData
|
||||
Status int `json:"status"`
|
||||
Domains []HttpsServiceManagerDomain `json:"result"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type HttpsServiceManagerDomain struct {
|
||||
@ -137,5 +137,5 @@ type MigrateHttpsDomainResponse struct {
|
||||
Data *struct {
|
||||
baseResponseData
|
||||
Status bool `json:"status"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user