From 8625146851ec7d65669074e94bfedf35b0e9b072 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Mon, 22 Jun 2026 17:41:44 +0800 Subject: [PATCH] fix: #1346 --- pkg/core/certmgr/providers/1panel/1panel.go | 24 +++------ pkg/core/deployer/providers/1panel/1panel.go | 11 ++-- pkg/sdk3rd/1panel/api_website_get.go | 22 +------- pkg/sdk3rd/1panel/api_website_https_get.go | 9 +--- pkg/sdk3rd/1panel/api_website_search.go | 17 +------ pkg/sdk3rd/1panel/api_website_ssl_get.go | 50 ------------------ pkg/sdk3rd/1panel/api_website_ssl_search.go | 13 +---- pkg/sdk3rd/1panel/models.go | 51 +++++++++++++++++++ pkg/sdk3rd/1panel/v2/api_website_get.go | 22 +------- pkg/sdk3rd/1panel/v2/api_website_https_get.go | 10 +--- pkg/sdk3rd/1panel/v2/api_website_search.go | 30 ++++------- pkg/sdk3rd/1panel/v2/api_website_ssl_get.go | 50 ------------------ .../1panel/v2/api_website_ssl_search.go | 13 +---- pkg/sdk3rd/1panel/v2/models.go | 21 ++++++++ 14 files changed, 100 insertions(+), 243 deletions(-) delete mode 100644 pkg/sdk3rd/1panel/api_website_ssl_get.go create mode 100644 pkg/sdk3rd/1panel/models.go delete mode 100644 pkg/sdk3rd/1panel/v2/api_website_ssl_get.go create mode 100644 pkg/sdk3rd/1panel/v2/models.go diff --git a/pkg/core/certmgr/providers/1panel/1panel.go b/pkg/core/certmgr/providers/1panel/1panel.go index bb826ca16..136c7b094 100644 --- a/pkg/core/certmgr/providers/1panel/1panel.go +++ b/pkg/core/certmgr/providers/1panel/1panel.go @@ -134,18 +134,11 @@ func (c *Certmgr) Replace(ctx context.Context, certIdOrName string, certPEM, pri switch sdkClient := c.sdkClient.(type) { case *onepanelsdk.Client: { - // 获取证书详情 - websiteSSLGetResp, err := sdkClient.WebsiteSSLGetWithContext(ctx, sslId) - c.logger.Debug("sdk request 'WebsiteSSLGet'", slog.Int64("params.sslId", sslId), slog.Any("response", websiteSSLGetResp)) - if err != nil { - return nil, fmt.Errorf("failed to execute sdk request 'WebsiteSSLGet': %w", err) - } - // 更新证书 websiteSSLUploadReq := &onepanelsdk.WebsiteSSLUploadRequest{ SSLID: sslId, Type: "paste", - Description: websiteSSLGetResp.Data.Description, + Description: "upload from certimate", Certificate: certPEM, PrivateKey: privkeyPEM, } @@ -158,18 +151,11 @@ func (c *Certmgr) Replace(ctx context.Context, certIdOrName string, certPEM, pri case *onepanelsdk2.Client: { - // 获取证书详情 - websiteSSLGetResp, err := sdkClient.WebsiteSSLGetWithContext(ctx, sslId) - c.logger.Debug("sdk request 'WebsiteSSLGet'", slog.Int64("params.sslId", sslId), slog.Any("response", websiteSSLGetResp)) - if err != nil { - return nil, fmt.Errorf("failed to execute sdk request 'WebsiteSSLGet': %w", err) - } - // 更新证书 websiteSSLUploadReq := &onepanelsdk2.WebsiteSSLUploadRequest{ SSLID: sslId, Type: "paste", - Description: websiteSSLGetResp.Data.Description, + Description: "upload from certimate", Certificate: certPEM, PrivateKey: privkeyPEM, } @@ -228,7 +214,8 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM, privkey } } - if len(websiteSSLSearchResp.Data.Items) < int(websiteSSLSearchResp.Data.Total) { + if len(websiteSSLSearchResp.Data.Items) < searchWebsiteSSLPageSize || + searchWebsiteSSLPage*searchWebsiteSSLPageSize >= int(websiteSSLSearchResp.Data.Total) { break } @@ -277,7 +264,8 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM, privkey } } - if len(websiteSSLSearchResp.Data.Items) < int(websiteSSLSearchResp.Data.Total) { + if len(websiteSSLSearchResp.Data.Items) < searchWebsiteSSLPageSize || + searchWebsiteSSLPage*searchWebsiteSSLPageSize >= int(websiteSSLSearchResp.Data.Total) { break } diff --git a/pkg/core/deployer/providers/1panel/1panel.go b/pkg/core/deployer/providers/1panel/1panel.go index 7d4819130..edcaaeb39 100644 --- a/pkg/core/deployer/providers/1panel/1panel.go +++ b/pkg/core/deployer/providers/1panel/1panel.go @@ -1,6 +1,7 @@ package onepanel import ( + "cmp" "context" "crypto/tls" "errors" @@ -339,14 +340,11 @@ func (d *Deployer) updateWebsiteCertificate(ctx context.Context, websiteId int64 Type: "existed", WebsiteSSLID: websiteSSLId, Enable: true, - HttpConfig: websiteHttpsGetResp.Data.HttpConfig, + HttpConfig: cmp.Or(websiteHttpsGetResp.Data.HttpConfig, "HTTPToHTTPS"), SSLProtocol: websiteHttpsGetResp.Data.SSLProtocol, Algorithm: websiteHttpsGetResp.Data.Algorithm, Hsts: websiteHttpsGetResp.Data.Hsts, } - if websiteHttpsPostReq.HttpConfig == "" { - websiteHttpsPostReq.HttpConfig = "HTTPToHTTPS" - } websiteHttpsPostResp, err := sdkClient.WebsiteHttpsPostWithContext(ctx, websiteId, websiteHttpsPostReq) d.logger.Debug("sdk request 'WebsiteHttpsPost'", slog.Int64("params.websiteId", websiteId), slog.Any("request", websiteHttpsPostReq), slog.Any("response", websiteHttpsPostResp)) if err != nil { @@ -373,15 +371,12 @@ func (d *Deployer) updateWebsiteCertificate(ctx context.Context, websiteId int64 Type: "existed", WebsiteSSLID: websiteSSLId, Enable: true, - HttpConfig: websiteHttpsGetResp.Data.HttpConfig, + HttpConfig: cmp.Or(websiteHttpsGetResp.Data.HttpConfig, "HTTPToHTTPS"), SSLProtocol: websiteHttpsGetResp.Data.SSLProtocol, Algorithm: websiteHttpsGetResp.Data.Algorithm, Hsts: websiteHttpsGetResp.Data.Hsts, Http3: websiteHttpsGetResp.Data.Http3, } - if websiteHttpsPostReq.HttpConfig == "" { - websiteHttpsPostReq.HttpConfig = "HTTPToHTTPS" - } websiteHttpsPostResp, err := sdkClient.WebsiteHttpsPostWithContext(ctx, websiteId, websiteHttpsPostReq) d.logger.Debug("sdk request 'WebsiteHttpsPost'", slog.Int64("params.websiteId", websiteId), slog.Any("request", websiteHttpsPostReq), slog.Any("response", websiteHttpsPostResp)) if err != nil { diff --git a/pkg/sdk3rd/1panel/api_website_get.go b/pkg/sdk3rd/1panel/api_website_get.go index cd67ebb1d..c86cc900f 100644 --- a/pkg/sdk3rd/1panel/api_website_get.go +++ b/pkg/sdk3rd/1panel/api_website_get.go @@ -16,27 +16,7 @@ type WebsiteGetRequest struct { type WebsiteGetResponse struct { sdkResponseBase - Data *struct { - ID int64 `json:"id"` - Alias string `json:"alias"` - PrimaryDomain string `json:"primaryDomain"` - Protocol string `json:"protocol"` - Type string `json:"type"` - Status string `json:"status"` - SitePath string `json:"sitePath"` - Remark string `json:"remark"` - Domains []*struct { - ID int64 `json:"id"` - Domain string `json:"domain"` - Port int32 `json:"port"` - SSL bool `json:"ssl"` - UpdatedAt string `json:"updatedAt"` - CreatedAt string `json:"createdAt"` - } `json:"domains"` - WebsiteSSLId int64 `json:"webSiteSSLId"` - UpdatedAt string `json:"updatedAt"` - CreatedAt string `json:"createdAt"` - } `json:"data,omitempty"` + Data *WebsiteDetail `json:"data,omitempty"` } func (c *Client) WebsiteGet(websiteId int64) (*WebsiteGetResponse, error) { diff --git a/pkg/sdk3rd/1panel/api_website_https_get.go b/pkg/sdk3rd/1panel/api_website_https_get.go index 6db52d9b5..94e7f4eaf 100644 --- a/pkg/sdk3rd/1panel/api_website_https_get.go +++ b/pkg/sdk3rd/1panel/api_website_https_get.go @@ -9,14 +9,7 @@ import ( type WebsiteHttpsGetResponse struct { sdkResponseBase - Data *struct { - Enable bool `json:"enable"` - WebsiteSSLID int64 `json:"websiteSSLId"` - HttpConfig string `json:"httpConfig"` - SSLProtocol []string `json:"SSLProtocol"` - Algorithm string `json:"algorithm"` - Hsts bool `json:"hsts"` - } `json:"data,omitempty"` + Data *WebsiteHTTPSConfig `json:"data,omitempty"` } func (c *Client) WebsiteHttpsGet(websiteId int64) (*WebsiteHttpsGetResponse, error) { diff --git a/pkg/sdk3rd/1panel/api_website_search.go b/pkg/sdk3rd/1panel/api_website_search.go index 9112fa168..821e5327b 100644 --- a/pkg/sdk3rd/1panel/api_website_search.go +++ b/pkg/sdk3rd/1panel/api_website_search.go @@ -18,21 +18,8 @@ type WebsiteSearchResponse struct { sdkResponseBase Data *struct { - Items []*struct { - ID int64 `json:"id"` - Alias string `json:"alias"` - PrimaryDomain string `json:"primaryDomain"` - Protocol string `json:"protocol"` - Type string `json:"type"` - Status string `json:"status"` - SitePath string `json:"sitePath"` - Remark string `json:"remark"` - SSLStatus string `json:"sslStatus"` - SSLExpireDate string `json:"sslExpireDate"` - UpdatedAt string `json:"updatedAt"` - CreatedAt string `json:"createdAt"` - } `json:"items"` - Total int32 `json:"total"` + Items []*Website `json:"items"` + Total int32 `json:"total"` } `json:"data,omitempty"` } diff --git a/pkg/sdk3rd/1panel/api_website_ssl_get.go b/pkg/sdk3rd/1panel/api_website_ssl_get.go deleted file mode 100644 index b1540a8b6..000000000 --- a/pkg/sdk3rd/1panel/api_website_ssl_get.go +++ /dev/null @@ -1,50 +0,0 @@ -package onepanel - -import ( - "context" - "fmt" - "net/http" -) - -type WebsiteSSLGetResponse struct { - sdkResponseBase - - 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) WebsiteSSLGet(sslId int64) (*WebsiteSSLGetResponse, error) { - return c.WebsiteSSLGetWithContext(context.Background(), sslId) -} - -func (c *Client) WebsiteSSLGetWithContext(ctx context.Context, sslId int64) (*WebsiteSSLGetResponse, error) { - if sslId == 0 { - return nil, fmt.Errorf("sdkerr: bad request: 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 := &WebsiteSSLGetResponse{} - if _, err := c.doRequestWithResult(httpreq, result); err != nil { - return result, err - } - - return result, nil -} diff --git a/pkg/sdk3rd/1panel/api_website_ssl_search.go b/pkg/sdk3rd/1panel/api_website_ssl_search.go index 3dc754f80..3c59c1913 100644 --- a/pkg/sdk3rd/1panel/api_website_ssl_search.go +++ b/pkg/sdk3rd/1panel/api_website_ssl_search.go @@ -15,17 +15,8 @@ type WebsiteSSLSearchResponse struct { sdkResponseBase 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"` + Items []*SSLCertificate `json:"items"` + Total int32 `json:"total"` } `json:"data,omitempty"` } diff --git a/pkg/sdk3rd/1panel/models.go b/pkg/sdk3rd/1panel/models.go new file mode 100644 index 000000000..eba3bdaae --- /dev/null +++ b/pkg/sdk3rd/1panel/models.go @@ -0,0 +1,51 @@ +package onepanel + +type Website struct { + ID int64 `json:"id"` + Alias string `json:"alias"` + PrimaryDomain string `json:"primaryDomain"` + Protocol string `json:"protocol"` + Type string `json:"type"` + Status string `json:"status"` + SitePath string `json:"sitePath"` + Remark string `json:"remark"` + SSLStatus string `json:"sslStatus,omitempty"` + SSLExpireDate string `json:"sslExpireDate,omitempty"` + WebsiteSSLID int64 `json:"webSiteSSLId,omitempty"` + UpdatedAt string `json:"updatedAt"` + CreatedAt string `json:"createdAt"` +} + +type WebsiteDetail struct { + Website + Domains []*WebsiteDomainConfig `json:"domains"` +} + +type WebsiteDomainConfig struct { + ID int64 `json:"id"` + Domain string `json:"domain"` + Port int32 `json:"port"` + SSL bool `json:"ssl"` + UpdatedAt string `json:"updatedAt"` + CreatedAt string `json:"createdAt"` +} + +type WebsiteHTTPSConfig struct { + Enable bool `json:"enable"` + WebsiteSSLID int64 `json:"websiteSSLId"` + HttpConfig string `json:"httpConfig"` + SSLProtocol []string `json:"SSLProtocol"` + Algorithm string `json:"algorithm"` + Hsts bool `json:"hsts"` +} + +type SSLCertificate 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"` +} diff --git a/pkg/sdk3rd/1panel/v2/api_website_get.go b/pkg/sdk3rd/1panel/v2/api_website_get.go index 9574ca595..a4e9f9520 100644 --- a/pkg/sdk3rd/1panel/v2/api_website_get.go +++ b/pkg/sdk3rd/1panel/v2/api_website_get.go @@ -16,27 +16,7 @@ type WebsiteGetRequest struct { type WebsiteGetResponse struct { sdkResponseBase - Data *struct { - ID int64 `json:"id"` - Alias string `json:"alias"` - PrimaryDomain string `json:"primaryDomain"` - Protocol string `json:"protocol"` - Type string `json:"type"` - Status string `json:"status"` - SitePath string `json:"sitePath"` - Remark string `json:"remark"` - Domains []*struct { - ID int64 `json:"id"` - Domain string `json:"domain"` - Port int32 `json:"port"` - SSL bool `json:"ssl"` - UpdatedAt string `json:"updatedAt"` - CreatedAt string `json:"createdAt"` - } `json:"domains,omitempty"` - WebsiteSSLId int64 `json:"webSiteSSLId"` - UpdatedAt string `json:"updatedAt"` - CreatedAt string `json:"createdAt"` - } `json:"data,omitempty"` + Data *WebsiteDetail `json:"data,omitempty"` } func (c *Client) WebsiteGet(websiteId int64) (*WebsiteGetResponse, error) { diff --git a/pkg/sdk3rd/1panel/v2/api_website_https_get.go b/pkg/sdk3rd/1panel/v2/api_website_https_get.go index 30261c985..59b2e9a20 100644 --- a/pkg/sdk3rd/1panel/v2/api_website_https_get.go +++ b/pkg/sdk3rd/1panel/v2/api_website_https_get.go @@ -9,15 +9,7 @@ import ( type WebsiteHttpsGetResponse struct { sdkResponseBase - Data *struct { - Enable bool `json:"enable"` - HttpConfig string `json:"httpConfig"` - WebsiteSSLID int64 `json:"websiteSSLId"` - SSLProtocol []string `json:"SSLProtocol"` - Algorithm string `json:"algorithm"` - Hsts bool `json:"hsts"` - Http3 bool `json:"http3"` - } `json:"data,omitempty"` + Data *WebsiteHTTPSConfig `json:"data,omitempty"` } func (c *Client) WebsiteHttpsGet(websiteId int64) (*WebsiteHttpsGetResponse, error) { diff --git a/pkg/sdk3rd/1panel/v2/api_website_search.go b/pkg/sdk3rd/1panel/v2/api_website_search.go index 00d7196c2..6943b97f3 100644 --- a/pkg/sdk3rd/1panel/v2/api_website_search.go +++ b/pkg/sdk3rd/1panel/v2/api_website_search.go @@ -6,33 +6,21 @@ import ( ) type WebsiteSearchRequest struct { - Name string `json:"name"` - Type string `json:"type"` - Order string `json:"order"` - OrderBy string `json:"orderBy"` - Page int32 `json:"page"` - PageSize int32 `json:"pageSize"` + WebsiteGroupId int64 `json:"websiteGroupId"` + Name string `json:"name"` + Type string `json:"type"` + Order string `json:"order"` + OrderBy string `json:"orderBy"` + Page int32 `json:"page"` + PageSize int32 `json:"pageSize"` } type WebsiteSearchResponse struct { sdkResponseBase Data *struct { - Items []*struct { - ID int64 `json:"id"` - Alias string `json:"alias"` - PrimaryDomain string `json:"primaryDomain"` - Protocol string `json:"protocol"` - Type string `json:"type"` - Status string `json:"status"` - SitePath string `json:"sitePath"` - Remark string `json:"remark"` - SSLStatus string `json:"sslStatus"` - SSLExpireDate string `json:"sslExpireDate"` - UpdatedAt string `json:"updatedAt"` - CreatedAt string `json:"createdAt"` - } `json:"items"` - Total int32 `json:"total"` + Items []*Website `json:"items"` + Total int32 `json:"total"` } `json:"data,omitempty"` } diff --git a/pkg/sdk3rd/1panel/v2/api_website_ssl_get.go b/pkg/sdk3rd/1panel/v2/api_website_ssl_get.go deleted file mode 100644 index efdc0ed6f..000000000 --- a/pkg/sdk3rd/1panel/v2/api_website_ssl_get.go +++ /dev/null @@ -1,50 +0,0 @@ -package v2 - -import ( - "context" - "fmt" - "net/http" -) - -type WebsiteSSLGetResponse struct { - sdkResponseBase - - 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) WebsiteSSLGet(sslId int64) (*WebsiteSSLGetResponse, error) { - return c.WebsiteSSLGetWithContext(context.Background(), sslId) -} - -func (c *Client) WebsiteSSLGetWithContext(ctx context.Context, sslId int64) (*WebsiteSSLGetResponse, error) { - if sslId == 0 { - return nil, fmt.Errorf("sdkerr: bad request: 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 := &WebsiteSSLGetResponse{} - if _, err := c.doRequestWithResult(httpreq, result); err != nil { - return result, err - } - - return result, nil -} diff --git a/pkg/sdk3rd/1panel/v2/api_website_ssl_search.go b/pkg/sdk3rd/1panel/v2/api_website_ssl_search.go index ff9a3ccca..fda36fe91 100644 --- a/pkg/sdk3rd/1panel/v2/api_website_ssl_search.go +++ b/pkg/sdk3rd/1panel/v2/api_website_ssl_search.go @@ -17,17 +17,8 @@ type WebsiteSSLSearchResponse struct { sdkResponseBase 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"` + Items []*SSLCertificate `json:"items"` + Total int32 `json:"total"` } `json:"data,omitempty"` } diff --git a/pkg/sdk3rd/1panel/v2/models.go b/pkg/sdk3rd/1panel/v2/models.go new file mode 100644 index 000000000..69b50032d --- /dev/null +++ b/pkg/sdk3rd/1panel/v2/models.go @@ -0,0 +1,21 @@ +package v2 + +import ( + v1 "github.com/certimate-go/certimate/pkg/sdk3rd/1panel" +) + +type Website v1.Website + +type WebsiteDetail struct { + Website + Domains []*WebsiteDomainConfig `json:"domains"` +} + +type WebsiteDomainConfig v1.WebsiteDomainConfig + +type WebsiteHTTPSConfig struct { + v1.WebsiteHTTPSConfig + Http3 bool `json:"http3"` +} + +type SSLCertificate v1.SSLCertificate