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