mirror of
https://github.com/certimate-go/certimate.git
synced 2026-09-24 23:10:13 +08:00
fix: #1346
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user