chore: move '/internal/pkg' to '/pkg'
This commit is contained in:
43
pkg/sdk3rd/1panel/api_get_https_conf.go
Normal file
43
pkg/sdk3rd/1panel/api_get_https_conf.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package onepanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetHttpsConfResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
Enable bool `json:"enable"`
|
||||
HttpConfig string `json:"httpConfig"`
|
||||
SSLProtocol []string `json:"SSLProtocol"`
|
||||
Algorithm string `json:"algorithm"`
|
||||
Hsts bool `json:"hsts"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsConf(websiteId int64) (*GetHttpsConfResponse, error) {
|
||||
return c.GetHttpsConfWithContext(context.Background(), websiteId)
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsConfWithContext(ctx context.Context, websiteId int64) (*GetHttpsConfResponse, error) {
|
||||
if websiteId == 0 {
|
||||
return nil, fmt.Errorf("sdkerr: unset websiteId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodGet, fmt.Sprintf("/websites/%d/https", websiteId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &GetHttpsConfResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/sdk3rd/1panel/api_get_website_ssl.go
Normal file
50
pkg/sdk3rd/1panel/api_get_website_ssl.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package onepanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetWebsiteSSLResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
ID int64 `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
Description string `json:"description"`
|
||||
PrimaryDomain string `json:"primaryDomain"`
|
||||
Domains string `json:"domains"`
|
||||
Type string `json:"type"`
|
||||
Organization string `json:"organization"`
|
||||
Status string `json:"status"`
|
||||
StartDate string `json:"startDate"`
|
||||
ExpireDate string `json:"expireDate"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) GetWebsiteSSL(sslId int64) (*GetWebsiteSSLResponse, error) {
|
||||
return c.GetWebsiteSSLWithContext(context.Background(), sslId)
|
||||
}
|
||||
|
||||
func (c *Client) GetWebsiteSSLWithContext(ctx context.Context, sslId int64) (*GetWebsiteSSLResponse, error) {
|
||||
if sslId == 0 {
|
||||
return nil, fmt.Errorf("sdkerr: unset sslId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodGet, fmt.Sprintf("/websites/ssl/%d", sslId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &GetWebsiteSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/sdk3rd/1panel/api_search_website_ssl.go
Normal file
50
pkg/sdk3rd/1panel/api_search_website_ssl.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package onepanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SearchWebsiteSSLRequest struct {
|
||||
Page int32 `json:"page"`
|
||||
PageSize int32 `json:"pageSize"`
|
||||
}
|
||||
|
||||
type SearchWebsiteSSLResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
Items []*struct {
|
||||
ID int64 `json:"id"`
|
||||
PEM string `json:"pem"`
|
||||
PrivateKey string `json:"privateKey"`
|
||||
Domains string `json:"domains"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
} `json:"items"`
|
||||
Total int32 `json:"total"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) SearchWebsiteSSL(req *SearchWebsiteSSLRequest) (*SearchWebsiteSSLResponse, error) {
|
||||
return c.SearchWebsiteSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SearchWebsiteSSLWithContext(ctx context.Context, req *SearchWebsiteSSLRequest) (*SearchWebsiteSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/websites/ssl/search")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SearchWebsiteSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
53
pkg/sdk3rd/1panel/api_update_https_conf.go
Normal file
53
pkg/sdk3rd/1panel/api_update_https_conf.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package onepanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UpdateHttpsConfRequest struct {
|
||||
WebsiteID int64 `json:"websiteId"`
|
||||
Enable bool `json:"enable"`
|
||||
Type string `json:"type"`
|
||||
WebsiteSSLID int64 `json:"websiteSSLId"`
|
||||
PrivateKey string `json:"privateKey"`
|
||||
Certificate string `json:"certificate"`
|
||||
PrivateKeyPath string `json:"privateKeyPath"`
|
||||
CertificatePath string `json:"certificatePath"`
|
||||
ImportType string `json:"importType"`
|
||||
HttpConfig string `json:"httpConfig"`
|
||||
SSLProtocol []string `json:"SSLProtocol"`
|
||||
Algorithm string `json:"algorithm"`
|
||||
Hsts bool `json:"hsts"`
|
||||
}
|
||||
|
||||
type UpdateHttpsConfResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsConf(websiteId int64, req *UpdateHttpsConfRequest) (*UpdateHttpsConfResponse, error) {
|
||||
return c.UpdateHttpsConfWithContext(context.Background(), websiteId, req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsConfWithContext(ctx context.Context, websiteId int64, req *UpdateHttpsConfRequest) (*UpdateHttpsConfResponse, error) {
|
||||
if websiteId == 0 {
|
||||
return nil, fmt.Errorf("sdkerr: unset websiteId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodPost, fmt.Sprintf("/websites/%d/https", websiteId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
req.WebsiteID = websiteId
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateHttpsConfResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
40
pkg/sdk3rd/1panel/api_update_settings_ssl.go
Normal file
40
pkg/sdk3rd/1panel/api_update_settings_ssl.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package onepanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UpdateSettingsSSLRequest struct {
|
||||
Cert string `json:"cert"`
|
||||
Key string `json:"key"`
|
||||
SSLType string `json:"sslType"`
|
||||
SSL string `json:"ssl"`
|
||||
SSLID int64 `json:"sslID"`
|
||||
AutoRestart string `json:"autoRestart"`
|
||||
}
|
||||
|
||||
type UpdateSettingsSSLResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateSettingsSSL(req *UpdateSettingsSSLRequest) (*UpdateSettingsSSLResponse, error) {
|
||||
return c.UpdateSettingsSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateSettingsSSLWithContext(ctx context.Context, req *UpdateSettingsSSLRequest) (*UpdateSettingsSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/settings/ssl/update")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateSettingsSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
41
pkg/sdk3rd/1panel/api_upload_website_ssl.go
Normal file
41
pkg/sdk3rd/1panel/api_upload_website_ssl.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package onepanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UploadWebsiteSSLRequest struct {
|
||||
SSLID int64 `json:"sslID"`
|
||||
Type string `json:"type"`
|
||||
Certificate string `json:"certificate"`
|
||||
CertificatePath string `json:"certificatePath"`
|
||||
PrivateKey string `json:"privateKey"`
|
||||
PrivateKeyPath string `json:"privateKeyPath"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type UploadWebsiteSSLResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UploadWebsiteSSL(req *UploadWebsiteSSLRequest) (*UploadWebsiteSSLResponse, error) {
|
||||
return c.UploadWebsiteSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) UploadWebsiteSSLWithContext(ctx context.Context, req *UploadWebsiteSSLRequest) (*UploadWebsiteSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/websites/ssl/upload")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UploadWebsiteSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
116
pkg/sdk3rd/1panel/client.go
Normal file
116
pkg/sdk3rd/1panel/client.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package onepanel
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(serverUrl, apiKey string) (*Client, error) {
|
||||
if serverUrl == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset serverUrl")
|
||||
}
|
||||
if _, err := url.Parse(serverUrl); err != nil {
|
||||
return nil, fmt.Errorf("sdkerr: invalid serverUrl: %w", err)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiKey")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api/v1").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetPreRequestHook(func(c *resty.Client, req *http.Request) error {
|
||||
timestamp := fmt.Sprintf("%d", time.Now().Unix())
|
||||
tokenMd5 := md5.Sum([]byte("1panel" + apiKey + timestamp))
|
||||
tokenMd5Hex := hex.EncodeToString(tokenMd5[:])
|
||||
req.Header.Set("1Panel-Timestamp", timestamp)
|
||||
req.Header.Set("1Panel-Token", tokenMd5Hex)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) SetTLSConfig(config *tls.Config) *Client {
|
||||
c.client.SetTLSClientConfig(config)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
} else {
|
||||
if tcode := res.GetCode(); tcode/100 != 2 {
|
||||
return resp, fmt.Errorf("sdkerr: api error: code='%d', message='%s'", tcode, res.GetMessage())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
29
pkg/sdk3rd/1panel/types.go
Normal file
29
pkg/sdk3rd/1panel/types.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package onepanel
|
||||
|
||||
type apiResponse interface {
|
||||
GetCode() int32
|
||||
GetMessage() string
|
||||
}
|
||||
|
||||
type apiResponseBase struct {
|
||||
Code *int32 `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetCode() int32 {
|
||||
if r.Code == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return *r.Code
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetMessage() string {
|
||||
if r.Message == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return *r.Message
|
||||
}
|
||||
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
43
pkg/sdk3rd/1panel/v2/api_get_https_conf.go
Normal file
43
pkg/sdk3rd/1panel/v2/api_get_https_conf.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package onepanelv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetHttpsConfResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
Enable bool `json:"enable"`
|
||||
HttpConfig string `json:"httpConfig"`
|
||||
SSLProtocol []string `json:"SSLProtocol"`
|
||||
Algorithm string `json:"algorithm"`
|
||||
Hsts bool `json:"hsts"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsConf(websiteId int64) (*GetHttpsConfResponse, error) {
|
||||
return c.GetHttpsConfWithContext(context.Background(), websiteId)
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsConfWithContext(ctx context.Context, websiteId int64) (*GetHttpsConfResponse, error) {
|
||||
if websiteId == 0 {
|
||||
return nil, fmt.Errorf("sdkerr: unset websiteId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodGet, fmt.Sprintf("/websites/%d/https", websiteId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &GetHttpsConfResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/sdk3rd/1panel/v2/api_get_website_ssl.go
Normal file
50
pkg/sdk3rd/1panel/v2/api_get_website_ssl.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package onepanelv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetWebsiteSSLResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
ID int64 `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
Description string `json:"description"`
|
||||
PrimaryDomain string `json:"primaryDomain"`
|
||||
Domains string `json:"domains"`
|
||||
Type string `json:"type"`
|
||||
Organization string `json:"organization"`
|
||||
Status string `json:"status"`
|
||||
StartDate string `json:"startDate"`
|
||||
ExpireDate string `json:"expireDate"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) GetWebsiteSSL(sslId int64) (*GetWebsiteSSLResponse, error) {
|
||||
return c.GetWebsiteSSLWithContext(context.Background(), sslId)
|
||||
}
|
||||
|
||||
func (c *Client) GetWebsiteSSLWithContext(ctx context.Context, sslId int64) (*GetWebsiteSSLResponse, error) {
|
||||
if sslId == 0 {
|
||||
return nil, fmt.Errorf("sdkerr: unset sslId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodGet, fmt.Sprintf("/websites/ssl/%d", sslId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &GetWebsiteSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/sdk3rd/1panel/v2/api_search_website_ssl.go
Normal file
50
pkg/sdk3rd/1panel/v2/api_search_website_ssl.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package onepanelv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SearchWebsiteSSLRequest struct {
|
||||
Page int32 `json:"page"`
|
||||
PageSize int32 `json:"pageSize"`
|
||||
}
|
||||
|
||||
type SearchWebsiteSSLResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
Items []*struct {
|
||||
ID int64 `json:"id"`
|
||||
PEM string `json:"pem"`
|
||||
PrivateKey string `json:"privateKey"`
|
||||
Domains string `json:"domains"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
} `json:"items"`
|
||||
Total int32 `json:"total"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) SearchWebsiteSSL(req *SearchWebsiteSSLRequest) (*SearchWebsiteSSLResponse, error) {
|
||||
return c.SearchWebsiteSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SearchWebsiteSSLWithContext(ctx context.Context, req *SearchWebsiteSSLRequest) (*SearchWebsiteSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/websites/ssl/search")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SearchWebsiteSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
40
pkg/sdk3rd/1panel/v2/api_update_core_settings_ssl.go
Normal file
40
pkg/sdk3rd/1panel/v2/api_update_core_settings_ssl.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package onepanelv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UpdateCoreSettingsSSLRequest struct {
|
||||
Cert string `json:"cert"`
|
||||
Key string `json:"key"`
|
||||
SSLType string `json:"sslType"`
|
||||
SSL string `json:"ssl"`
|
||||
SSLID int64 `json:"sslID"`
|
||||
AutoRestart string `json:"autoRestart"`
|
||||
}
|
||||
|
||||
type UpdateCoreSettingsSSLResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCoreSettingsSSL(req *UpdateCoreSettingsSSLRequest) (*UpdateCoreSettingsSSLResponse, error) {
|
||||
return c.UpdateCoreSettingsSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCoreSettingsSSLWithContext(ctx context.Context, req *UpdateCoreSettingsSSLRequest) (*UpdateCoreSettingsSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/core/settings/ssl/update")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateCoreSettingsSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
53
pkg/sdk3rd/1panel/v2/api_update_https_conf.go
Normal file
53
pkg/sdk3rd/1panel/v2/api_update_https_conf.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package onepanelv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UpdateHttpsConfRequest struct {
|
||||
WebsiteID int64 `json:"websiteId"`
|
||||
Enable bool `json:"enable"`
|
||||
Type string `json:"type"`
|
||||
WebsiteSSLID int64 `json:"websiteSSLId"`
|
||||
PrivateKey string `json:"privateKey"`
|
||||
Certificate string `json:"certificate"`
|
||||
PrivateKeyPath string `json:"privateKeyPath"`
|
||||
CertificatePath string `json:"certificatePath"`
|
||||
ImportType string `json:"importType"`
|
||||
HttpConfig string `json:"httpConfig"`
|
||||
SSLProtocol []string `json:"SSLProtocol"`
|
||||
Algorithm string `json:"algorithm"`
|
||||
Hsts bool `json:"hsts"`
|
||||
}
|
||||
|
||||
type UpdateHttpsConfResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsConf(websiteId int64, req *UpdateHttpsConfRequest) (*UpdateHttpsConfResponse, error) {
|
||||
return c.UpdateHttpsConfWithContext(context.Background(), websiteId, req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsConfWithContext(ctx context.Context, websiteId int64, req *UpdateHttpsConfRequest) (*UpdateHttpsConfResponse, error) {
|
||||
if websiteId == 0 {
|
||||
return nil, fmt.Errorf("sdkerr: unset websiteId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodPost, fmt.Sprintf("/websites/%d/https", websiteId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
req.WebsiteID = websiteId
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateHttpsConfResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
41
pkg/sdk3rd/1panel/v2/api_upload_website_ssl.go
Normal file
41
pkg/sdk3rd/1panel/v2/api_upload_website_ssl.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package onepanelv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UploadWebsiteSSLRequest struct {
|
||||
SSLID int64 `json:"sslID"`
|
||||
Type string `json:"type"`
|
||||
Certificate string `json:"certificate"`
|
||||
CertificatePath string `json:"certificatePath"`
|
||||
PrivateKey string `json:"privateKey"`
|
||||
PrivateKeyPath string `json:"privateKeyPath"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type UploadWebsiteSSLResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UploadWebsiteSSL(req *UploadWebsiteSSLRequest) (*UploadWebsiteSSLResponse, error) {
|
||||
return c.UploadWebsiteSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) UploadWebsiteSSLWithContext(ctx context.Context, req *UploadWebsiteSSLRequest) (*UploadWebsiteSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/websites/ssl/upload")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UploadWebsiteSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
116
pkg/sdk3rd/1panel/v2/client.go
Normal file
116
pkg/sdk3rd/1panel/v2/client.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package onepanelv2
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(serverUrl, apiKey string) (*Client, error) {
|
||||
if serverUrl == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset serverUrl")
|
||||
}
|
||||
if _, err := url.Parse(serverUrl); err != nil {
|
||||
return nil, fmt.Errorf("sdkerr: invalid serverUrl: %w", err)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiKey")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api/v2").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetPreRequestHook(func(c *resty.Client, req *http.Request) error {
|
||||
timestamp := fmt.Sprintf("%d", time.Now().Unix())
|
||||
tokenMd5 := md5.Sum([]byte("1panel" + apiKey + timestamp))
|
||||
tokenMd5Hex := hex.EncodeToString(tokenMd5[:])
|
||||
req.Header.Set("1Panel-Timestamp", timestamp)
|
||||
req.Header.Set("1Panel-Token", tokenMd5Hex)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) SetTLSConfig(config *tls.Config) *Client {
|
||||
c.client.SetTLSClientConfig(config)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
} else {
|
||||
if tcode := res.GetCode(); tcode/100 != 2 {
|
||||
return resp, fmt.Errorf("sdkerr: api error: code='%d', message='%s'", tcode, res.GetMessage())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
29
pkg/sdk3rd/1panel/v2/types.go
Normal file
29
pkg/sdk3rd/1panel/v2/types.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package onepanelv2
|
||||
|
||||
type apiResponse interface {
|
||||
GetCode() int32
|
||||
GetMessage() string
|
||||
}
|
||||
|
||||
type apiResponseBase struct {
|
||||
Code *int32 `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetCode() int32 {
|
||||
if r.Code == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return *r.Code
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetMessage() string {
|
||||
if r.Message == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return *r.Message
|
||||
}
|
||||
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
44
pkg/sdk3rd/apisix/api_update_ssl.go
Normal file
44
pkg/sdk3rd/apisix/api_update_ssl.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package apisix
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UpdateSSLRequest struct {
|
||||
Cert *string `json:"cert,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
SNIs *[]string `json:"snis,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Status *int32 `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateSSLResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateSSL(sslId string, req *UpdateSSLRequest) (*UpdateSSLResponse, error) {
|
||||
return c.UpdateSSLWithContext(context.Background(), sslId, req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateSSLWithContext(ctx context.Context, sslId string, req *UpdateSSLRequest) (*UpdateSSLResponse, error) {
|
||||
if sslId == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset sslId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodPut, fmt.Sprintf("/ssls/%s", sslId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
106
pkg/sdk3rd/apisix/client.go
Normal file
106
pkg/sdk3rd/apisix/client.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package apisix
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(serverUrl, apiKey string) (*Client, error) {
|
||||
if serverUrl == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset serverUrl")
|
||||
}
|
||||
if _, err := url.Parse(serverUrl); err != nil {
|
||||
return nil, fmt.Errorf("sdkerr: invalid serverUrl: %w", err)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiKey")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL(strings.TrimRight(serverUrl, "/")+"/apisix/admin").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetPreRequestHook(func(c *resty.Client, req *http.Request) error {
|
||||
req.Header.Set("X-API-KEY", apiKey)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) SetTLSConfig(config *tls.Config) *Client {
|
||||
c.client.SetTLSClientConfig(config)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
7
pkg/sdk3rd/apisix/types.go
Normal file
7
pkg/sdk3rd/apisix/types.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package apisix
|
||||
|
||||
type apiResponse interface{}
|
||||
|
||||
type apiResponseBase struct{}
|
||||
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
47
pkg/sdk3rd/azure/env/config.go
vendored
Normal file
47
pkg/sdk3rd/azure/env/config.go
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
|
||||
)
|
||||
|
||||
func IsPublicEnv(env string) bool {
|
||||
switch strings.ToLower(env) {
|
||||
case "", "default", "public", "azurecloud":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func IsUSGovernmentEnv(env string) bool {
|
||||
switch strings.ToLower(env) {
|
||||
case "usgovernment", "government", "azureusgovernment", "azuregovernment":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func IsChinaEnv(env string) bool {
|
||||
switch strings.ToLower(env) {
|
||||
case "china", "chinacloud", "azurechina", "azurechinacloud":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func GetCloudEnvConfiguration(env string) (cloud.Configuration, error) {
|
||||
if IsPublicEnv(env) {
|
||||
return cloud.AzurePublic, nil
|
||||
} else if IsUSGovernmentEnv(env) {
|
||||
return cloud.AzureGovernment, nil
|
||||
} else if IsChinaEnv(env) {
|
||||
return cloud.AzureChina, nil
|
||||
}
|
||||
|
||||
return cloud.Configuration{}, fmt.Errorf("unknown azure cloud environment %s", env)
|
||||
}
|
||||
93
pkg/sdk3rd/baiducloud/cert/cert.go
Normal file
93
pkg/sdk3rd/baiducloud/cert/cert.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package cert
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/baidubce/bce-sdk-go/bce"
|
||||
"github.com/baidubce/bce-sdk-go/http"
|
||||
"github.com/baidubce/bce-sdk-go/services/cert"
|
||||
)
|
||||
|
||||
func (c *Client) CreateCert(args *CreateCertArgs) (*CreateCertResult, error) {
|
||||
if args == nil {
|
||||
return nil, errors.New("unset args")
|
||||
}
|
||||
|
||||
result, err := c.Client.CreateCert(&args.CreateCertArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &CreateCertResult{CreateCertResult: *result}, nil
|
||||
}
|
||||
|
||||
func (c *Client) ListCerts() (*ListCertResult, error) {
|
||||
result, err := c.Client.ListCerts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ListCertResult{ListCertResult: *result}, nil
|
||||
}
|
||||
|
||||
func (c *Client) ListCertDetail() (*ListCertDetailResult, error) {
|
||||
result, err := c.Client.ListCertDetail()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ListCertDetailResult{ListCertDetailResult: *result}, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetCertMeta(id string) (*CertificateMeta, error) {
|
||||
result, err := c.Client.GetCertMeta(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &CertificateMeta{CertificateMeta: *result}, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetCertDetail(id string) (*CertificateDetailMeta, error) {
|
||||
result, err := c.Client.GetCertDetail(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &CertificateDetailMeta{CertificateDetailMeta: *result}, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetCertRawData(id string) (*CertificateRawData, error) {
|
||||
result := &CertificateRawData{}
|
||||
err := bce.NewRequestBuilder(c).
|
||||
WithMethod(http.GET).
|
||||
WithURL(cert.URI_PREFIX + cert.REQUEST_CERT_URL + "/" + id + "/rawData").
|
||||
WithResult(result).
|
||||
Do()
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCertName(id string, args *UpdateCertNameArgs) error {
|
||||
if args == nil {
|
||||
return errors.New("unset args")
|
||||
}
|
||||
|
||||
err := c.Client.UpdateCertName(id, &args.UpdateCertNameArgs)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCertData(id string, args *UpdateCertDataArgs) error {
|
||||
if args == nil {
|
||||
return fmt.Errorf("unset args")
|
||||
}
|
||||
|
||||
err := c.Client.UpdateCertData(id, &args.UpdateCertDataArgs)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteCert(id string) error {
|
||||
err := c.Client.DeleteCert(id)
|
||||
return err
|
||||
}
|
||||
18
pkg/sdk3rd/baiducloud/cert/client.go
Normal file
18
pkg/sdk3rd/baiducloud/cert/client.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package cert
|
||||
|
||||
import (
|
||||
"github.com/baidubce/bce-sdk-go/services/cert"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
*cert.Client
|
||||
}
|
||||
|
||||
func NewClient(ak, sk, endPoint string) (*Client, error) {
|
||||
client, err := cert.NewClient(ak, sk, endPoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
48
pkg/sdk3rd/baiducloud/cert/model.go
Normal file
48
pkg/sdk3rd/baiducloud/cert/model.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package cert
|
||||
|
||||
import "github.com/baidubce/bce-sdk-go/services/cert"
|
||||
|
||||
type CreateCertArgs struct {
|
||||
cert.CreateCertArgs
|
||||
}
|
||||
|
||||
type CreateCertResult struct {
|
||||
cert.CreateCertResult
|
||||
}
|
||||
|
||||
type UpdateCertNameArgs struct {
|
||||
cert.UpdateCertNameArgs
|
||||
}
|
||||
|
||||
type CertificateMeta struct {
|
||||
cert.CertificateMeta
|
||||
}
|
||||
|
||||
type CertificateDetailMeta struct {
|
||||
cert.CertificateDetailMeta
|
||||
}
|
||||
|
||||
type CertificateRawData struct {
|
||||
CertId string `json:"certId"`
|
||||
CertName string `json:"certName"`
|
||||
CertServerData string `json:"certServerData"`
|
||||
CertPrivateData string `json:"certPrivateKey"`
|
||||
CertLinkData string `json:"certLinkData,omitempty"`
|
||||
CertType int `json:"certType,omitempty"`
|
||||
}
|
||||
|
||||
type ListCertResult struct {
|
||||
cert.ListCertResult
|
||||
}
|
||||
|
||||
type ListCertDetailResult struct {
|
||||
cert.ListCertDetailResult
|
||||
}
|
||||
|
||||
type UpdateCertDataArgs struct {
|
||||
cert.UpdateCertDataArgs
|
||||
}
|
||||
|
||||
type CertInServiceMeta struct {
|
||||
cert.CertInServiceMeta
|
||||
}
|
||||
49
pkg/sdk3rd/baishan/api_get_domain_config.go
Normal file
49
pkg/sdk3rd/baishan/api_get_domain_config.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package baishan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetDomainConfigRequest struct {
|
||||
Domains *string `json:"domains,omitempty"`
|
||||
Config *[]string `json:"config,omitempty"`
|
||||
}
|
||||
|
||||
type GetDomainConfigResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data []*struct {
|
||||
Domain string `json:"domain"`
|
||||
Config *DomainConfig `json:"config"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
||||
return c.GetDomainConfigWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) GetDomainConfigWithContext(ctx context.Context, req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/v2/domain/config")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if req.Domains != nil {
|
||||
httpreq.SetQueryParam("domains", *req.Domains)
|
||||
}
|
||||
if req.Config != nil {
|
||||
for _, config := range *req.Config {
|
||||
httpreq.QueryParam.Add("config[]", config)
|
||||
}
|
||||
}
|
||||
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &GetDomainConfigResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
40
pkg/sdk3rd/baishan/api_set_domain_certificate.go
Normal file
40
pkg/sdk3rd/baishan/api_set_domain_certificate.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package baishan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SetDomainCertificateRequest struct {
|
||||
CertificateId *string `json:"cert_id,omitempty"`
|
||||
Certificate *string `json:"certificate,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type SetDomainCertificateResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *DomainCertificate `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) SetDomainCertificate(req *SetDomainCertificateRequest) (*SetDomainCertificateResponse, error) {
|
||||
return c.SetDomainCertificateWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SetDomainCertificateWithContext(ctx context.Context, req *SetDomainCertificateRequest) (*SetDomainCertificateResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/v2/domain/certificate")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SetDomainCertificateResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
40
pkg/sdk3rd/baishan/api_set_domain_config.go
Normal file
40
pkg/sdk3rd/baishan/api_set_domain_config.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package baishan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SetDomainConfigRequest struct {
|
||||
Domains *string `json:"domains,omitempty"`
|
||||
Config *DomainConfig `json:"config,omitempty"`
|
||||
}
|
||||
|
||||
type SetDomainConfigResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
Config *DomainConfig `json:"config"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) SetDomainConfig(req *SetDomainConfigRequest) (*SetDomainConfigResponse, error) {
|
||||
return c.SetDomainConfigWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SetDomainConfigWithContext(ctx context.Context, req *SetDomainConfigRequest) (*SetDomainConfigResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/v2/domain/config")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SetDomainConfigResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
91
pkg/sdk3rd/baishan/client.go
Normal file
91
pkg/sdk3rd/baishan/client.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package baishan
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(apiToken string) (*Client, error) {
|
||||
if apiToken == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiToken")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL("https://cdn.api.baishan.com").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetHeader("Token", apiToken)
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
} else {
|
||||
if tcode := res.GetCode(); tcode != 0 {
|
||||
return resp, fmt.Errorf("sdkerr: code='%d', message='%s'", tcode, res.GetMessage())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
49
pkg/sdk3rd/baishan/types.go
Normal file
49
pkg/sdk3rd/baishan/types.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package baishan
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type apiResponse interface {
|
||||
GetCode() int32
|
||||
GetMessage() string
|
||||
}
|
||||
|
||||
type apiResponseBase struct {
|
||||
Code *int32 `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetCode() int32 {
|
||||
if r.Code == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return *r.Code
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetMessage() string {
|
||||
if r.Message == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return *r.Message
|
||||
}
|
||||
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
|
||||
type DomainCertificate struct {
|
||||
CertId json.Number `json:"cert_id"`
|
||||
Name string `json:"name"`
|
||||
CertStartTime string `json:"cert_start_time"`
|
||||
CertExpireTime string `json:"cert_expire_time"`
|
||||
}
|
||||
|
||||
type DomainConfig struct {
|
||||
Https *DomainConfigHttps `json:"https"`
|
||||
}
|
||||
|
||||
type DomainConfigHttps struct {
|
||||
CertId json.Number `json:"cert_id"`
|
||||
ForceHttps *string `json:"force_https,omitempty"`
|
||||
EnableHttp2 *string `json:"http2,omitempty"`
|
||||
EnableOcsp *string `json:"ocsp,omitempty"`
|
||||
}
|
||||
35
pkg/sdk3rd/btpanel/api_config_save_panel_ssl.go
Normal file
35
pkg/sdk3rd/btpanel/api_config_save_panel_ssl.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package btpanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ConfigSavePanelSSLRequest struct {
|
||||
PrivateKey string `json:"privateKey"`
|
||||
Certificate string `json:"certPem"`
|
||||
}
|
||||
|
||||
type ConfigSavePanelSSLResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) ConfigSavePanelSSL(req *ConfigSavePanelSSLRequest) (*ConfigSavePanelSSLResponse, error) {
|
||||
return c.ConfigSavePanelSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) ConfigSavePanelSSLWithContext(ctx context.Context, req *ConfigSavePanelSSLRequest) (*ConfigSavePanelSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/config?action=SavePanelSSL", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &ConfigSavePanelSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
37
pkg/sdk3rd/btpanel/api_site_set_ssl.go
Normal file
37
pkg/sdk3rd/btpanel/api_site_set_ssl.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package btpanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SiteSetSSLRequest struct {
|
||||
Type string `json:"type"`
|
||||
SiteName string `json:"siteName"`
|
||||
PrivateKey string `json:"key"`
|
||||
Certificate string `json:"csr"`
|
||||
}
|
||||
|
||||
type SiteSetSSLResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) SiteSetSSL(req *SiteSetSSLRequest) (*SiteSetSSLResponse, error) {
|
||||
return c.SiteSetSSLWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SiteSetSSLWithContext(ctx context.Context, req *SiteSetSSLRequest) (*SiteSetSSLResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/site?action=SetSSL", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SiteSetSSLResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
37
pkg/sdk3rd/btpanel/api_ssl_cert_save_cert.go
Normal file
37
pkg/sdk3rd/btpanel/api_ssl_cert_save_cert.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package btpanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SSLCertSaveCertRequest struct {
|
||||
PrivateKey string `json:"key"`
|
||||
Certificate string `json:"csr"`
|
||||
}
|
||||
|
||||
type SSLCertSaveCertResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
SSLHash string `json:"ssl_hash"`
|
||||
}
|
||||
|
||||
func (c *Client) SSLCertSaveCert(req *SSLCertSaveCertRequest) (*SSLCertSaveCertResponse, error) {
|
||||
return c.SSLCertSaveCertWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SSLCertSaveCertWithContext(ctx context.Context, req *SSLCertSaveCertRequest) (*SSLCertSaveCertResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/ssl/cert/save_cert", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SSLCertSaveCertResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
44
pkg/sdk3rd/btpanel/api_ssl_set_batch_cert_to_site.go
Normal file
44
pkg/sdk3rd/btpanel/api_ssl_set_batch_cert_to_site.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package btpanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SSLSetBatchCertToSiteRequest struct {
|
||||
BatchInfo []*SSLSetBatchCertToSiteRequestBatchInfo `json:"BatchInfo"`
|
||||
}
|
||||
|
||||
type SSLSetBatchCertToSiteRequestBatchInfo struct {
|
||||
SSLHash string `json:"ssl_hash"`
|
||||
SiteName string `json:"siteName"`
|
||||
CertName string `json:"certName"`
|
||||
}
|
||||
|
||||
type SSLSetBatchCertToSiteResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
TotalCount int32 `json:"total"`
|
||||
SuccessCount int32 `json:"success"`
|
||||
FailedCount int32 `json:"faild"`
|
||||
}
|
||||
|
||||
func (c *Client) SSLSetBatchCertToSite(req *SSLSetBatchCertToSiteRequest) (*SSLSetBatchCertToSiteResponse, error) {
|
||||
return c.SSLSetBatchCertToSiteWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SSLSetBatchCertToSiteWithContext(ctx context.Context, req *SSLSetBatchCertToSiteRequest) (*SSLSetBatchCertToSiteResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/ssl?action=SetBatchCertToSite", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SSLSetBatchCertToSiteResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
35
pkg/sdk3rd/btpanel/api_system_service_admin.go
Normal file
35
pkg/sdk3rd/btpanel/api_system_service_admin.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package btpanel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SystemServiceAdminRequest struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type SystemServiceAdminResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) SystemServiceAdmin(req *SystemServiceAdminRequest) (*SystemServiceAdminResponse, error) {
|
||||
return c.SystemServiceAdminWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) SystemServiceAdminWithContext(ctx context.Context, req *SystemServiceAdminRequest) (*SystemServiceAdminResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/system?action=ServiceAdmin", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &SystemServiceAdminResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
159
pkg/sdk3rd/btpanel/client.go
Normal file
159
pkg/sdk3rd/btpanel/client.go
Normal file
@@ -0,0 +1,159 @@
|
||||
package btpanel
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiKey string
|
||||
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(serverUrl, apiKey string) (*Client, error) {
|
||||
if serverUrl == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset serverUrl")
|
||||
}
|
||||
if _, err := url.Parse(serverUrl); err != nil {
|
||||
return nil, fmt.Errorf("sdkerr: invalid serverUrl: %w", err)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiKey")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL(strings.TrimRight(serverUrl, "/")).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/x-www-form-urlencoded").
|
||||
SetHeader("User-Agent", "certimate")
|
||||
|
||||
return &Client{
|
||||
apiKey: apiKey,
|
||||
client: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) SetTLSConfig(config *tls.Config) *Client {
|
||||
c.client.SetTLSClientConfig(config)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string, params any) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
data := make(map[string]string)
|
||||
if params != nil {
|
||||
temp := make(map[string]any)
|
||||
jsonb, _ := json.Marshal(params)
|
||||
json.Unmarshal(jsonb, &temp)
|
||||
for k, v := range temp {
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
switch reflect.Indirect(reflect.ValueOf(v)).Kind() {
|
||||
case reflect.String:
|
||||
data[k] = v.(string)
|
||||
|
||||
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
|
||||
data[k] = fmt.Sprintf("%v", v)
|
||||
|
||||
default:
|
||||
if t, ok := v.(time.Time); ok {
|
||||
data[k] = t.Format(time.RFC3339)
|
||||
} else {
|
||||
jsonb, _ := json.Marshal(v)
|
||||
data[k] = string(jsonb)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timestamp := time.Now().Unix()
|
||||
data["request_time"] = fmt.Sprintf("%d", timestamp)
|
||||
data["request_token"] = generateSignature(fmt.Sprintf("%d", timestamp), c.apiKey)
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
req.SetFormData(data)
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetBody` or `req.SetFormData` HERE! USE `newRequest` INSTEAD.
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
} else {
|
||||
if tstatus := res.GetStatus(); tstatus != nil && !*tstatus {
|
||||
if res.GetMessage() == nil {
|
||||
return resp, fmt.Errorf("sdkerr: api error: unknown error")
|
||||
} else {
|
||||
return resp, fmt.Errorf("sdkerr: api error: message='%s'", *res.GetMessage())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func generateSignature(timestamp string, apiKey string) string {
|
||||
keyMd5 := md5.Sum([]byte(apiKey))
|
||||
keyMd5Hex := strings.ToLower(hex.EncodeToString(keyMd5[:]))
|
||||
|
||||
signMd5 := md5.Sum([]byte(timestamp + keyMd5Hex))
|
||||
signMd5Hex := strings.ToLower(hex.EncodeToString(signMd5[:]))
|
||||
return signMd5Hex
|
||||
}
|
||||
19
pkg/sdk3rd/btpanel/types.go
Normal file
19
pkg/sdk3rd/btpanel/types.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package btpanel
|
||||
|
||||
type apiResponse interface {
|
||||
GetStatus() *bool
|
||||
GetMessage() *string
|
||||
}
|
||||
|
||||
type apiResponseBase struct {
|
||||
Status *bool `json:"status,omitempty"`
|
||||
Message *string `json:"msg,omitempty"`
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetStatus() *bool {
|
||||
return r.Status
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetMessage() *string {
|
||||
return r.Message
|
||||
}
|
||||
36
pkg/sdk3rd/btwaf/api_config_set_cert.go
Normal file
36
pkg/sdk3rd/btwaf/api_config_set_cert.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package btwaf
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ConfigSetCertRequest struct {
|
||||
CertContent *string `json:"certContent,omitempty"`
|
||||
KeyContent *string `json:"keyContent,omitempty"`
|
||||
}
|
||||
|
||||
type ConfigSetCertResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) ConfigSetCert(req *ConfigSetCertRequest) (*ConfigSetCertResponse, error) {
|
||||
return c.ConfigSetCertWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) ConfigSetCertWithContext(ctx context.Context, req *ConfigSetCertRequest) (*ConfigSetCertResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/config/set_cert")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &ConfigSetCertResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/sdk3rd/btwaf/api_get_site_list.go
Normal file
42
pkg/sdk3rd/btwaf/api_get_site_list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package btwaf
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetSiteListRequest struct {
|
||||
Page *int32 `json:"p,omitempty"`
|
||||
PageSize *int32 `json:"p_size,omitempty"`
|
||||
SiteName *string `json:"site_name,omitempty"`
|
||||
}
|
||||
|
||||
type GetSiteListResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Result *struct {
|
||||
List []*SiteRecord `json:"list"`
|
||||
Total int32 `json:"total"`
|
||||
} `json:"res,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) GetSiteList(req *GetSiteListRequest) (*GetSiteListResponse, error) {
|
||||
return c.GetSiteListWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) GetSiteListWithContext(ctx context.Context, req *GetSiteListRequest) (*GetSiteListResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/wafmastersite/get_site_list")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &GetSiteListResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
37
pkg/sdk3rd/btwaf/api_modify_site.go
Normal file
37
pkg/sdk3rd/btwaf/api_modify_site.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package btwaf
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ModifySiteRequest struct {
|
||||
SiteId *string `json:"site_id,omitempty"`
|
||||
Type *string `json:"types,omitempty"`
|
||||
Server *SiteServerInfo `json:"server,omitempty"`
|
||||
}
|
||||
|
||||
type ModifySiteResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) ModifySite(req *ModifySiteRequest) (*ModifySiteResponse, error) {
|
||||
return c.ModifySiteWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) ModifySiteWithContext(ctx context.Context, req *ModifySiteRequest) (*ModifySiteResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/wafmastersite/modify_site")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &ModifySiteResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
118
pkg/sdk3rd/btwaf/client.go
Normal file
118
pkg/sdk3rd/btwaf/client.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package btwaf
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(serverUrl, apiKey string) (*Client, error) {
|
||||
if serverUrl == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset serverUrl")
|
||||
}
|
||||
if _, err := url.Parse(serverUrl); err != nil {
|
||||
return nil, fmt.Errorf("sdkerr: invalid serverUrl: %w", err)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiKey")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetPreRequestHook(func(c *resty.Client, req *http.Request) error {
|
||||
timestamp := fmt.Sprintf("%d", time.Now().Unix())
|
||||
keyMd5 := md5.Sum([]byte(apiKey))
|
||||
keyMd5Hex := strings.ToLower(hex.EncodeToString(keyMd5[:]))
|
||||
signMd5 := md5.Sum([]byte(timestamp + keyMd5Hex))
|
||||
signMd5Hex := strings.ToLower(hex.EncodeToString(signMd5[:]))
|
||||
req.Header.Set("waf_request_time", timestamp)
|
||||
req.Header.Set("waf_request_token", signMd5Hex)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) SetTLSConfig(config *tls.Config) *Client {
|
||||
c.client.SetTLSClientConfig(config)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
} else {
|
||||
if code := res.GetCode(); code != 0 {
|
||||
return resp, fmt.Errorf("sdkerr: api error: code='%d'", code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
39
pkg/sdk3rd/btwaf/types.go
Normal file
39
pkg/sdk3rd/btwaf/types.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package btwaf
|
||||
|
||||
type apiResponse interface {
|
||||
GetCode() int32
|
||||
}
|
||||
|
||||
type apiResponseBase struct {
|
||||
Code *int32 `json:"code,omitempty"`
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetCode() int32 {
|
||||
if r.Code == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return *r.Code
|
||||
}
|
||||
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
|
||||
type SiteRecord struct {
|
||||
SiteId string `json:"site_id"`
|
||||
SiteName string `json:"site_name"`
|
||||
Type string `json:"types"`
|
||||
Status int32 `json:"status"`
|
||||
CreateTime int64 `json:"create_time"`
|
||||
UpdateTime int64 `json:"update_time"`
|
||||
}
|
||||
|
||||
type SiteServerInfo struct {
|
||||
ListenSSLPorts *[]int32 `json:"listen_ssl_port,omitempty"`
|
||||
SSL *SiteServerSSLInfo `json:"ssl,omitempty"`
|
||||
}
|
||||
|
||||
type SiteServerSSLInfo struct {
|
||||
IsSSL *int32 `json:"is_ssl,omitempty"`
|
||||
FullChain *string `json:"full_chain,omitempty"`
|
||||
PrivateKey *string `json:"private_key,omitempty"`
|
||||
}
|
||||
38
pkg/sdk3rd/bunny/api_add_custom_certificate.go
Normal file
38
pkg/sdk3rd/bunny/api_add_custom_certificate.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package bunny
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type AddCustomCertificateRequest struct {
|
||||
Hostname string `json:"Hostname"`
|
||||
Certificate string `json:"Certificate"`
|
||||
CertificateKey string `json:"CertificateKey"`
|
||||
}
|
||||
|
||||
func (c *Client) AddCustomCertificate(pullZoneId string, req *AddCustomCertificateRequest) error {
|
||||
return c.AddCustomCertificateWithContext(context.Background(), pullZoneId, req)
|
||||
}
|
||||
|
||||
func (c *Client) AddCustomCertificateWithContext(ctx context.Context, pullZoneId string, req *AddCustomCertificateRequest) error {
|
||||
if pullZoneId == "" {
|
||||
return fmt.Errorf("sdkerr: unset pullZoneId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodPost, fmt.Sprintf("/pullzone/%s/addCertificate", url.PathEscape(pullZoneId)))
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
if _, err := c.doRequest(httpreq); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
64
pkg/sdk3rd/bunny/client.go
Normal file
64
pkg/sdk3rd/bunny/client.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package bunny
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(apiToken string) (*Client, error) {
|
||||
if apiToken == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiToken")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL("https://api.bunny.net").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetHeader("AccessKey", apiToken)
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
50
pkg/sdk3rd/cachefly/api_create_certificate.go
Normal file
50
pkg/sdk3rd/cachefly/api_create_certificate.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package cachefly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CreateCertificateRequest struct {
|
||||
Certificate *string `json:"certificate,omitempty"`
|
||||
CertificateKey *string `json:"certificateKey,omitempty"`
|
||||
Password *string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
type CreateCertificateResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Id string `json:"_id"`
|
||||
SubjectCommonName string `json:"subjectCommonName"`
|
||||
SubjectNames []string `json:"subjectNames"`
|
||||
Expired bool `json:"expired"`
|
||||
Expiring bool `json:"expiring"`
|
||||
InUse bool `json:"inUse"`
|
||||
Managed bool `json:"managed"`
|
||||
Services []string `json:"services"`
|
||||
Domains []string `json:"domains"`
|
||||
NotBefore string `json:"notBefore"`
|
||||
NotAfter string `json:"notAfter"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||
return c.CreateCertificateWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) CreateCertificateWithContext(ctx context.Context, req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/certificates")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &CreateCertificateResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
87
pkg/sdk3rd/cachefly/client.go
Normal file
87
pkg/sdk3rd/cachefly/client.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package cachefly
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(apiToken string) (*Client, error) {
|
||||
if apiToken == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiToken")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL("https://api.cachefly.com/api/2.5").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetHeader("X-CF-Authorization", "Bearer "+apiToken)
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
19
pkg/sdk3rd/cachefly/types.go
Normal file
19
pkg/sdk3rd/cachefly/types.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package cachefly
|
||||
|
||||
type apiResponse interface {
|
||||
GetMessage() string
|
||||
}
|
||||
|
||||
type apiResponseBase struct {
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetMessage() string {
|
||||
if r.Message == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return *r.Message
|
||||
}
|
||||
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
41
pkg/sdk3rd/cdnfly/api_create_cert.go
Normal file
41
pkg/sdk3rd/cdnfly/api_create_cert.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cdnfly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CreateCertRequest struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"des,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Cert *string `json:"cert,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
}
|
||||
|
||||
type CreateCertResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateCert(req *CreateCertRequest) (*CreateCertResponse, error) {
|
||||
return c.CreateCertWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) CreateCertWithContext(ctx context.Context, req *CreateCertRequest) (*CreateCertResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/certs")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &CreateCertResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/sdk3rd/cdnfly/api_get_site.go
Normal file
43
pkg/sdk3rd/cdnfly/api_get_site.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package cdnfly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type GetSiteResponse struct {
|
||||
apiResponseBase
|
||||
|
||||
Data *struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Domain string `json:"domain"`
|
||||
HttpsListen string `json:"https_listen"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) GetSite(siteId string) (*GetSiteResponse, error) {
|
||||
return c.GetSiteWithContext(context.Background(), siteId)
|
||||
}
|
||||
|
||||
func (c *Client) GetSiteWithContext(ctx context.Context, siteId string) (*GetSiteResponse, error) {
|
||||
if siteId == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset siteId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodGet, fmt.Sprintf("/sites/%s", url.PathEscape(siteId)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &GetSiteResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
46
pkg/sdk3rd/cdnfly/api_update_cert.go
Normal file
46
pkg/sdk3rd/cdnfly/api_update_cert.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package cdnfly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type UpdateCertRequest struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"des,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Cert *string `json:"cert,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateCertResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCert(certId string, req *UpdateCertRequest) (*UpdateCertResponse, error) {
|
||||
return c.UpdateCertWithContext(context.Background(), certId, req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCertWithContext(ctx context.Context, certId string, req *UpdateCertRequest) (*UpdateCertResponse, error) {
|
||||
if certId == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset certId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodPut, fmt.Sprintf("/certs/%s", url.PathEscape(certId)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateCertResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/sdk3rd/cdnfly/api_update_site.go
Normal file
42
pkg/sdk3rd/cdnfly/api_update_site.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package cdnfly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type UpdateSiteRequest struct {
|
||||
HttpsListen *string `json:"https_listen,omitempty"`
|
||||
Enable *bool `json:"enable,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateSiteResponse struct {
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateSite(siteId string, req *UpdateSiteRequest) (*UpdateSiteResponse, error) {
|
||||
return c.UpdateSiteWithContext(context.Background(), siteId, req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateSiteWithContext(ctx context.Context, siteId string, req *UpdateSiteRequest) (*UpdateSiteResponse, error) {
|
||||
if siteId == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset siteId")
|
||||
}
|
||||
|
||||
httpreq, err := c.newRequest(http.MethodPut, fmt.Sprintf("/sites/%s", url.PathEscape(siteId)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &UpdateSiteResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
109
pkg/sdk3rd/cdnfly/client.go
Normal file
109
pkg/sdk3rd/cdnfly/client.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package cdnfly
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(serverUrl, apiKey, apiSecret string) (*Client, error) {
|
||||
if serverUrl == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset serverUrl")
|
||||
}
|
||||
if _, err := url.Parse(serverUrl); err != nil {
|
||||
return nil, fmt.Errorf("sdkerr: invalid serverUrl: %w", err)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiKey")
|
||||
}
|
||||
if apiSecret == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset apiSecret")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
SetBaseURL(strings.TrimRight(serverUrl, "/")+"/v1").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", "certimate").
|
||||
SetHeader("API-Key", apiKey).
|
||||
SetHeader("API-Secret", apiSecret)
|
||||
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) SetTLSConfig(config *tls.Config) *Client {
|
||||
c.client.SetTLSClientConfig(config)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset path")
|
||||
}
|
||||
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("sdkerr: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
} else {
|
||||
if tcode := res.GetCode(); tcode != "" && tcode != "0" {
|
||||
return resp, fmt.Errorf("sdkerr: code='%s', message='%s'", tcode, res.GetMessage())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
46
pkg/sdk3rd/cdnfly/types.go
Normal file
46
pkg/sdk3rd/cdnfly/types.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package cdnfly
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type apiResponse interface {
|
||||
GetCode() string
|
||||
GetMessage() string
|
||||
}
|
||||
|
||||
type apiResponseBase struct {
|
||||
Code json.RawMessage `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetCode() string {
|
||||
if r.Code == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(bytes.NewReader(r.Code))
|
||||
token, err := decoder.Token()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
switch t := token.(type) {
|
||||
case string:
|
||||
return t
|
||||
case float64:
|
||||
return strconv.FormatFloat(t, 'f', -1, 64)
|
||||
case json.Number:
|
||||
return t.String()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (r *apiResponseBase) GetMessage() string {
|
||||
return r.Message
|
||||
}
|
||||
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
13
pkg/sdk3rd/cmcc/README.md
Normal file
13
pkg/sdk3rd/cmcc/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
移动云 Go SDK 文档: [https://ecloud.10086.cn/op-help-center/doc/article/53799](https://ecloud.10086.cn/op-help-center/doc/article/53799)
|
||||
|
||||
移动云 Go SDK 下载地址: [https://ecloud.10086.cn/api/query/developer/nexus/service/rest/repository/browse/go-sdk/gitlab.ecloud.com/ecloud/](https://ecloud.10086.cn/api/query/developer/nexus/service/rest/repository/browse/go-sdk/gitlab.ecloud.com/ecloud/)
|
||||
|
||||
---
|
||||
|
||||
将其引入本地目录的原因是:
|
||||
|
||||
1. 原始包必须通过移动云私有仓库获取, 为构建带来不便。
|
||||
2. 原始包存在部分内容错误, 需要自行修改, 如:
|
||||
- 存在一些编译错误;
|
||||
- 返回错误的时候, 未返回错误信息;
|
||||
- 解析响应体错误。
|
||||
144
pkg/sdk3rd/cmcc/ecloudsdkclouddns@v1.0.1/client.go
Normal file
144
pkg/sdk3rd/cmcc/ecloudsdkclouddns@v1.0.1/client.go
Normal file
@@ -0,0 +1,144 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package ecloudsdkclouddns
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkclouddns/model"
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore"
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/config"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
APIClient *ecloudsdkcore.APIClient
|
||||
config *config.Config
|
||||
httpRequest *ecloudsdkcore.HttpRequest
|
||||
}
|
||||
|
||||
func NewClient(config *config.Config) *Client {
|
||||
client := &Client{}
|
||||
client.config = config
|
||||
apiClient := ecloudsdkcore.NewAPIClient()
|
||||
httpRequest := ecloudsdkcore.NewDefaultHttpRequest()
|
||||
httpRequest.Product = product
|
||||
httpRequest.Version = version
|
||||
httpRequest.SdkVersion = sdkVersion
|
||||
client.httpRequest = httpRequest
|
||||
client.APIClient = apiClient
|
||||
return client
|
||||
}
|
||||
|
||||
func NewClientByCustomized(config *config.Config, httpRequest *ecloudsdkcore.HttpRequest) *Client {
|
||||
client := &Client{}
|
||||
client.config = config
|
||||
apiClient := ecloudsdkcore.NewAPIClient()
|
||||
httpRequest.Product = product
|
||||
httpRequest.Version = version
|
||||
httpRequest.SdkVersion = sdkVersion
|
||||
client.httpRequest = httpRequest
|
||||
client.APIClient = apiClient
|
||||
return client
|
||||
}
|
||||
|
||||
const (
|
||||
product string = "clouddns"
|
||||
version string = "v1"
|
||||
sdkVersion string = "1.0.1"
|
||||
)
|
||||
|
||||
// CreateRecord 新增解析记录
|
||||
func (c *Client) CreateRecord(request *model.CreateRecordRequest) (*model.CreateRecordResponse, error) {
|
||||
c.httpRequest.Action = "createRecord"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.CreateRecordResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// CreateRecordOpenapi 新增解析记录Openapi
|
||||
func (c *Client) CreateRecordOpenapi(request *model.CreateRecordOpenapiRequest) (*model.CreateRecordOpenapiResponse, error) {
|
||||
c.httpRequest.Action = "createRecordOpenapi"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.CreateRecordOpenapiResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteRecord 删除解析记录
|
||||
func (c *Client) DeleteRecord(request *model.DeleteRecordRequest) (*model.DeleteRecordResponse, error) {
|
||||
c.httpRequest.Action = "deleteRecord"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.DeleteRecordResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteRecordOpenapi 删除解析记录Openapi
|
||||
func (c *Client) DeleteRecordOpenapi(request *model.DeleteRecordOpenapiRequest) (*model.DeleteRecordOpenapiResponse, error) {
|
||||
c.httpRequest.Action = "deleteRecordOpenapi"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.DeleteRecordOpenapiResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ListRecord 查询解析记录
|
||||
func (c *Client) ListRecord(request *model.ListRecordRequest) (*model.ListRecordResponse, error) {
|
||||
c.httpRequest.Action = "listRecord"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.ListRecordResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ListRecordOpenapi 查询解析记录Openapi
|
||||
func (c *Client) ListRecordOpenapi(request *model.ListRecordOpenapiRequest) (*model.ListRecordOpenapiResponse, error) {
|
||||
c.httpRequest.Action = "listRecordOpenapi"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.ListRecordOpenapiResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ModifyRecord 修改解析记录
|
||||
func (c *Client) ModifyRecord(request *model.ModifyRecordRequest) (*model.ModifyRecordResponse, error) {
|
||||
c.httpRequest.Action = "modifyRecord"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.ModifyRecordResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ModifyRecordOpenapi 修改解析记录Openapi
|
||||
func (c *Client) ModifyRecordOpenapi(request *model.ModifyRecordOpenapiRequest) (*model.ModifyRecordOpenapiResponse, error) {
|
||||
c.httpRequest.Action = "modifyRecordOpenapi"
|
||||
c.httpRequest.Body = request
|
||||
returnValue := &model.ModifyRecordOpenapiResponse{}
|
||||
if _, err := c.APIClient.Excute(c.httpRequest, c.config, returnValue); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return returnValue, nil
|
||||
}
|
||||
}
|
||||
7
pkg/sdk3rd/cmcc/ecloudsdkclouddns@v1.0.1/go.mod
Normal file
7
pkg/sdk3rd/cmcc/ecloudsdkclouddns@v1.0.1/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module gitlab.ecloud.com/ecloud/ecloudsdkclouddns
|
||||
|
||||
go 1.24.0
|
||||
|
||||
require gitlab.ecloud.com/ecloud/ecloudsdkcore v1.0.0
|
||||
|
||||
replace gitlab.ecloud.com/ecloud/ecloudsdkcore v1.0.0 => ../ecloudsdkcore@v1.0.0
|
||||
@@ -0,0 +1,55 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type CreateRecordBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
CreateRecordBodyTypeEnumA CreateRecordBodyTypeEnum = "A"
|
||||
CreateRecordBodyTypeEnumAaaa CreateRecordBodyTypeEnum = "AAAA"
|
||||
CreateRecordBodyTypeEnumCaa CreateRecordBodyTypeEnum = "CAA"
|
||||
CreateRecordBodyTypeEnumCmauth CreateRecordBodyTypeEnum = "CMAUTH"
|
||||
CreateRecordBodyTypeEnumCname CreateRecordBodyTypeEnum = "CNAME"
|
||||
CreateRecordBodyTypeEnumMx CreateRecordBodyTypeEnum = "MX"
|
||||
CreateRecordBodyTypeEnumNs CreateRecordBodyTypeEnum = "NS"
|
||||
CreateRecordBodyTypeEnumPtr CreateRecordBodyTypeEnum = "PTR"
|
||||
CreateRecordBodyTypeEnumRp CreateRecordBodyTypeEnum = "RP"
|
||||
CreateRecordBodyTypeEnumSpf CreateRecordBodyTypeEnum = "SPF"
|
||||
CreateRecordBodyTypeEnumSrv CreateRecordBodyTypeEnum = "SRV"
|
||||
CreateRecordBodyTypeEnumTxt CreateRecordBodyTypeEnum = "TXT"
|
||||
CreateRecordBodyTypeEnumUrl CreateRecordBodyTypeEnum = "URL"
|
||||
)
|
||||
|
||||
type CreateRecordBody struct {
|
||||
position.Body
|
||||
// 主机头
|
||||
Rr string `json:"rr"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId"`
|
||||
|
||||
// MX优先级,若“记录类型”选择”MX”,则需要配置该参数,默认是5
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type CreateRecordBodyTypeEnum `json:"type"`
|
||||
|
||||
// 缓存的生命周期,默认可配置600s
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value"`
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type CreateRecordOpenapiBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
CreateRecordOpenapiBodyTypeEnumA CreateRecordOpenapiBodyTypeEnum = "A"
|
||||
CreateRecordOpenapiBodyTypeEnumAaaa CreateRecordOpenapiBodyTypeEnum = "AAAA"
|
||||
CreateRecordOpenapiBodyTypeEnumCname CreateRecordOpenapiBodyTypeEnum = "CNAME"
|
||||
CreateRecordOpenapiBodyTypeEnumMx CreateRecordOpenapiBodyTypeEnum = "MX"
|
||||
CreateRecordOpenapiBodyTypeEnumTxt CreateRecordOpenapiBodyTypeEnum = "TXT"
|
||||
CreateRecordOpenapiBodyTypeEnumNs CreateRecordOpenapiBodyTypeEnum = "NS"
|
||||
CreateRecordOpenapiBodyTypeEnumSpf CreateRecordOpenapiBodyTypeEnum = "SPF"
|
||||
CreateRecordOpenapiBodyTypeEnumSrv CreateRecordOpenapiBodyTypeEnum = "SRV"
|
||||
CreateRecordOpenapiBodyTypeEnumCaa CreateRecordOpenapiBodyTypeEnum = "CAA"
|
||||
CreateRecordOpenapiBodyTypeEnumCmauth CreateRecordOpenapiBodyTypeEnum = "CMAUTH"
|
||||
)
|
||||
|
||||
type CreateRecordOpenapiBody struct {
|
||||
position.Body
|
||||
// 主机头
|
||||
Rr string `json:"rr"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId"`
|
||||
|
||||
// MX优先级,若“记录类型”选择”MX”,则需要配置该参数,默认是5
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type CreateRecordOpenapiBodyTypeEnum `json:"type"`
|
||||
|
||||
// 缓存的生命周期,默认可配置600s
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value"`
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordOpenapiRequest struct {
|
||||
CreateRecordOpenapiBody *CreateRecordOpenapiBody `json:"createRecordOpenapiBody,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordOpenapiResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
CreateRecordOpenapiResponseStateEnumError CreateRecordOpenapiResponseStateEnum = "ERROR"
|
||||
CreateRecordOpenapiResponseStateEnumException CreateRecordOpenapiResponseStateEnum = "EXCEPTION"
|
||||
CreateRecordOpenapiResponseStateEnumForbidden CreateRecordOpenapiResponseStateEnum = "FORBIDDEN"
|
||||
CreateRecordOpenapiResponseStateEnumOk CreateRecordOpenapiResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type CreateRecordOpenapiResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State CreateRecordOpenapiResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *CreateRecordOpenapiResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordOpenapiResponseBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
CreateRecordOpenapiResponseBodyTypeEnumA CreateRecordOpenapiResponseBodyTypeEnum = "A"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumAaaa CreateRecordOpenapiResponseBodyTypeEnum = "AAAA"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumCname CreateRecordOpenapiResponseBodyTypeEnum = "CNAME"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumMx CreateRecordOpenapiResponseBodyTypeEnum = "MX"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumTxt CreateRecordOpenapiResponseBodyTypeEnum = "TXT"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumNs CreateRecordOpenapiResponseBodyTypeEnum = "NS"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumSpf CreateRecordOpenapiResponseBodyTypeEnum = "SPF"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumSrv CreateRecordOpenapiResponseBodyTypeEnum = "SRV"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumCaa CreateRecordOpenapiResponseBodyTypeEnum = "CAA"
|
||||
CreateRecordOpenapiResponseBodyTypeEnumCmauth CreateRecordOpenapiResponseBodyTypeEnum = "CMAUTH"
|
||||
)
|
||||
|
||||
type CreateRecordOpenapiResponseBodyStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
CreateRecordOpenapiResponseBodyStateEnumDisabled CreateRecordOpenapiResponseBodyStateEnum = "DISABLED"
|
||||
CreateRecordOpenapiResponseBodyStateEnumEnabled CreateRecordOpenapiResponseBodyStateEnum = "ENABLED"
|
||||
)
|
||||
|
||||
type CreateRecordOpenapiResponseBody struct {
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 修改时间
|
||||
ModifiedTime string `json:"modifiedTime,omitempty"`
|
||||
|
||||
// 线路中文名
|
||||
LineZh string `json:"lineZh,omitempty"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// 权重值
|
||||
Weight *int32 `json:"weight,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type CreateRecordOpenapiResponseBodyTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 标签
|
||||
Tags *[]CreateRecordOpenapiResponseTags `json:"tags,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
|
||||
// 线路英文名
|
||||
LineEn string `json:"lineEn,omitempty"`
|
||||
|
||||
// 状态
|
||||
State CreateRecordOpenapiResponseBodyStateEnum `json:"state,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
|
||||
// 定时发布时间
|
||||
Pubdate string `json:"pubdate,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordOpenapiResponseTags struct {
|
||||
// 标签ID
|
||||
TagId string `json:"tagId,omitempty"`
|
||||
|
||||
// 标签名称
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordRequest struct {
|
||||
CreateRecordBody *CreateRecordBody `json:"createRecordBody,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
CreateRecordResponseStateEnumError CreateRecordResponseStateEnum = "ERROR"
|
||||
CreateRecordResponseStateEnumException CreateRecordResponseStateEnum = "EXCEPTION"
|
||||
CreateRecordResponseStateEnumForbidden CreateRecordResponseStateEnum = "FORBIDDEN"
|
||||
CreateRecordResponseStateEnumOk CreateRecordResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type CreateRecordResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State CreateRecordResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *CreateRecordResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordResponseBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
CreateRecordResponseBodyTypeEnumA CreateRecordResponseBodyTypeEnum = "A"
|
||||
CreateRecordResponseBodyTypeEnumAaaa CreateRecordResponseBodyTypeEnum = "AAAA"
|
||||
CreateRecordResponseBodyTypeEnumCaa CreateRecordResponseBodyTypeEnum = "CAA"
|
||||
CreateRecordResponseBodyTypeEnumCmauth CreateRecordResponseBodyTypeEnum = "CMAUTH"
|
||||
CreateRecordResponseBodyTypeEnumCname CreateRecordResponseBodyTypeEnum = "CNAME"
|
||||
CreateRecordResponseBodyTypeEnumMx CreateRecordResponseBodyTypeEnum = "MX"
|
||||
CreateRecordResponseBodyTypeEnumNs CreateRecordResponseBodyTypeEnum = "NS"
|
||||
CreateRecordResponseBodyTypeEnumPtr CreateRecordResponseBodyTypeEnum = "PTR"
|
||||
CreateRecordResponseBodyTypeEnumRp CreateRecordResponseBodyTypeEnum = "RP"
|
||||
CreateRecordResponseBodyTypeEnumSpf CreateRecordResponseBodyTypeEnum = "SPF"
|
||||
CreateRecordResponseBodyTypeEnumSrv CreateRecordResponseBodyTypeEnum = "SRV"
|
||||
CreateRecordResponseBodyTypeEnumTxt CreateRecordResponseBodyTypeEnum = "TXT"
|
||||
CreateRecordResponseBodyTypeEnumUrl CreateRecordResponseBodyTypeEnum = "URL"
|
||||
)
|
||||
|
||||
type CreateRecordResponseBodyTimedStatusEnum string
|
||||
|
||||
// List of TimedStatus
|
||||
const (
|
||||
CreateRecordResponseBodyTimedStatusEnumDisabled CreateRecordResponseBodyTimedStatusEnum = "DISABLED"
|
||||
CreateRecordResponseBodyTimedStatusEnumEnabled CreateRecordResponseBodyTimedStatusEnum = "ENABLED"
|
||||
CreateRecordResponseBodyTimedStatusEnumTimed CreateRecordResponseBodyTimedStatusEnum = "TIMED"
|
||||
)
|
||||
|
||||
type CreateRecordResponseBodyStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
CreateRecordResponseBodyStateEnumDisabled CreateRecordResponseBodyStateEnum = "DISABLED"
|
||||
CreateRecordResponseBodyStateEnumEnabled CreateRecordResponseBodyStateEnum = "ENABLED"
|
||||
)
|
||||
|
||||
type CreateRecordResponseBody struct {
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 修改时间
|
||||
ModifiedTime string `json:"modifiedTime,omitempty"`
|
||||
|
||||
// 线路中文名
|
||||
LineZh string `json:"lineZh,omitempty"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// 权重值
|
||||
Weight *int32 `json:"weight,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type CreateRecordResponseBodyTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 标签
|
||||
Tags *[]CreateRecordResponseTags `json:"tags,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 定时状态
|
||||
TimedStatus CreateRecordResponseBodyTimedStatusEnum `json:"timedStatus,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
|
||||
// 线路英文名
|
||||
LineEn string `json:"lineEn,omitempty"`
|
||||
|
||||
// 状态
|
||||
State CreateRecordResponseBodyStateEnum `json:"state,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
|
||||
// 定时发布时间
|
||||
Pubdate string `json:"pubdate,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type CreateRecordResponseTags struct {
|
||||
// 标签ID
|
||||
TagId string `json:"tagId,omitempty"`
|
||||
|
||||
// 标签名称
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type DeleteRecordBody struct {
|
||||
position.Body
|
||||
// 解析记录ID列表
|
||||
RecordIdList []string `json:"recordIdList"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type DeleteRecordOpenapiBody struct {
|
||||
position.Body
|
||||
// 待删除的解析记录ID请求体
|
||||
RecordIdList []string `json:"recordIdList"`
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type DeleteRecordOpenapiRequest struct {
|
||||
DeleteRecordOpenapiBody *DeleteRecordOpenapiBody `json:"deleteRecordOpenapiBody,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type DeleteRecordOpenapiResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
DeleteRecordOpenapiResponseStateEnumError DeleteRecordOpenapiResponseStateEnum = "ERROR"
|
||||
DeleteRecordOpenapiResponseStateEnumException DeleteRecordOpenapiResponseStateEnum = "EXCEPTION"
|
||||
DeleteRecordOpenapiResponseStateEnumForbidden DeleteRecordOpenapiResponseStateEnum = "FORBIDDEN"
|
||||
DeleteRecordOpenapiResponseStateEnumOk DeleteRecordOpenapiResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type DeleteRecordOpenapiResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State DeleteRecordOpenapiResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *[]DeleteRecordOpenapiResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type DeleteRecordOpenapiResponseBodyCodeEnum string
|
||||
|
||||
// List of Code
|
||||
const (
|
||||
DeleteRecordOpenapiResponseBodyCodeEnumError DeleteRecordOpenapiResponseBodyCodeEnum = "ERROR"
|
||||
DeleteRecordOpenapiResponseBodyCodeEnumSuccess DeleteRecordOpenapiResponseBodyCodeEnum = "SUCCESS"
|
||||
)
|
||||
|
||||
type DeleteRecordOpenapiResponseBody struct {
|
||||
// 结果说明
|
||||
Msg string `json:"msg,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 结果码
|
||||
Code DeleteRecordOpenapiResponseBodyCodeEnum `json:"code,omitempty"`
|
||||
|
||||
// 域名
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type DeleteRecordRequest struct {
|
||||
DeleteRecordBody *DeleteRecordBody `json:"deleteRecordBody,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type DeleteRecordResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
DeleteRecordResponseStateEnumError DeleteRecordResponseStateEnum = "ERROR"
|
||||
DeleteRecordResponseStateEnumException DeleteRecordResponseStateEnum = "EXCEPTION"
|
||||
DeleteRecordResponseStateEnumForbidden DeleteRecordResponseStateEnum = "FORBIDDEN"
|
||||
DeleteRecordResponseStateEnumOk DeleteRecordResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type DeleteRecordResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State DeleteRecordResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *[]DeleteRecordResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type DeleteRecordResponseBodyCodeEnum string
|
||||
|
||||
// List of Code
|
||||
const (
|
||||
DeleteRecordResponseBodyCodeEnumError DeleteRecordResponseBodyCodeEnum = "ERROR"
|
||||
DeleteRecordResponseBodyCodeEnumSuccess DeleteRecordResponseBodyCodeEnum = "SUCCESS"
|
||||
)
|
||||
|
||||
type DeleteRecordResponseBody struct {
|
||||
// 结果说明
|
||||
Msg string `json:"msg,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 结果码
|
||||
Code DeleteRecordResponseBodyCodeEnum `json:"code,omitempty"`
|
||||
|
||||
// 域名
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type ListRecordBody struct {
|
||||
position.Body
|
||||
// 域名
|
||||
DomainName string `json:"domainName"`
|
||||
|
||||
// 可以匹配主机头rr、记录值value、备注description,并且是模糊搜索
|
||||
DataLike string `json:"dataLike,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type ListRecordOpenapiBody struct {
|
||||
position.Body
|
||||
// 域名
|
||||
DomainName string `json:"domainName"`
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type ListRecordOpenapiQuery struct {
|
||||
position.Query
|
||||
// 页大小
|
||||
PageSize *int32 `json:"pageSize,omitempty"`
|
||||
|
||||
// 当前页
|
||||
Page *int32 `json:"page,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordOpenapiRequest struct {
|
||||
ListRecordOpenapiQuery *ListRecordOpenapiQuery `json:"listRecordOpenapiQuery,omitempty"`
|
||||
|
||||
ListRecordOpenapiBody *ListRecordOpenapiBody `json:"listRecordOpenapiBody,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordOpenapiResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ListRecordOpenapiResponseStateEnumError ListRecordOpenapiResponseStateEnum = "ERROR"
|
||||
ListRecordOpenapiResponseStateEnumException ListRecordOpenapiResponseStateEnum = "EXCEPTION"
|
||||
ListRecordOpenapiResponseStateEnumForbidden ListRecordOpenapiResponseStateEnum = "FORBIDDEN"
|
||||
ListRecordOpenapiResponseStateEnumOk ListRecordOpenapiResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type ListRecordOpenapiResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State ListRecordOpenapiResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *ListRecordOpenapiResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordOpenapiResponseBody struct {
|
||||
// 当前页的具体数据列表
|
||||
Data *[]ListRecordOpenapiResponseData `json:"data,omitempty"`
|
||||
|
||||
// 总数据量
|
||||
TotalNum *int32 `json:"totalNum,omitempty"`
|
||||
|
||||
// 总页数
|
||||
TotalPages *int32 `json:"totalPages,omitempty"`
|
||||
|
||||
// 页大小
|
||||
PageSize *int32 `json:"pageSize,omitempty"`
|
||||
|
||||
// 当前页码,从0开始,0表示第一页
|
||||
Page *int32 `json:"page,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordOpenapiResponseDataTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
ListRecordOpenapiResponseDataTypeEnumA ListRecordOpenapiResponseDataTypeEnum = "A"
|
||||
ListRecordOpenapiResponseDataTypeEnumAaaa ListRecordOpenapiResponseDataTypeEnum = "AAAA"
|
||||
ListRecordOpenapiResponseDataTypeEnumCname ListRecordOpenapiResponseDataTypeEnum = "CNAME"
|
||||
ListRecordOpenapiResponseDataTypeEnumMx ListRecordOpenapiResponseDataTypeEnum = "MX"
|
||||
ListRecordOpenapiResponseDataTypeEnumTxt ListRecordOpenapiResponseDataTypeEnum = "TXT"
|
||||
ListRecordOpenapiResponseDataTypeEnumNs ListRecordOpenapiResponseDataTypeEnum = "NS"
|
||||
ListRecordOpenapiResponseDataTypeEnumSpf ListRecordOpenapiResponseDataTypeEnum = "SPF"
|
||||
ListRecordOpenapiResponseDataTypeEnumSrv ListRecordOpenapiResponseDataTypeEnum = "SRV"
|
||||
ListRecordOpenapiResponseDataTypeEnumCaa ListRecordOpenapiResponseDataTypeEnum = "CAA"
|
||||
ListRecordOpenapiResponseDataTypeEnumCmauth ListRecordOpenapiResponseDataTypeEnum = "CMAUTH"
|
||||
)
|
||||
|
||||
type ListRecordOpenapiResponseDataTimedStatusEnum string
|
||||
|
||||
// List of TimedStatus
|
||||
const (
|
||||
ListRecordOpenapiResponseDataTimedStatusEnumDisabled ListRecordOpenapiResponseDataTimedStatusEnum = "DISABLED"
|
||||
ListRecordOpenapiResponseDataTimedStatusEnumEnabled ListRecordOpenapiResponseDataTimedStatusEnum = "ENABLED"
|
||||
ListRecordOpenapiResponseDataTimedStatusEnumTimed ListRecordOpenapiResponseDataTimedStatusEnum = "TIMED"
|
||||
)
|
||||
|
||||
type ListRecordOpenapiResponseDataStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ListRecordOpenapiResponseDataStateEnumDisabled ListRecordOpenapiResponseDataStateEnum = "DISABLED"
|
||||
ListRecordOpenapiResponseDataStateEnumEnabled ListRecordOpenapiResponseDataStateEnum = "ENABLED"
|
||||
)
|
||||
|
||||
type ListRecordOpenapiResponseData struct {
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 修改时间
|
||||
ModifiedTime string `json:"modifiedTime,omitempty"`
|
||||
|
||||
// 线路中文名
|
||||
LineZh string `json:"lineZh,omitempty"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// 权重值
|
||||
Weight *int32 `json:"weight,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type ListRecordOpenapiResponseDataTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 标签
|
||||
Tags *[]ListRecordOpenapiResponseTags `json:"tags,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 定时状态
|
||||
TimedStatus ListRecordOpenapiResponseDataTimedStatusEnum `json:"timedStatus,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
|
||||
// 线路英文名
|
||||
LineEn string `json:"lineEn,omitempty"`
|
||||
|
||||
// 状态
|
||||
State ListRecordOpenapiResponseDataStateEnum `json:"state,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
|
||||
// 定时发布时间
|
||||
Pubdate string `json:"pubdate,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordOpenapiResponseTags struct {
|
||||
// 标签ID
|
||||
TagId string `json:"tagId,omitempty"`
|
||||
|
||||
// 标签名称
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type ListRecordQuery struct {
|
||||
position.Query
|
||||
// 页大小
|
||||
PageSize *int32 `json:"pageSize,omitempty"`
|
||||
|
||||
// 当前页
|
||||
CurrentPage *int32 `json:"currentPage,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordRequest struct {
|
||||
ListRecordBody *ListRecordBody `json:"listRecordBody,omitempty"`
|
||||
|
||||
ListRecordQuery *ListRecordQuery `json:"listRecordQuery,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ListRecordResponseStateEnumError ListRecordResponseStateEnum = "ERROR"
|
||||
ListRecordResponseStateEnumException ListRecordResponseStateEnum = "EXCEPTION"
|
||||
ListRecordResponseStateEnumForbidden ListRecordResponseStateEnum = "FORBIDDEN"
|
||||
ListRecordResponseStateEnumOk ListRecordResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type ListRecordResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State ListRecordResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *ListRecordResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordResponseBody struct {
|
||||
// 总页数
|
||||
TotalPages *int32 `json:"totalPages,omitempty"`
|
||||
|
||||
// 当前页码,从0开始,0表示第一页
|
||||
CurrentPage *int32 `json:"currentPage,omitempty"`
|
||||
|
||||
// 当前页的具体数据列表
|
||||
Results *[]ListRecordResponseResults `json:"results,omitempty"`
|
||||
|
||||
// 总数据量
|
||||
TotalElements *int64 `json:"totalElements,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ListRecordResponseResultsTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
ListRecordResponseResultsTypeEnumA ListRecordResponseResultsTypeEnum = "A"
|
||||
ListRecordResponseResultsTypeEnumAaaa ListRecordResponseResultsTypeEnum = "AAAA"
|
||||
ListRecordResponseResultsTypeEnumCaa ListRecordResponseResultsTypeEnum = "CAA"
|
||||
ListRecordResponseResultsTypeEnumCmauth ListRecordResponseResultsTypeEnum = "CMAUTH"
|
||||
ListRecordResponseResultsTypeEnumCname ListRecordResponseResultsTypeEnum = "CNAME"
|
||||
ListRecordResponseResultsTypeEnumMx ListRecordResponseResultsTypeEnum = "MX"
|
||||
ListRecordResponseResultsTypeEnumNs ListRecordResponseResultsTypeEnum = "NS"
|
||||
ListRecordResponseResultsTypeEnumPtr ListRecordResponseResultsTypeEnum = "PTR"
|
||||
ListRecordResponseResultsTypeEnumRp ListRecordResponseResultsTypeEnum = "RP"
|
||||
ListRecordResponseResultsTypeEnumSpf ListRecordResponseResultsTypeEnum = "SPF"
|
||||
ListRecordResponseResultsTypeEnumSrv ListRecordResponseResultsTypeEnum = "SRV"
|
||||
ListRecordResponseResultsTypeEnumTxt ListRecordResponseResultsTypeEnum = "TXT"
|
||||
ListRecordResponseResultsTypeEnumUrl ListRecordResponseResultsTypeEnum = "URL"
|
||||
)
|
||||
|
||||
type ListRecordResponseResultsTimedStatusEnum string
|
||||
|
||||
// List of TimedStatus
|
||||
const (
|
||||
ListRecordResponseResultsTimedStatusEnumDisabled ListRecordResponseResultsTimedStatusEnum = "DISABLED"
|
||||
ListRecordResponseResultsTimedStatusEnumEnabled ListRecordResponseResultsTimedStatusEnum = "ENABLED"
|
||||
ListRecordResponseResultsTimedStatusEnumTimed ListRecordResponseResultsTimedStatusEnum = "TIMED"
|
||||
)
|
||||
|
||||
type ListRecordResponseResultsStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ListRecordResponseResultsStateEnumDisabled ListRecordResponseResultsStateEnum = "DISABLED"
|
||||
ListRecordResponseResultsStateEnumEnabled ListRecordResponseResultsStateEnum = "ENABLED"
|
||||
)
|
||||
|
||||
type ListRecordResponseResults struct {
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 修改时间
|
||||
ModifiedTime string `json:"modifiedTime,omitempty"`
|
||||
|
||||
// 线路中文名
|
||||
LineZh string `json:"lineZh,omitempty"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// 权重值
|
||||
Weight *int32 `json:"weight,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type ListRecordResponseResultsTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 定时状态
|
||||
TimedStatus ListRecordResponseResultsTimedStatusEnum `json:"timedStatus,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
|
||||
// 线路英文名
|
||||
LineEn string `json:"lineEn,omitempty"`
|
||||
|
||||
// 状态
|
||||
State ListRecordResponseResultsStateEnum `json:"state,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
|
||||
// 定时发布时间
|
||||
Pubdate string `json:"pubdate,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type ModifyRecordBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
ModifyRecordBodyTypeEnumA ModifyRecordBodyTypeEnum = "A"
|
||||
ModifyRecordBodyTypeEnumAaaa ModifyRecordBodyTypeEnum = "AAAA"
|
||||
ModifyRecordBodyTypeEnumCaa ModifyRecordBodyTypeEnum = "CAA"
|
||||
ModifyRecordBodyTypeEnumCmauth ModifyRecordBodyTypeEnum = "CMAUTH"
|
||||
ModifyRecordBodyTypeEnumCname ModifyRecordBodyTypeEnum = "CNAME"
|
||||
ModifyRecordBodyTypeEnumMx ModifyRecordBodyTypeEnum = "MX"
|
||||
ModifyRecordBodyTypeEnumNs ModifyRecordBodyTypeEnum = "NS"
|
||||
ModifyRecordBodyTypeEnumPtr ModifyRecordBodyTypeEnum = "PTR"
|
||||
ModifyRecordBodyTypeEnumRp ModifyRecordBodyTypeEnum = "RP"
|
||||
ModifyRecordBodyTypeEnumSpf ModifyRecordBodyTypeEnum = "SPF"
|
||||
ModifyRecordBodyTypeEnumSrv ModifyRecordBodyTypeEnum = "SRV"
|
||||
ModifyRecordBodyTypeEnumTxt ModifyRecordBodyTypeEnum = "TXT"
|
||||
ModifyRecordBodyTypeEnumUrl ModifyRecordBodyTypeEnum = "URL"
|
||||
)
|
||||
|
||||
type ModifyRecordBody struct {
|
||||
position.Body
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId"`
|
||||
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type ModifyRecordBodyTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/position"
|
||||
)
|
||||
|
||||
type ModifyRecordOpenapiBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
ModifyRecordOpenapiBodyTypeEnumA ModifyRecordOpenapiBodyTypeEnum = "A"
|
||||
ModifyRecordOpenapiBodyTypeEnumAaaa ModifyRecordOpenapiBodyTypeEnum = "AAAA"
|
||||
ModifyRecordOpenapiBodyTypeEnumCname ModifyRecordOpenapiBodyTypeEnum = "CNAME"
|
||||
ModifyRecordOpenapiBodyTypeEnumMx ModifyRecordOpenapiBodyTypeEnum = "MX"
|
||||
ModifyRecordOpenapiBodyTypeEnumTxt ModifyRecordOpenapiBodyTypeEnum = "TXT"
|
||||
ModifyRecordOpenapiBodyTypeEnumNs ModifyRecordOpenapiBodyTypeEnum = "NS"
|
||||
ModifyRecordOpenapiBodyTypeEnumSpf ModifyRecordOpenapiBodyTypeEnum = "SPF"
|
||||
ModifyRecordOpenapiBodyTypeEnumSrv ModifyRecordOpenapiBodyTypeEnum = "SRV"
|
||||
ModifyRecordOpenapiBodyTypeEnumCaa ModifyRecordOpenapiBodyTypeEnum = "CAA"
|
||||
ModifyRecordOpenapiBodyTypeEnumCmauth ModifyRecordOpenapiBodyTypeEnum = "CMAUTH"
|
||||
)
|
||||
|
||||
type ModifyRecordOpenapiBody struct {
|
||||
position.Body
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId"`
|
||||
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type ModifyRecordOpenapiBodyTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ModifyRecordOpenapiRequest struct {
|
||||
ModifyRecordOpenapiBody *ModifyRecordOpenapiBody `json:"modifyRecordOpenapiBody,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ModifyRecordOpenapiResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ModifyRecordOpenapiResponseStateEnumError ModifyRecordOpenapiResponseStateEnum = "ERROR"
|
||||
ModifyRecordOpenapiResponseStateEnumException ModifyRecordOpenapiResponseStateEnum = "EXCEPTION"
|
||||
ModifyRecordOpenapiResponseStateEnumForbidden ModifyRecordOpenapiResponseStateEnum = "FORBIDDEN"
|
||||
ModifyRecordOpenapiResponseStateEnumOk ModifyRecordOpenapiResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type ModifyRecordOpenapiResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State ModifyRecordOpenapiResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *ModifyRecordOpenapiResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ModifyRecordOpenapiResponseBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumA ModifyRecordOpenapiResponseBodyTypeEnum = "A"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumAaaa ModifyRecordOpenapiResponseBodyTypeEnum = "AAAA"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumCname ModifyRecordOpenapiResponseBodyTypeEnum = "CNAME"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumMx ModifyRecordOpenapiResponseBodyTypeEnum = "MX"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumTxt ModifyRecordOpenapiResponseBodyTypeEnum = "TXT"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumNs ModifyRecordOpenapiResponseBodyTypeEnum = "NS"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumSpf ModifyRecordOpenapiResponseBodyTypeEnum = "SPF"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumSrv ModifyRecordOpenapiResponseBodyTypeEnum = "SRV"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumCaa ModifyRecordOpenapiResponseBodyTypeEnum = "CAA"
|
||||
ModifyRecordOpenapiResponseBodyTypeEnumCmauth ModifyRecordOpenapiResponseBodyTypeEnum = "CMAUTH"
|
||||
)
|
||||
|
||||
type ModifyRecordOpenapiResponseBodyTimedStatusEnum string
|
||||
|
||||
// List of TimedStatus
|
||||
const (
|
||||
ModifyRecordOpenapiResponseBodyTimedStatusEnumDisabled ModifyRecordOpenapiResponseBodyTimedStatusEnum = "DISABLED"
|
||||
ModifyRecordOpenapiResponseBodyTimedStatusEnumEnabled ModifyRecordOpenapiResponseBodyTimedStatusEnum = "ENABLED"
|
||||
ModifyRecordOpenapiResponseBodyTimedStatusEnumTimed ModifyRecordOpenapiResponseBodyTimedStatusEnum = "TIMED"
|
||||
)
|
||||
|
||||
type ModifyRecordOpenapiResponseBodyStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ModifyRecordOpenapiResponseBodyStateEnumDisabled ModifyRecordOpenapiResponseBodyStateEnum = "DISABLED"
|
||||
ModifyRecordOpenapiResponseBodyStateEnumEnabled ModifyRecordOpenapiResponseBodyStateEnum = "ENABLED"
|
||||
)
|
||||
|
||||
type ModifyRecordOpenapiResponseBody struct {
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 修改时间
|
||||
ModifiedTime string `json:"modifiedTime,omitempty"`
|
||||
|
||||
// 线路中文名
|
||||
LineZh string `json:"lineZh,omitempty"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// 权重值
|
||||
Weight *int32 `json:"weight,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type ModifyRecordOpenapiResponseBodyTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 标签
|
||||
Tags *[]ModifyRecordOpenapiResponseTags `json:"tags,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 定时状态
|
||||
TimedStatus ModifyRecordOpenapiResponseBodyTimedStatusEnum `json:"timedStatus,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
|
||||
// 线路英文名
|
||||
LineEn string `json:"lineEn,omitempty"`
|
||||
|
||||
// 状态
|
||||
State ModifyRecordOpenapiResponseBodyStateEnum `json:"state,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
|
||||
// 定时发布时间
|
||||
Pubdate string `json:"pubdate,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ModifyRecordOpenapiResponseTags struct {
|
||||
// 标签ID
|
||||
TagId string `json:"tagId,omitempty"`
|
||||
|
||||
// 标签名称
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ModifyRecordRequest struct {
|
||||
ModifyRecordBody *ModifyRecordBody `json:"modifyRecordBody,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ModifyRecordResponseStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ModifyRecordResponseStateEnumError ModifyRecordResponseStateEnum = "ERROR"
|
||||
ModifyRecordResponseStateEnumException ModifyRecordResponseStateEnum = "EXCEPTION"
|
||||
ModifyRecordResponseStateEnumForbidden ModifyRecordResponseStateEnum = "FORBIDDEN"
|
||||
ModifyRecordResponseStateEnumOk ModifyRecordResponseStateEnum = "OK"
|
||||
)
|
||||
|
||||
type ModifyRecordResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
|
||||
State ModifyRecordResponseStateEnum `json:"state,omitempty"`
|
||||
|
||||
Body *ModifyRecordResponseBody `json:"body,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// @Title Golang SDK Client
|
||||
// @Description This code is auto generated
|
||||
// @Author Ecloud SDK
|
||||
|
||||
package model
|
||||
|
||||
type ModifyRecordResponseBodyTypeEnum string
|
||||
|
||||
// List of Type
|
||||
const (
|
||||
ModifyRecordResponseBodyTypeEnumA ModifyRecordResponseBodyTypeEnum = "A"
|
||||
ModifyRecordResponseBodyTypeEnumAaaa ModifyRecordResponseBodyTypeEnum = "AAAA"
|
||||
ModifyRecordResponseBodyTypeEnumCaa ModifyRecordResponseBodyTypeEnum = "CAA"
|
||||
ModifyRecordResponseBodyTypeEnumCmauth ModifyRecordResponseBodyTypeEnum = "CMAUTH"
|
||||
ModifyRecordResponseBodyTypeEnumCname ModifyRecordResponseBodyTypeEnum = "CNAME"
|
||||
ModifyRecordResponseBodyTypeEnumMx ModifyRecordResponseBodyTypeEnum = "MX"
|
||||
ModifyRecordResponseBodyTypeEnumNs ModifyRecordResponseBodyTypeEnum = "NS"
|
||||
ModifyRecordResponseBodyTypeEnumPtr ModifyRecordResponseBodyTypeEnum = "PTR"
|
||||
ModifyRecordResponseBodyTypeEnumRp ModifyRecordResponseBodyTypeEnum = "RP"
|
||||
ModifyRecordResponseBodyTypeEnumSpf ModifyRecordResponseBodyTypeEnum = "SPF"
|
||||
ModifyRecordResponseBodyTypeEnumSrv ModifyRecordResponseBodyTypeEnum = "SRV"
|
||||
ModifyRecordResponseBodyTypeEnumTxt ModifyRecordResponseBodyTypeEnum = "TXT"
|
||||
ModifyRecordResponseBodyTypeEnumUrl ModifyRecordResponseBodyTypeEnum = "URL"
|
||||
)
|
||||
|
||||
type ModifyRecordResponseBodyStateEnum string
|
||||
|
||||
// List of State
|
||||
const (
|
||||
ModifyRecordResponseBodyStateEnumDisabled ModifyRecordResponseBodyStateEnum = "DISABLED"
|
||||
ModifyRecordResponseBodyStateEnumEnabled ModifyRecordResponseBodyStateEnum = "ENABLED"
|
||||
)
|
||||
|
||||
type ModifyRecordResponseBody struct {
|
||||
// 主机头
|
||||
Rr string `json:"rr,omitempty"`
|
||||
|
||||
// 修改时间
|
||||
ModifiedTime string `json:"modifiedTime,omitempty"`
|
||||
|
||||
// 线路中文名
|
||||
LineZh string `json:"lineZh,omitempty"`
|
||||
|
||||
// 备注
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// 线路ID
|
||||
LineId string `json:"lineId,omitempty"`
|
||||
|
||||
// 权重值
|
||||
Weight *int32 `json:"weight,omitempty"`
|
||||
|
||||
// MX优先级
|
||||
MxPri *int32 `json:"mxPri,omitempty"`
|
||||
|
||||
// 记录类型
|
||||
Type ModifyRecordResponseBodyTypeEnum `json:"type,omitempty"`
|
||||
|
||||
// 缓存的生命周期
|
||||
Ttl *int32 `json:"ttl,omitempty"`
|
||||
|
||||
// 解析记录ID
|
||||
RecordId string `json:"recordId,omitempty"`
|
||||
|
||||
// 域名名称
|
||||
DomainName string `json:"domainName,omitempty"`
|
||||
|
||||
// 线路英文名
|
||||
LineEn string `json:"lineEn,omitempty"`
|
||||
|
||||
// 状态
|
||||
State ModifyRecordResponseBodyStateEnum `json:"state,omitempty"`
|
||||
|
||||
// 记录值
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
509
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/api_client.go
Normal file
509
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/api_client.go
Normal file
@@ -0,0 +1,509 @@
|
||||
package ecloudsdkcore
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitlab.ecloud.com/ecloud/ecloudsdkcore/config"
|
||||
)
|
||||
|
||||
var (
|
||||
jsonCheck = regexp.MustCompile("(?i:(?:application|text)/json)")
|
||||
xmlCheck = regexp.MustCompile("(?i:(?:application|text)/xml)")
|
||||
)
|
||||
|
||||
// APIClient manages communication
|
||||
// In most cases there should be only one, shared, APIClient.
|
||||
type APIClient struct {
|
||||
cfg *Configuration
|
||||
common service
|
||||
}
|
||||
|
||||
type service struct {
|
||||
client *APIClient
|
||||
}
|
||||
|
||||
type HttpRequestPosition string
|
||||
|
||||
const (
|
||||
BODY HttpRequestPosition = "Body"
|
||||
QUERY HttpRequestPosition = "Query"
|
||||
PATH HttpRequestPosition = "Path"
|
||||
HEADER HttpRequestPosition = "Header"
|
||||
)
|
||||
|
||||
const (
|
||||
SdkPortalUrl = "/op-apim-portal/apim/request/sdk"
|
||||
SdkPortalGatewayUrl = "/api/query/openapi/apim/request/sdk"
|
||||
)
|
||||
|
||||
// NewAPIClient creates a new API client.
|
||||
func NewAPIClient() *APIClient {
|
||||
cfg := NewConfiguration()
|
||||
if cfg.HTTPClient == nil {
|
||||
cfg.HTTPClient = http.DefaultClient
|
||||
}
|
||||
c := &APIClient{}
|
||||
c.cfg = cfg
|
||||
c.common.client = c
|
||||
return c
|
||||
}
|
||||
|
||||
// atoi string to int
|
||||
func atoi(in string) (int, error) {
|
||||
return strconv.Atoi(in)
|
||||
}
|
||||
|
||||
// selectHeaderContentType select a content type from the available list.
|
||||
func selectHeaderContentType(contentTypes []string) string {
|
||||
if len(contentTypes) == 0 {
|
||||
return ""
|
||||
}
|
||||
if contains(contentTypes, "application/json") {
|
||||
return "application/json"
|
||||
}
|
||||
return contentTypes[0]
|
||||
}
|
||||
|
||||
// selectHeaderAccept join all accept types and return
|
||||
func selectHeaderAccept(accepts []string) string {
|
||||
if len(accepts) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if contains(accepts, "application/json") {
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
return strings.Join(accepts, ",")
|
||||
}
|
||||
|
||||
// contains is a case insenstive match, finding needle in a haystack
|
||||
func contains(haystack []string, needle string) bool {
|
||||
for _, a := range haystack {
|
||||
if strings.ToLower(a) == strings.ToLower(needle) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Verify optional parameters are of the correct type.
|
||||
func typeCheckParameter(obj interface{}, expected string, name string) error {
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
if reflect.TypeOf(obj).String() != expected {
|
||||
return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// parameterToString convert interface{} parameters to string, using a delimiter if format is provided.
|
||||
func parameterToString(obj interface{}, collectionFormat string, request HttpRequest) (*http.Request, string) {
|
||||
var delimiter string
|
||||
|
||||
switch collectionFormat {
|
||||
case "pipes":
|
||||
delimiter = "|"
|
||||
case "ssv":
|
||||
delimiter = " "
|
||||
case "tsv":
|
||||
delimiter = "\t"
|
||||
case "csv":
|
||||
delimiter = ","
|
||||
}
|
||||
|
||||
if reflect.TypeOf(obj).Kind() == reflect.Slice {
|
||||
return nil, strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]")
|
||||
}
|
||||
|
||||
return nil, fmt.Sprintf("%v", obj)
|
||||
}
|
||||
|
||||
// Excute entry for http call
|
||||
func (c *APIClient) Excute(httpRequest *HttpRequest, config *config.Config, returnType interface{}) (*http.Response, error) {
|
||||
httpRequest = buildHttpRequest(httpRequest, config)
|
||||
request := buildCall(httpRequest)
|
||||
httpResponse, err := c.callAPI(request)
|
||||
if err != nil || httpResponse == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
responseBody, err := ioutil.ReadAll(httpResponse.Body)
|
||||
httpResponse.Body.Close()
|
||||
if err != nil {
|
||||
return httpResponse, err
|
||||
}
|
||||
|
||||
if httpResponse.StatusCode < 300 {
|
||||
// If we succeed, return the data, otherwise pass on to decode error.
|
||||
err = c.decode(&returnType, responseBody, httpResponse.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
return httpResponse, fmt.Errorf("%w, response body is: %s", err, string(responseBody))
|
||||
}
|
||||
return httpResponse, nil
|
||||
}
|
||||
|
||||
if httpResponse.StatusCode >= 300 {
|
||||
newErr := GenericResponseError{
|
||||
body: responseBody,
|
||||
error: httpResponse.Status,
|
||||
}
|
||||
return httpResponse, newErr
|
||||
}
|
||||
return httpResponse, err
|
||||
}
|
||||
|
||||
// callAPI do the request.
|
||||
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
|
||||
return c.cfg.HTTPClient.Do(request)
|
||||
}
|
||||
|
||||
// ChangeBasePath Change base path to allow switching to mocks
|
||||
func (c *APIClient) ChangeBasePath(path string) {
|
||||
c.cfg.BasePath = path
|
||||
}
|
||||
|
||||
// buildHttpRequest build the request
|
||||
func buildHttpRequest(httpRequest *HttpRequest, config *config.Config) *HttpRequest {
|
||||
openApiRequest := &OpenApiRequest{
|
||||
AccessKey: config.AccessKey,
|
||||
SecretKey: config.SecretKey,
|
||||
PoolId: config.PoolId,
|
||||
Api: httpRequest.Action,
|
||||
Product: httpRequest.Product,
|
||||
Version: httpRequest.Version,
|
||||
SdkVersion: httpRequest.SdkVersion,
|
||||
Language: "Golang",
|
||||
}
|
||||
if httpRequest.Body != nil {
|
||||
reqType := reflect.TypeOf(httpRequest.Body)
|
||||
if reqType.Kind() == reflect.Ptr {
|
||||
reqType = reqType.Elem()
|
||||
}
|
||||
v := reflect.ValueOf(httpRequest.Body)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
}
|
||||
flag := false
|
||||
for i := 0; i < reqType.NumField(); i++ {
|
||||
fieldType := reqType.Field(i)
|
||||
value := v.FieldByName(fieldType.Name)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
if value.IsNil() {
|
||||
continue
|
||||
}
|
||||
value = value.Elem()
|
||||
|
||||
}
|
||||
propertyType := fieldType.Type
|
||||
if propertyType.Kind() == reflect.Ptr {
|
||||
propertyType = propertyType.Elem()
|
||||
}
|
||||
|
||||
_, flag = propertyType.FieldByName(string(BODY))
|
||||
if flag {
|
||||
openApiRequest.BodyParameter = value.Interface()
|
||||
continue
|
||||
}
|
||||
_, flag = propertyType.FieldByName(string(HEADER))
|
||||
if flag {
|
||||
openApiRequest.HeaderParameter = structToMap(value.Interface())
|
||||
continue
|
||||
}
|
||||
_, flag = propertyType.FieldByName(string(QUERY))
|
||||
if flag {
|
||||
openApiRequest.QueryParameter = structToMap(value.Interface())
|
||||
continue
|
||||
}
|
||||
_, flag = propertyType.FieldByName(string(PATH))
|
||||
if flag {
|
||||
openApiRequest.PathParameter = structToMap(value.Interface())
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
headers := make(map[string]interface{})
|
||||
if httpRequest.HeaderParams != nil {
|
||||
if openApiRequest.HeaderParameter == nil {
|
||||
headers = httpRequest.HeaderParams
|
||||
} else {
|
||||
headers = mergeMap(openApiRequest.HeaderParameter, httpRequest.HeaderParams)
|
||||
}
|
||||
openApiRequest.HeaderParameter = headers
|
||||
}
|
||||
httpRequest.Body = openApiRequest
|
||||
return httpRequest
|
||||
}
|
||||
|
||||
// mergeMap merge the two map results
|
||||
func mergeMap(mObj ...map[string]interface{}) map[string]interface{} {
|
||||
newMap := map[string]interface{}{}
|
||||
for _, m := range mObj {
|
||||
for k, v := range m {
|
||||
newMap[k] = v
|
||||
}
|
||||
}
|
||||
return newMap
|
||||
}
|
||||
|
||||
// structToMap struct convert to map
|
||||
func structToMap(value interface{}) map[string]interface{} {
|
||||
data, _ := json.Marshal(value)
|
||||
result := make(map[string]interface{})
|
||||
json.Unmarshal(data, &result)
|
||||
return result
|
||||
}
|
||||
|
||||
func buildCall(httpRequest *HttpRequest) (request *http.Request) {
|
||||
url := ""
|
||||
if len(httpRequest.Url) > 0 {
|
||||
url = httpRequest.Url + SdkPortalUrl
|
||||
} else {
|
||||
url = httpRequest.DefaultUrl + SdkPortalGatewayUrl
|
||||
}
|
||||
request, _ = prepareRequest(url, "POST", httpRequest.Body)
|
||||
return request
|
||||
}
|
||||
|
||||
// prepareRequest build the request
|
||||
func prepareRequest(path string, method string,
|
||||
postBody interface{},
|
||||
) (httpRequest *http.Request, err error) {
|
||||
var body *bytes.Buffer
|
||||
|
||||
// Detect postBody type and post.
|
||||
if postBody != nil {
|
||||
contentType := detectContentType(postBody)
|
||||
body, err = setBody(postBody, contentType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Setup path and query parameters
|
||||
url, err := url.Parse(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Generate a new request
|
||||
if body != nil {
|
||||
httpRequest, err = http.NewRequest(method, url.String(), body)
|
||||
} else {
|
||||
httpRequest, err = http.NewRequest(method, url.String(), nil)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// add default header parameters
|
||||
httpRequest.Header.Add("Content-Type", "application/json")
|
||||
return httpRequest, nil
|
||||
}
|
||||
|
||||
func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
|
||||
if strings.Contains(contentType, "application/xml") {
|
||||
if err = xml.Unmarshal(b, v); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
} else if strings.Contains(contentType, "application/json") {
|
||||
platformResponse := &APIPlatformResponse{}
|
||||
if err = json.Unmarshal(b, platformResponse); err != nil {
|
||||
newErr := GenericResponseError{
|
||||
body: b,
|
||||
error: err.Error(),
|
||||
}
|
||||
return newErr
|
||||
}
|
||||
platformResponseBodyBytes, _ := json.Marshal(platformResponse.Body)
|
||||
platformResponseBody := &APIPlatformResponseBody{}
|
||||
if err = json.Unmarshal(platformResponseBodyBytes, platformResponseBody); err != nil {
|
||||
return err
|
||||
}
|
||||
/*
|
||||
找到两层指针指向的元素
|
||||
*/
|
||||
value := reflect.ValueOf(v).Elem().Elem()
|
||||
|
||||
if !value.IsNil() {
|
||||
structValue := value.Elem()
|
||||
if structValue.NumField() == 1 && structValue.Field(0).Kind() == reflect.String {
|
||||
n := len(platformResponseBody.ResponseBody)
|
||||
structValue.Field(0).SetString(platformResponseBody.ResponseBody[1 : n-1])
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if err = json.Unmarshal([]byte(platformResponseBody.ResponseBody), v); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errors.New("undefined response type")
|
||||
}
|
||||
|
||||
// Add a file to the multipart request
|
||||
func addFile(w *multipart.Writer, fieldName, path string) error {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(part, file)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Prevent trying to import "fmt"
|
||||
func reportError(format string, a ...interface{}) error {
|
||||
return fmt.Errorf(format, a...)
|
||||
}
|
||||
|
||||
// Set request body from an interface{}
|
||||
func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) {
|
||||
if bodyBuf == nil {
|
||||
bodyBuf = &bytes.Buffer{}
|
||||
}
|
||||
if reader, ok := body.(io.Reader); ok {
|
||||
_, err = bodyBuf.ReadFrom(reader)
|
||||
} else if b, ok := body.([]byte); ok {
|
||||
_, err = bodyBuf.Write(b)
|
||||
} else if s, ok := body.(string); ok {
|
||||
_, err = bodyBuf.WriteString(s)
|
||||
} else if s, ok := body.(*string); ok {
|
||||
_, err = bodyBuf.WriteString(*s)
|
||||
} else if jsonCheck.MatchString(contentType) {
|
||||
err = json.NewEncoder(bodyBuf).Encode(body)
|
||||
} else if xmlCheck.MatchString(contentType) {
|
||||
xml.NewEncoder(bodyBuf).Encode(body)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if bodyBuf.Len() == 0 {
|
||||
err = fmt.Errorf("Invalid body type %s\n", contentType)
|
||||
return nil, err
|
||||
}
|
||||
return bodyBuf, nil
|
||||
}
|
||||
|
||||
// detectContentType method is used to figure out `Request.Body` content type for request header
|
||||
func detectContentType(body interface{}) string {
|
||||
contentType := "text/plain; charset=utf-8"
|
||||
kind := reflect.TypeOf(body).Kind()
|
||||
|
||||
switch kind {
|
||||
case reflect.Struct, reflect.Map, reflect.Ptr:
|
||||
contentType = "application/json; charset=utf-8"
|
||||
case reflect.String:
|
||||
contentType = "text/plain; charset=utf-8"
|
||||
default:
|
||||
if b, ok := body.([]byte); ok {
|
||||
contentType = http.DetectContentType(b)
|
||||
} else if kind == reflect.Slice {
|
||||
contentType = "application/json; charset=utf-8"
|
||||
}
|
||||
}
|
||||
|
||||
return contentType
|
||||
}
|
||||
|
||||
type cacheControl map[string]string
|
||||
|
||||
func parseCacheControl(headers http.Header) cacheControl {
|
||||
cc := cacheControl{}
|
||||
ccHeader := headers.Get("Cache-Control")
|
||||
for _, part := range strings.Split(ccHeader, ",") {
|
||||
part = strings.Trim(part, " ")
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
if strings.ContainsRune(part, '=') {
|
||||
keyval := strings.Split(part, "=")
|
||||
cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",")
|
||||
} else {
|
||||
cc[part] = ""
|
||||
}
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
// CacheExpires helper function to determine remaining time before repeating a request.
|
||||
func CacheExpires(r *http.Response) time.Time {
|
||||
// Figure out when the cache expires.
|
||||
var expires time.Time
|
||||
now, err := time.Parse(time.RFC1123, r.Header.Get("date"))
|
||||
if err != nil {
|
||||
return time.Now()
|
||||
}
|
||||
respCacheControl := parseCacheControl(r.Header)
|
||||
|
||||
if maxAge, ok := respCacheControl["max-age"]; ok {
|
||||
lifetime, err := time.ParseDuration(maxAge + "s")
|
||||
if err != nil {
|
||||
expires = now
|
||||
}
|
||||
expires = now.Add(lifetime)
|
||||
} else {
|
||||
expiresHeader := r.Header.Get("Expires")
|
||||
if expiresHeader != "" {
|
||||
expires, err = time.Parse(time.RFC1123, expiresHeader)
|
||||
if err != nil {
|
||||
expires = now
|
||||
}
|
||||
}
|
||||
}
|
||||
return expires
|
||||
}
|
||||
|
||||
func strlen(s string) int {
|
||||
return utf8.RuneCountInString(s)
|
||||
}
|
||||
|
||||
// GenericResponseError Provides access to the body, error and model on returned errors.
|
||||
type GenericResponseError struct {
|
||||
body []byte
|
||||
error string
|
||||
model interface{}
|
||||
}
|
||||
|
||||
// Error returns non-empty string if there was an error.
|
||||
func (e GenericResponseError) Error() string {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Body returns the raw bytes of the response
|
||||
func (e GenericResponseError) Body() []byte {
|
||||
return e.body
|
||||
}
|
||||
|
||||
// Model returns the unpacked model of the error
|
||||
func (e GenericResponseError) Model() interface{} {
|
||||
return e.model
|
||||
}
|
||||
62
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/api_response.go
Normal file
62
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/api_response.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package ecloudsdkcore
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ReturnState string
|
||||
|
||||
const (
|
||||
OK ReturnState = "OK"
|
||||
ERROR ReturnState = "ERROR"
|
||||
EXCEPTION ReturnState = "EXCEPTION"
|
||||
ALARM ReturnState = "ALARM"
|
||||
FORBIDDEN ReturnState = "FORBIDDEN"
|
||||
)
|
||||
|
||||
type APIResponse struct {
|
||||
*http.Response `json:"-"`
|
||||
Message string `json:"message,omitempty"`
|
||||
// Operation is the name of the swagger operation.
|
||||
Operation string `json:"operation,omitempty"`
|
||||
// RequestURL is the request URL. This value is always available, even if the
|
||||
// embedded *http.Response is nil.
|
||||
RequestURL string `json:"url,omitempty"`
|
||||
// Method is the HTTP method used for the request. This value is always
|
||||
// available, even if the embedded *http.Response is nil.
|
||||
Method string `json:"method,omitempty"`
|
||||
// Payload holds the contents of the response body (which may be nil or empty).
|
||||
// This is provided here as the raw response.Body() reader will have already
|
||||
// been drained.
|
||||
Payload []byte `json:"-"`
|
||||
}
|
||||
|
||||
type APIPlatformResponse struct {
|
||||
RequestId string `json:"requestId,omitempty"`
|
||||
State ReturnState `json:"state,omitempty"`
|
||||
Body interface{} `json:"body,omitempty"`
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
ErrorParams []string `json:"errorParams,omitempty"`
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
}
|
||||
|
||||
type APIPlatformResponseBody struct {
|
||||
// TimeConsuming int64 `json:"timeConsuming,omitempty"`
|
||||
ResponseBody string `json:"responseBody,omitempty"`
|
||||
RequestHeader map[string]interface{} `json:"requestHeader,omitempty"`
|
||||
ResponseHeader map[string]interface{} `json:"responseHeader,omitempty"`
|
||||
ResponseMessage string `json:"responseMessage,omitempty"`
|
||||
StatusCode int `json:"statusCode,omitempty"`
|
||||
HttpMethod string `json:"httpMethod,omitempty"`
|
||||
RequestUrl string `json:"requestUrl,omitempty"`
|
||||
}
|
||||
|
||||
func NewAPIResponse(r *http.Response) *APIResponse {
|
||||
response := &APIResponse{Response: r}
|
||||
return response
|
||||
}
|
||||
|
||||
func NewAPIResponseWithError(errorMessage string) *APIResponse {
|
||||
response := &APIResponse{Message: errorMessage}
|
||||
return response
|
||||
}
|
||||
9
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/config/config.go
Normal file
9
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/config/config.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
AccessKey string `json:"accessKey,string"`
|
||||
SecretKey string `json:"secretKey,string"`
|
||||
PoolId string `json:"poolId,string"`
|
||||
ReadTimeOut int `json:"readTimeOut,int"`
|
||||
ConnectTimeout int `json:"connectTimeout,int"`
|
||||
}
|
||||
32
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/configuration.go
Normal file
32
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/configuration.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package ecloudsdkcore
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type APIKey struct {
|
||||
Key string
|
||||
Prefix string
|
||||
}
|
||||
|
||||
type Configuration struct {
|
||||
BasePath string `json:"basePath,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Scheme string `json:"scheme,omitempty"`
|
||||
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
|
||||
UserAgent string `json:"userAgent,omitempty"`
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
func NewConfiguration() *Configuration {
|
||||
cfg := &Configuration{
|
||||
BasePath: "https://ecloud.10086.cn/",
|
||||
DefaultHeader: make(map[string]string),
|
||||
UserAgent: "Ecloud-SDK/1.0.0/go",
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (c *Configuration) AddDefaultHeader(key string, value string) {
|
||||
c.DefaultHeader[key] = value
|
||||
}
|
||||
3
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/go.mod
Normal file
3
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module gitlab.ecloud.com/ecloud/ecloudsdkcore
|
||||
|
||||
go 1.24.0
|
||||
22
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/http_request.go
Normal file
22
pkg/sdk3rd/cmcc/ecloudsdkcore@v1.0.0/http_request.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package ecloudsdkcore
|
||||
|
||||
type HttpRequest struct {
|
||||
Url string `json:"url,omitempty"`
|
||||
DefaultUrl string `json:"defaultUrl,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Action string `json:"action,omitempty"`
|
||||
Product string `json:"product,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
SdkVersion string `json:"sdkVersion,omitempty"`
|
||||
Body interface{} `json:"body,omitempty"`
|
||||
PathParams map[string]interface{} `json:"pathParams,omitempty"`
|
||||
QueryParams map[string]interface{} `json:"queryParams,omitempty"`
|
||||
HeaderParams map[string]interface{} `json:"headerParams,omitempty"`
|
||||
}
|
||||
|
||||
func NewDefaultHttpRequest() *HttpRequest {
|
||||
return &HttpRequest{
|
||||
DefaultUrl: "https://ecloud.10086.cn",
|
||||
Method: "POST",
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user