feat: add baotapanel console deployer

This commit is contained in:
Fu Diwei
2025-02-15 23:32:09 +08:00
parent 6d8301b159
commit b734ffcf9d
16 changed files with 447 additions and 161 deletions

View File

@@ -5,22 +5,44 @@ type BaseResponse interface {
GetMsg() *string
}
type SetSiteSSLRequest struct {
Type string `json:"type"`
SiteName string `json:"siteName"`
Key string `json:"key"`
Csr string `json:"csr"`
}
type SetSiteSSLResponse struct {
type baseResponse struct {
Status *bool `json:"status,omitempty"`
Msg *string `json:"msg,omitempty"`
}
func (r *SetSiteSSLResponse) GetStatus() *bool {
func (r *baseResponse) GetStatus() *bool {
return r.Status
}
func (r *SetSiteSSLResponse) GetMsg() *string {
func (r *baseResponse) GetMsg() *string {
return r.Msg
}
type ConfigSavePanelSSLRequest struct {
PrivateKey string `json:"privateKey"`
Certificate string `json:"certPem"`
}
type ConfigSavePanelSSLResponse struct {
baseResponse
}
type SiteSetSSLRequest struct {
Type string `json:"type"`
SiteName string `json:"siteName"`
PrivateKey string `json:"key"`
Certificate string `json:"csr"`
}
type SiteSetSSLResponse struct {
baseResponse
}
type SystemServiceAdminRequest struct {
Name string `json:"name"`
Type string `json:"type"`
}
type SystemServiceAdminResponse struct {
baseResponse
}

View File

@@ -34,12 +34,25 @@ func (c *BaoTaPanelClient) WithTimeout(timeout time.Duration) *BaoTaPanelClient
return c
}
func (c *BaoTaPanelClient) SetSiteSSL(req *SetSiteSSLRequest) (*SetSiteSSLResponse, error) {
func (c *BaoTaPanelClient) ConfigSavePanelSSL(req *ConfigSavePanelSSLRequest) (*ConfigSavePanelSSLResponse, error) {
params := make(map[string]any)
jsonData, _ := json.Marshal(req)
json.Unmarshal(jsonData, &params)
result := SetSiteSSLResponse{}
result := ConfigSavePanelSSLResponse{}
err := c.sendRequestWithResult("/config?action=SavePanelSSL", params, &result)
if err != nil {
return nil, err
}
return &result, nil
}
func (c *BaoTaPanelClient) SiteSetSSL(req *SiteSetSSLRequest) (*SiteSetSSLResponse, error) {
params := make(map[string]any)
jsonData, _ := json.Marshal(req)
json.Unmarshal(jsonData, &params)
result := SiteSetSSLResponse{}
err := c.sendRequestWithResult("/site?action=SetSSL", params, &result)
if err != nil {
return nil, err
@@ -47,6 +60,19 @@ func (c *BaoTaPanelClient) SetSiteSSL(req *SetSiteSSLRequest) (*SetSiteSSLRespon
return &result, nil
}
func (c *BaoTaPanelClient) SystemServiceAdmin(req *SystemServiceAdminRequest) (*SystemServiceAdminResponse, error) {
params := make(map[string]any)
jsonData, _ := json.Marshal(req)
json.Unmarshal(jsonData, &params)
result := SystemServiceAdminResponse{}
err := c.sendRequestWithResult("/system?action=ServiceAdmin", params, &result)
if err != nil {
return nil, err
}
return &result, nil
}
func (c *BaoTaPanelClient) generateSignature(timestamp string) string {
keyMd5 := md5.Sum([]byte(c.apiKey))
keyMd5Hex := strings.ToLower(hex.EncodeToString(keyMd5[:]))