feat: add baishan cdn deployer
This commit is contained in:
42
internal/pkg/vendors/safeline-sdk/api.go
vendored
42
internal/pkg/vendors/safeline-sdk/api.go
vendored
@@ -1,34 +1,18 @@
|
||||
package safelinesdk
|
||||
|
||||
type BaseResponse interface {
|
||||
GetErrCode() *string
|
||||
GetErrMsg() *string
|
||||
}
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type baseResponse struct {
|
||||
ErrCode *string `json:"err,omitempty"`
|
||||
ErrMsg *string `json:"msg,omitempty"`
|
||||
}
|
||||
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
func (r *baseResponse) GetErrCode() *string {
|
||||
return r.ErrCode
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetErrMsg() *string {
|
||||
return r.ErrMsg
|
||||
}
|
||||
|
||||
type UpdateCertificateRequest struct {
|
||||
Id int32 `json:"id"`
|
||||
Type int32 `json:"type"`
|
||||
Manual *UpdateCertificateRequestBodyManul `json:"manual"`
|
||||
}
|
||||
|
||||
type UpdateCertificateRequestBodyManul struct {
|
||||
Crt string `json:"crt"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type UpdateCertificateResponse struct {
|
||||
baseResponse
|
||||
result := UpdateCertificateResponse{}
|
||||
err := c.sendRequestWithResult("/api/open/cert", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
25
internal/pkg/vendors/safeline-sdk/client.go
vendored
25
internal/pkg/vendors/safeline-sdk/client.go
vendored
@@ -9,41 +9,28 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type SafeLineClient struct {
|
||||
type Client struct {
|
||||
apiHost string
|
||||
apiToken string
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewSafeLineClient(apiHost, apiToken string) *SafeLineClient {
|
||||
func NewClient(apiHost, apiToken string) *Client {
|
||||
client := resty.New()
|
||||
|
||||
return &SafeLineClient{
|
||||
return &Client{
|
||||
apiHost: apiHost,
|
||||
apiToken: apiToken,
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *SafeLineClient) WithTimeout(timeout time.Duration) *SafeLineClient {
|
||||
func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *SafeLineClient) 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *SafeLineClient) sendRequest(path string, params map[string]any) (*resty.Response, error) {
|
||||
func (c *Client) sendRequest(path string, params map[string]any) (*resty.Response, error) {
|
||||
if params == nil {
|
||||
params = make(map[string]any)
|
||||
}
|
||||
@@ -65,7 +52,7 @@ func (c *SafeLineClient) sendRequest(path string, params map[string]any) (*resty
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *SafeLineClient) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
|
||||
func (c *Client) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
|
||||
resp, err := c.sendRequest(path, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
34
internal/pkg/vendors/safeline-sdk/models.go
vendored
Normal file
34
internal/pkg/vendors/safeline-sdk/models.go
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
package safelinesdk
|
||||
|
||||
type BaseResponse interface {
|
||||
GetErrCode() *string
|
||||
GetErrMsg() *string
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
ErrCode *string `json:"err,omitempty"`
|
||||
ErrMsg *string `json:"msg,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetErrCode() *string {
|
||||
return r.ErrCode
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetErrMsg() *string {
|
||||
return r.ErrMsg
|
||||
}
|
||||
|
||||
type UpdateCertificateRequest struct {
|
||||
Id int32 `json:"id"`
|
||||
Type int32 `json:"type"`
|
||||
Manual *UpdateCertificateRequestBodyManul `json:"manual"`
|
||||
}
|
||||
|
||||
type UpdateCertificateRequestBodyManul struct {
|
||||
Crt string `json:"crt"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type UpdateCertificateResponse struct {
|
||||
baseResponse
|
||||
}
|
||||
Reference in New Issue
Block a user