mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 05:29:51 +00:00
refactor: reimpl 3rd sdks
This commit is contained in:
parent
688a013d73
commit
469c24751e
@ -34,6 +34,7 @@ const (
|
|||||||
AccessProviderTypeGoDaddy = AccessProviderType("godaddy")
|
AccessProviderTypeGoDaddy = AccessProviderType("godaddy")
|
||||||
AccessProviderTypeGoEdge = AccessProviderType("goedge") // GoEdge(预留)
|
AccessProviderTypeGoEdge = AccessProviderType("goedge") // GoEdge(预留)
|
||||||
AccessProviderTypeHuaweiCloud = AccessProviderType("huaweicloud")
|
AccessProviderTypeHuaweiCloud = AccessProviderType("huaweicloud")
|
||||||
|
AccessProviderTypeJDCloud = AccessProviderType("jdcloud") // 京东云(预留)
|
||||||
AccessProviderTypeKubernetes = AccessProviderType("k8s")
|
AccessProviderTypeKubernetes = AccessProviderType("k8s")
|
||||||
AccessProviderTypeLocal = AccessProviderType("local")
|
AccessProviderTypeLocal = AccessProviderType("local")
|
||||||
AccessProviderTypeNameDotCom = AccessProviderType("namedotcom")
|
AccessProviderTypeNameDotCom = AccessProviderType("namedotcom")
|
||||||
@ -41,6 +42,7 @@ const (
|
|||||||
AccessProviderTypeNS1 = AccessProviderType("ns1")
|
AccessProviderTypeNS1 = AccessProviderType("ns1")
|
||||||
AccessProviderTypePowerDNS = AccessProviderType("powerdns")
|
AccessProviderTypePowerDNS = AccessProviderType("powerdns")
|
||||||
AccessProviderTypeQiniu = AccessProviderType("qiniu")
|
AccessProviderTypeQiniu = AccessProviderType("qiniu")
|
||||||
|
AccessProviderTypeQingCloud = AccessProviderType("qingcloud") // 青云(预留)
|
||||||
AccessProviderTypeRainYun = AccessProviderType("rainyun")
|
AccessProviderTypeRainYun = AccessProviderType("rainyun")
|
||||||
AccessProviderTypeSafeLine = AccessProviderType("safeline")
|
AccessProviderTypeSafeLine = AccessProviderType("safeline")
|
||||||
AccessProviderTypeSSH = AccessProviderType("ssh")
|
AccessProviderTypeSSH = AccessProviderType("ssh")
|
||||||
|
@ -57,9 +57,11 @@ func TestDeploy(t *testing.T) {
|
|||||||
}, "\n"))
|
}, "\n"))
|
||||||
|
|
||||||
deployer, err := provider.NewDeployer(&provider.DeployerConfig{
|
deployer, err := provider.NewDeployer(&provider.DeployerConfig{
|
||||||
ApiUrl: fApiUrl,
|
ApiUrl: fApiUrl,
|
||||||
ApiKey: fApiKey,
|
ApiKey: fApiKey,
|
||||||
SiteName: fSiteName,
|
SiteType: fSiteType,
|
||||||
|
SiteName: fSiteName,
|
||||||
|
SiteNames: []string{fSiteName},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err: %+v", err)
|
t.Errorf("err: %+v", err)
|
||||||
|
31
internal/pkg/vendors/baishan-sdk/api.go
vendored
31
internal/pkg/vendors/baishan-sdk/api.go
vendored
@ -1,45 +1,32 @@
|
|||||||
package baishansdk
|
package baishansdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := CreateCertificateResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/certificate", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := CreateCertificateResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/certificate", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := GetDomainConfigResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodGet, "/v2/domain/config", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := GetDomainConfigResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodGet, "/v2/domain/config", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SetDomainConfig(req *SetDomainConfigRequest) (*SetDomainConfigResponse, error) {
|
func (c *Client) SetDomainConfig(req *SetDomainConfigRequest) (*SetDomainConfigResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := SetDomainConfigResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/config", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := SetDomainConfigResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/config", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
18
internal/pkg/vendors/baishan-sdk/client.go
vendored
18
internal/pkg/vendors/baishan-sdk/client.go
vendored
@ -29,17 +29,23 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequest(method string, path string, params map[string]any) (*resty.Response, error) {
|
func (c *Client) sendRequest(method string, path string, params interface{}) (*resty.Response, error) {
|
||||||
req := c.client.R()
|
req := c.client.R()
|
||||||
req.Method = method
|
req.Method = method
|
||||||
req.URL = "https://cdn.api.baishan.com" + path
|
req.URL = "https://cdn.api.baishan.com" + path
|
||||||
if strings.EqualFold(method, http.MethodGet) {
|
if strings.EqualFold(method, http.MethodGet) {
|
||||||
data := make(map[string]string)
|
qs := make(map[string]string)
|
||||||
for k, v := range params {
|
if params != nil {
|
||||||
data[k] = fmt.Sprintf("%v", v)
|
temp := make(map[string]any)
|
||||||
|
jsonData, _ := json.Marshal(params)
|
||||||
|
json.Unmarshal(jsonData, &temp)
|
||||||
|
for k, v := range temp {
|
||||||
|
qs[k] = fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req = req.
|
req = req.
|
||||||
SetQueryParams(data).
|
SetQueryParams(qs).
|
||||||
SetQueryParam("token", c.apiToken)
|
SetQueryParam("token", c.apiToken)
|
||||||
} else {
|
} else {
|
||||||
req = req.
|
req = req.
|
||||||
@ -58,7 +64,7 @@ func (c *Client) sendRequest(method string, path string, params map[string]any)
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequestWithResult(method string, path string, params map[string]any, result BaseResponse) error {
|
func (c *Client) sendRequestWithResult(method string, path string, params interface{}, result BaseResponse) error {
|
||||||
resp, err := c.sendRequest(method, path, params)
|
resp, err := c.sendRequest(method, path, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
54
internal/pkg/vendors/btpanel-sdk/api.go
vendored
54
internal/pkg/vendors/btpanel-sdk/api.go
vendored
@ -1,70 +1,46 @@
|
|||||||
package btpanelsdk
|
package btpanelsdk
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *Client) ConfigSavePanelSSL(req *ConfigSavePanelSSLRequest) (*ConfigSavePanelSSLResponse, error) {
|
func (c *Client) ConfigSavePanelSSL(req *ConfigSavePanelSSLRequest) (*ConfigSavePanelSSLResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := ConfigSavePanelSSLResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/config?action=SavePanelSSL", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := ConfigSavePanelSSLResponse{}
|
|
||||||
err := c.sendRequestWithResult("/config?action=SavePanelSSL", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SiteSetSSL(req *SiteSetSSLRequest) (*SiteSetSSLResponse, error) {
|
func (c *Client) SiteSetSSL(req *SiteSetSSLRequest) (*SiteSetSSLResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := SiteSetSSLResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/site?action=SetSSL", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := SiteSetSSLResponse{}
|
|
||||||
err := c.sendRequestWithResult("/site?action=SetSSL", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SystemServiceAdmin(req *SystemServiceAdminRequest) (*SystemServiceAdminResponse, error) {
|
func (c *Client) SystemServiceAdmin(req *SystemServiceAdminRequest) (*SystemServiceAdminResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := SystemServiceAdminResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/system?action=ServiceAdmin", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := SystemServiceAdminResponse{}
|
|
||||||
err := c.sendRequestWithResult("/system?action=ServiceAdmin", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SSLCertSaveCert(req *SSLCertSaveCertRequest) (*SSLCertSaveCertResponse, error) {
|
func (c *Client) SSLCertSaveCert(req *SSLCertSaveCertRequest) (*SSLCertSaveCertResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := SSLCertSaveCertResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/ssl/cert/save_cert", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := SSLCertSaveCertResponse{}
|
|
||||||
err := c.sendRequestWithResult("/ssl/cert/save_cert", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SSLSetBatchCertToSite(req *SSLSetBatchCertToSiteRequest) (*SSLSetBatchCertToSiteResponse, error) {
|
func (c *Client) SSLSetBatchCertToSite(req *SSLSetBatchCertToSiteRequest) (*SSLSetBatchCertToSiteResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := SSLSetBatchCertToSiteResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/ssl?action=SetBatchCertToSite", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := SSLSetBatchCertToSiteResponse{}
|
|
||||||
err := c.sendRequestWithResult("/ssl?action=SetBatchCertToSite", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
24
internal/pkg/vendors/btpanel-sdk/client.go
vendored
24
internal/pkg/vendors/btpanel-sdk/client.go
vendored
@ -42,19 +42,25 @@ func (c *Client) generateSignature(timestamp string) string {
|
|||||||
return signMd5Hex
|
return signMd5Hex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequest(path string, params map[string]any) (*resty.Response, error) {
|
func (c *Client) sendRequest(path string, params interface{}) (*resty.Response, error) {
|
||||||
if params == nil {
|
|
||||||
params = make(map[string]any)
|
|
||||||
}
|
|
||||||
|
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
params["request_time"] = timestamp
|
|
||||||
params["request_token"] = c.generateSignature(fmt.Sprintf("%d", timestamp))
|
data := make(map[string]any)
|
||||||
|
if params != nil {
|
||||||
|
temp := make(map[string]any)
|
||||||
|
jsonData, _ := json.Marshal(params)
|
||||||
|
json.Unmarshal(jsonData, &temp)
|
||||||
|
for k, v := range temp {
|
||||||
|
data[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data["request_time"] = timestamp
|
||||||
|
data["request_token"] = c.generateSignature(fmt.Sprintf("%d", timestamp))
|
||||||
|
|
||||||
url := c.apiHost + path
|
url := c.apiHost + path
|
||||||
req := c.client.R().
|
req := c.client.R().
|
||||||
SetHeader("Content-Type", "application/json").
|
SetHeader("Content-Type", "application/json").
|
||||||
SetBody(params)
|
SetBody(data)
|
||||||
resp, err := req.Post(url)
|
resp, err := req.Post(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("baota api error: failed to send request: %w", err)
|
return nil, fmt.Errorf("baota api error: failed to send request: %w", err)
|
||||||
@ -65,7 +71,7 @@ func (c *Client) sendRequest(path string, params map[string]any) (*resty.Respons
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
|
func (c *Client) sendRequestWithResult(path string, params interface{}, result BaseResponse) error {
|
||||||
resp, err := c.sendRequest(path, params)
|
resp, err := c.sendRequest(path, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
11
internal/pkg/vendors/cachefly-sdk/api.go
vendored
11
internal/pkg/vendors/cachefly-sdk/api.go
vendored
@ -1,19 +1,14 @@
|
|||||||
package cacheflysdk
|
package cacheflysdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := CreateCertificateResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodPost, "/certificates", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := CreateCertificateResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodPost, "/certificates", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
18
internal/pkg/vendors/cachefly-sdk/client.go
vendored
18
internal/pkg/vendors/cachefly-sdk/client.go
vendored
@ -29,17 +29,23 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequest(method string, path string, params map[string]any) (*resty.Response, error) {
|
func (c *Client) sendRequest(method string, path string, params interface{}) (*resty.Response, error) {
|
||||||
req := c.client.R()
|
req := c.client.R()
|
||||||
req.Method = method
|
req.Method = method
|
||||||
req.URL = "https://api.cachefly.com/api/2.5" + path
|
req.URL = "https://api.cachefly.com/api/2.5" + path
|
||||||
req = req.SetHeader("x-cf-authorization", "Bearer "+c.apiToken)
|
req = req.SetHeader("x-cf-authorization", "Bearer "+c.apiToken)
|
||||||
if strings.EqualFold(method, http.MethodGet) {
|
if strings.EqualFold(method, http.MethodGet) {
|
||||||
data := make(map[string]string)
|
qs := make(map[string]string)
|
||||||
for k, v := range params {
|
if params != nil {
|
||||||
data[k] = fmt.Sprintf("%v", v)
|
temp := make(map[string]any)
|
||||||
|
jsonData, _ := json.Marshal(params)
|
||||||
|
json.Unmarshal(jsonData, &temp)
|
||||||
|
for k, v := range temp {
|
||||||
|
qs[k] = fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
req = req.SetQueryParams(data)
|
|
||||||
|
req = req.SetQueryParams(qs)
|
||||||
} else {
|
} else {
|
||||||
req = req.
|
req = req.
|
||||||
SetHeader("Content-Type", "application/json").
|
SetHeader("Content-Type", "application/json").
|
||||||
@ -56,7 +62,7 @@ func (c *Client) sendRequest(method string, path string, params map[string]any)
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequestWithResult(method string, path string, params map[string]any, result BaseResponse) error {
|
func (c *Client) sendRequestWithResult(method string, path string, params interface{}, result BaseResponse) error {
|
||||||
resp, err := c.sendRequest(method, path, params)
|
resp, err := c.sendRequest(method, path, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
41
internal/pkg/vendors/cdnfly-sdk/api.go
vendored
41
internal/pkg/vendors/cdnfly-sdk/api.go
vendored
@ -1,59 +1,42 @@
|
|||||||
package cdnflysdk
|
package cdnflysdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) GetSite(req *GetSiteRequest) (*GetSiteResponse, error) {
|
func (c *Client) GetSite(req *GetSiteRequest) (*GetSiteResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := GetSiteResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodGet, fmt.Sprintf("/v1/sites/%s", req.Id), req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := GetSiteResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodGet, fmt.Sprintf("/v1/sites/%s", req.Id), params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateSite(req *UpdateSiteRequest) (*UpdateSiteResponse, error) {
|
func (c *Client) UpdateSite(req *UpdateSiteRequest) (*UpdateSiteResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := UpdateSiteResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/sites/%s", req.Id), req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := UpdateSiteResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/sites/%s", req.Id), params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := CreateCertificateResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodPost, "/v1/certs", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := CreateCertificateResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodPost, "/v1/certs", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := UpdateCertificateResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/certs/%s", req.Id), req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := UpdateCertificateResponse{}
|
|
||||||
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/certs/%s", req.Id), params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
18
internal/pkg/vendors/cdnfly-sdk/client.go
vendored
18
internal/pkg/vendors/cdnfly-sdk/client.go
vendored
@ -34,7 +34,7 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequest(method string, path string, params map[string]any) (*resty.Response, error) {
|
func (c *Client) sendRequest(method string, path string, params interface{}) (*resty.Response, error) {
|
||||||
req := c.client.R()
|
req := c.client.R()
|
||||||
req.Method = method
|
req.Method = method
|
||||||
req.URL = c.apiHost + path
|
req.URL = c.apiHost + path
|
||||||
@ -42,11 +42,17 @@ func (c *Client) sendRequest(method string, path string, params map[string]any)
|
|||||||
SetHeader("api-key", c.apiKey).
|
SetHeader("api-key", c.apiKey).
|
||||||
SetHeader("api-secret", c.apiSecret)
|
SetHeader("api-secret", c.apiSecret)
|
||||||
if strings.EqualFold(method, http.MethodGet) {
|
if strings.EqualFold(method, http.MethodGet) {
|
||||||
data := make(map[string]string)
|
qs := make(map[string]string)
|
||||||
for k, v := range params {
|
if params != nil {
|
||||||
data[k] = fmt.Sprintf("%v", v)
|
temp := make(map[string]any)
|
||||||
|
jsonData, _ := json.Marshal(params)
|
||||||
|
json.Unmarshal(jsonData, &temp)
|
||||||
|
for k, v := range temp {
|
||||||
|
qs[k] = fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
req = req.SetQueryParams(data)
|
|
||||||
|
req = req.SetQueryParams(qs)
|
||||||
} else {
|
} else {
|
||||||
req = req.
|
req = req.
|
||||||
SetHeader("Content-Type", "application/json").
|
SetHeader("Content-Type", "application/json").
|
||||||
@ -63,7 +69,7 @@ func (c *Client) sendRequest(method string, path string, params map[string]any)
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequestWithResult(method string, path string, params map[string]any, result BaseResponse) error {
|
func (c *Client) sendRequestWithResult(method string, path string, params interface{}, result BaseResponse) error {
|
||||||
resp, err := c.sendRequest(method, path, params)
|
resp, err := c.sendRequest(method, path, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
40
internal/pkg/vendors/gname-sdk/api.go
vendored
40
internal/pkg/vendors/gname-sdk/api.go
vendored
@ -1,16 +1,8 @@
|
|||||||
package gnamesdk
|
package gnamesdk
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *Client) AddDomainResolution(req *AddDomainResolutionRequest) (*AddDomainResolutionResponse, error) {
|
func (c *Client) AddDomainResolution(req *AddDomainResolutionRequest) (*AddDomainResolutionResponse, error) {
|
||||||
params := make(map[string]any)
|
|
||||||
jsonData, _ := json.Marshal(req)
|
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := AddDomainResolutionResponse{}
|
result := AddDomainResolutionResponse{}
|
||||||
err := c.sendRequestWithResult("/api/resolution/add", params, &result)
|
err := c.sendRequestWithResult("/api/resolution/add", req, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -18,40 +10,28 @@ func (c *Client) AddDomainResolution(req *AddDomainResolutionRequest) (*AddDomai
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ModifyDomainResolution(req *ModifyDomainResolutionRequest) (*ModifyDomainResolutionResponse, error) {
|
func (c *Client) ModifyDomainResolution(req *ModifyDomainResolutionRequest) (*ModifyDomainResolutionResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := ModifyDomainResolutionResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/api/resolution/edit", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := ModifyDomainResolutionResponse{}
|
|
||||||
err := c.sendRequestWithResult("/api/resolution/edit", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) DeleteDomainResolution(req *DeleteDomainResolutionRequest) (*DeleteDomainResolutionResponse, error) {
|
func (c *Client) DeleteDomainResolution(req *DeleteDomainResolutionRequest) (*DeleteDomainResolutionResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := DeleteDomainResolutionResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/api/resolution/delete", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := DeleteDomainResolutionResponse{}
|
|
||||||
err := c.sendRequestWithResult("/api/resolution/delete", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ListDomainResolution(req *ListDomainResolutionRequest) (*ListDomainResolutionResponse, error) {
|
func (c *Client) ListDomainResolution(req *ListDomainResolutionRequest) (*ListDomainResolutionResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := ListDomainResolutionResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/api/resolution/list", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := ListDomainResolutionResponse{}
|
|
||||||
err := c.sendRequestWithResult("/api/resolution/list", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
19
internal/pkg/vendors/gname-sdk/client.go
vendored
19
internal/pkg/vendors/gname-sdk/client.go
vendored
@ -58,14 +58,15 @@ func (c *Client) generateSignature(params map[string]string) string {
|
|||||||
return strings.ToUpper(fmt.Sprintf("%x", hash))
|
return strings.ToUpper(fmt.Sprintf("%x", hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequest(path string, params map[string]any) (*resty.Response, error) {
|
func (c *Client) sendRequest(path string, params interface{}) (*resty.Response, error) {
|
||||||
if params == nil {
|
|
||||||
params = make(map[string]any)
|
|
||||||
}
|
|
||||||
|
|
||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
for k, v := range params {
|
if params != nil {
|
||||||
data[k] = fmt.Sprintf("%v", v)
|
temp := make(map[string]any)
|
||||||
|
jsonData, _ := json.Marshal(params)
|
||||||
|
json.Unmarshal(jsonData, &temp)
|
||||||
|
for k, v := range temp {
|
||||||
|
data[k] = fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data["appid"] = c.appId
|
data["appid"] = c.appId
|
||||||
data["gntime"] = fmt.Sprintf("%d", time.Now().Unix())
|
data["gntime"] = fmt.Sprintf("%d", time.Now().Unix())
|
||||||
@ -85,7 +86,7 @@ func (c *Client) sendRequest(path string, params map[string]any) (*resty.Respons
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
|
func (c *Client) sendRequestWithResult(path string, params interface{}, result BaseResponse) error {
|
||||||
resp, err := c.sendRequest(path, params)
|
resp, err := c.sendRequest(path, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -94,7 +95,7 @@ func (c *Client) sendRequestWithResult(path string, params map[string]any, resul
|
|||||||
if err := json.Unmarshal(resp.Body(), &result); err != nil {
|
if err := json.Unmarshal(resp.Body(), &result); err != nil {
|
||||||
return fmt.Errorf("gname api error: failed to parse response: %w", err)
|
return fmt.Errorf("gname api error: failed to parse response: %w", err)
|
||||||
} else if errcode := result.GetCode(); errcode != 1 {
|
} else if errcode := result.GetCode(); errcode != 1 {
|
||||||
return fmt.Errorf("gname api error: %d - %s", errcode, result.GetMsg())
|
return fmt.Errorf("gname api error: %d - %s", errcode, result.GetMessage())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
10
internal/pkg/vendors/gname-sdk/models.go
vendored
10
internal/pkg/vendors/gname-sdk/models.go
vendored
@ -2,20 +2,20 @@ package gnamesdk
|
|||||||
|
|
||||||
type BaseResponse interface {
|
type BaseResponse interface {
|
||||||
GetCode() int
|
GetCode() int
|
||||||
GetMsg() string
|
GetMessage() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type baseResponse struct {
|
type baseResponse struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *baseResponse) GetCode() int {
|
func (r *baseResponse) GetCode() int {
|
||||||
return r.Code
|
return r.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *baseResponse) GetMsg() string {
|
func (r *baseResponse) GetMessage() string {
|
||||||
return r.Msg
|
return r.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddDomainResolutionRequest struct {
|
type AddDomainResolutionRequest struct {
|
||||||
|
14
internal/pkg/vendors/safeline-sdk/api.go
vendored
14
internal/pkg/vendors/safeline-sdk/api.go
vendored
@ -1,18 +1,10 @@
|
|||||||
package safelinesdk
|
package safelinesdk
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
||||||
params := make(map[string]any)
|
resp := UpdateCertificateResponse{}
|
||||||
jsonData, _ := json.Marshal(req)
|
err := c.sendRequestWithResult("/api/open/cert", req, &resp)
|
||||||
json.Unmarshal(jsonData, ¶ms)
|
|
||||||
|
|
||||||
result := UpdateCertificateResponse{}
|
|
||||||
err := c.sendRequestWithResult("/api/open/cert", params, &result)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
8
internal/pkg/vendors/safeline-sdk/client.go
vendored
8
internal/pkg/vendors/safeline-sdk/client.go
vendored
@ -31,11 +31,7 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequest(path string, params map[string]any) (*resty.Response, error) {
|
func (c *Client) sendRequest(path string, params interface{}) (*resty.Response, error) {
|
||||||
if params == nil {
|
|
||||||
params = make(map[string]any)
|
|
||||||
}
|
|
||||||
|
|
||||||
url := c.apiHost + path
|
url := c.apiHost + path
|
||||||
req := c.client.R().
|
req := c.client.R().
|
||||||
SetHeader("Content-Type", "application/json").
|
SetHeader("Content-Type", "application/json").
|
||||||
@ -51,7 +47,7 @@ func (c *Client) sendRequest(path string, params map[string]any) (*resty.Respons
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
|
func (c *Client) sendRequestWithResult(path string, params interface{}, result BaseResponse) error {
|
||||||
resp, err := c.sendRequest(path, params)
|
resp, err := c.sendRequest(path, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -73,6 +73,7 @@ func init() {
|
|||||||
"godaddy",
|
"godaddy",
|
||||||
"goedge",
|
"goedge",
|
||||||
"huaweicloud",
|
"huaweicloud",
|
||||||
|
"jdcloud",
|
||||||
"k8s",
|
"k8s",
|
||||||
"local",
|
"local",
|
||||||
"namedotcom",
|
"namedotcom",
|
||||||
@ -80,6 +81,7 @@ func init() {
|
|||||||
"ns1",
|
"ns1",
|
||||||
"powerdns",
|
"powerdns",
|
||||||
"qiniu",
|
"qiniu",
|
||||||
|
"qingcloud",
|
||||||
"rainyun",
|
"rainyun",
|
||||||
"safeline",
|
"safeline",
|
||||||
"ssh",
|
"ssh",
|
||||||
@ -179,6 +181,7 @@ func init() {
|
|||||||
"godaddy",
|
"godaddy",
|
||||||
"goedge",
|
"goedge",
|
||||||
"huaweicloud",
|
"huaweicloud",
|
||||||
|
"jdcloud",
|
||||||
"k8s",
|
"k8s",
|
||||||
"local",
|
"local",
|
||||||
"namedotcom",
|
"namedotcom",
|
||||||
@ -186,6 +189,7 @@ func init() {
|
|||||||
"ns1",
|
"ns1",
|
||||||
"powerdns",
|
"powerdns",
|
||||||
"qiniu",
|
"qiniu",
|
||||||
|
"qingcloud",
|
||||||
"rainyun",
|
"rainyun",
|
||||||
"safeline",
|
"safeline",
|
||||||
"ssh",
|
"ssh",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user