mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-19 10:50:13 +00:00
refactor: clean code
This commit is contained in:
parent
94a0292fad
commit
769b24aa88
@ -119,17 +119,17 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId
|
||||
default:
|
||||
}
|
||||
|
||||
listListenerReq := &ctyunelb.ListListenerRequest{
|
||||
listListenersReq := &ctyunelb.ListListenersRequest{
|
||||
RegionID: typeutil.ToPtr(d.config.RegionId),
|
||||
LoadBalancerID: typeutil.ToPtr(d.config.LoadbalancerId),
|
||||
}
|
||||
listListenerResp, err := d.sdkClient.ListListener(listListenerReq)
|
||||
d.logger.Debug("sdk request 'elb.ListListener'", slog.Any("request", listListenerReq), slog.Any("response", listListenerResp))
|
||||
listListenersResp, err := d.sdkClient.ListListeners(listListenersReq)
|
||||
d.logger.Debug("sdk request 'elb.ListListeners'", slog.Any("request", listListenersReq), slog.Any("response", listListenersResp))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute sdk request 'elb.ListListener': %w", err)
|
||||
return fmt.Errorf("failed to execute sdk request 'elb.ListListeners': %w", err)
|
||||
}
|
||||
|
||||
for _, listener := range listListenerResp.ReturnObj {
|
||||
for _, listener := range listListenersResp.ReturnObj {
|
||||
if strings.EqualFold(listener.Protocol, "HTTPS") {
|
||||
listenerIds = append(listenerIds, listener.ID)
|
||||
}
|
||||
|
@ -73,19 +73,19 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE
|
||||
default:
|
||||
}
|
||||
|
||||
listCertReq := &ctyunao.ListCertRequest{
|
||||
listCertsReq := &ctyunao.ListCertsRequest{
|
||||
Page: typeutil.ToPtr(listCertPage),
|
||||
PerPage: typeutil.ToPtr(listCertPerPage),
|
||||
UsageMode: typeutil.ToPtr(int32(0)),
|
||||
}
|
||||
listCertResp, err := u.sdkClient.ListCert(listCertReq)
|
||||
u.logger.Debug("sdk request 'ao.ListCert'", slog.Any("request", listCertReq), slog.Any("response", listCertResp))
|
||||
listCertsResp, err := u.sdkClient.ListCerts(listCertsReq)
|
||||
u.logger.Debug("sdk request 'ao.ListCerts'", slog.Any("request", listCertsReq), slog.Any("response", listCertsResp))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'ao.ListCert': %w", err)
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'ao.ListCerts': %w", err)
|
||||
}
|
||||
|
||||
if listCertResp.ReturnObj != nil {
|
||||
for _, certRecord := range listCertResp.ReturnObj.Results {
|
||||
if listCertsResp.ReturnObj != nil {
|
||||
for _, certRecord := range listCertsResp.ReturnObj.Results {
|
||||
// 对比证书通用名称
|
||||
if !strings.EqualFold(certX509.Subject.CommonName, certRecord.CN) {
|
||||
continue
|
||||
@ -137,7 +137,7 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE
|
||||
}
|
||||
}
|
||||
|
||||
if listCertResp.ReturnObj == nil || len(listCertResp.ReturnObj.Results) < int(listCertPerPage) {
|
||||
if listCertsResp.ReturnObj == nil || len(listCertsResp.ReturnObj.Results) < int(listCertPerPage) {
|
||||
break
|
||||
} else {
|
||||
listCertPage++
|
||||
|
@ -66,15 +66,15 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE
|
||||
|
||||
// 查询证书列表,避免重复上传
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=24&api=5692&data=88&isNormal=1&vid=82
|
||||
listCertificateReq := &ctyunelb.ListCertificateRequest{
|
||||
listCertificatesReq := &ctyunelb.ListCertificatesRequest{
|
||||
RegionID: typeutil.ToPtr(u.config.RegionId),
|
||||
}
|
||||
listCertificateResp, err := u.sdkClient.ListCertificate(listCertificateReq)
|
||||
u.logger.Debug("sdk request 'elb.ListCertificate'", slog.Any("request", listCertificateReq), slog.Any("response", listCertificateResp))
|
||||
listCertificatesResp, err := u.sdkClient.ListCertificates(listCertificatesReq)
|
||||
u.logger.Debug("sdk request 'elb.ListCertificates'", slog.Any("request", listCertificatesReq), slog.Any("response", listCertificatesResp))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'elb.ListCertificate': %w", err)
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'elb.ListCertificates': %w", err)
|
||||
} else {
|
||||
for _, certRecord := range listCertificateResp.ReturnObj {
|
||||
for _, certRecord := range listCertificatesResp.ReturnObj {
|
||||
var isSameCert bool
|
||||
if certRecord.Certificate == certPEM {
|
||||
isSameCert = true
|
||||
|
@ -31,7 +31,7 @@ func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigR
|
||||
}
|
||||
|
||||
func (c *Client) GetDomainConfigWithContext(ctx context.Context, req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/ctapi/v1/accessone/domain/config")
|
||||
httpreq, err := c.newRequest(http.MethodPost, "/ctapi/v1/accessone/domain/config")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
@ -6,13 +6,13 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ListCertRequest struct {
|
||||
type ListCertsRequest struct {
|
||||
Page *int32 `json:"page,omitempty"`
|
||||
PerPage *int32 `json:"per_page,omitempty"`
|
||||
UsageMode *int32 `json:"usage_mode,omitempty"`
|
||||
}
|
||||
|
||||
type ListCertResponse struct {
|
||||
type ListCertsResponse struct {
|
||||
baseResult
|
||||
|
||||
ReturnObj *struct {
|
||||
@ -24,11 +24,11 @@ type ListCertResponse struct {
|
||||
} `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ListCert(req *ListCertRequest) (*ListCertResponse, error) {
|
||||
return c.ListCertWithContext(context.Background(), req)
|
||||
func (c *Client) ListCerts(req *ListCertsRequest) (*ListCertsResponse, error) {
|
||||
return c.ListCertsWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) ListCertWithContext(ctx context.Context, req *ListCertRequest) (*ListCertResponse, error) {
|
||||
func (c *Client) ListCertsWithContext(ctx context.Context, req *ListCertsRequest) (*ListCertsResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/ctapi/v1/accessone/cert/list")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -46,7 +46,7 @@ func (c *Client) ListCertWithContext(ctx context.Context, req *ListCertRequest)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &ListCertResponse{}
|
||||
result := &ListCertsResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListCertificateRequest struct {
|
||||
type ListCertificatesRequest struct {
|
||||
ClientToken *string `json:"clientToken,omitempty"`
|
||||
RegionID *string `json:"regionID,omitempty"`
|
||||
IDs *string `json:"IDs,omitempty"`
|
||||
@ -13,17 +13,17 @@ type ListCertificateRequest struct {
|
||||
Type *string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
type ListCertificateResponse struct {
|
||||
type ListCertificatesResponse struct {
|
||||
baseResult
|
||||
|
||||
ReturnObj []*CertificateRecord `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ListCertificate(req *ListCertificateRequest) (*ListCertificateResponse, error) {
|
||||
return c.ListCertificateWithContext(context.Background(), req)
|
||||
func (c *Client) ListCertificates(req *ListCertificatesRequest) (*ListCertificatesResponse, error) {
|
||||
return c.ListCertificatesWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) ListCertificateWithContext(ctx context.Context, req *ListCertificateRequest) (*ListCertificateResponse, error) {
|
||||
func (c *Client) ListCertificatesWithContext(ctx context.Context, req *ListCertificatesRequest) (*ListCertificatesResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/v4/elb/list-certificate")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -47,7 +47,7 @@ func (c *Client) ListCertificateWithContext(ctx context.Context, req *ListCertif
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &ListCertificateResponse{}
|
||||
result := &ListCertificatesResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListListenerRequest struct {
|
||||
type ListListenersRequest struct {
|
||||
ClientToken *string `json:"clientToken,omitempty"`
|
||||
RegionID *string `json:"regionID,omitempty"`
|
||||
ProjectID *string `json:"projectID,omitempty"`
|
||||
@ -15,17 +15,17 @@ type ListListenerRequest struct {
|
||||
AccessControlID *string `json:"accessControlID,omitempty"`
|
||||
}
|
||||
|
||||
type ListListenerResponse struct {
|
||||
type ListListenersResponse struct {
|
||||
baseResult
|
||||
|
||||
ReturnObj []*ListenerRecord `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ListListener(req *ListListenerRequest) (*ListListenerResponse, error) {
|
||||
return c.ListListenerWithContext(context.Background(), req)
|
||||
func (c *Client) ListListeners(req *ListListenersRequest) (*ListListenersResponse, error) {
|
||||
return c.ListListenersWithContext(context.Background(), req)
|
||||
}
|
||||
|
||||
func (c *Client) ListListenerWithContext(ctx context.Context, req *ListListenerRequest) (*ListListenerResponse, error) {
|
||||
func (c *Client) ListListenersWithContext(ctx context.Context, req *ListListenersRequest) (*ListListenersResponse, error) {
|
||||
httpreq, err := c.newRequest(http.MethodGet, "/v4/elb/list-listener")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -55,7 +55,7 @@ func (c *Client) ListListenerWithContext(ctx context.Context, req *ListListenerR
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
result := &ListListenerResponse{}
|
||||
result := &ListListenersResponse{}
|
||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||
return result, err
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user