mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-19 02:39:57 +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:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
listListenerReq := &ctyunelb.ListListenerRequest{
|
listListenersReq := &ctyunelb.ListListenersRequest{
|
||||||
RegionID: typeutil.ToPtr(d.config.RegionId),
|
RegionID: typeutil.ToPtr(d.config.RegionId),
|
||||||
LoadBalancerID: typeutil.ToPtr(d.config.LoadbalancerId),
|
LoadBalancerID: typeutil.ToPtr(d.config.LoadbalancerId),
|
||||||
}
|
}
|
||||||
listListenerResp, err := d.sdkClient.ListListener(listListenerReq)
|
listListenersResp, err := d.sdkClient.ListListeners(listListenersReq)
|
||||||
d.logger.Debug("sdk request 'elb.ListListener'", slog.Any("request", listListenerReq), slog.Any("response", listListenerResp))
|
d.logger.Debug("sdk request 'elb.ListListeners'", slog.Any("request", listListenersReq), slog.Any("response", listListenersResp))
|
||||||
if err != nil {
|
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") {
|
if strings.EqualFold(listener.Protocol, "HTTPS") {
|
||||||
listenerIds = append(listenerIds, listener.ID)
|
listenerIds = append(listenerIds, listener.ID)
|
||||||
}
|
}
|
||||||
|
@ -73,19 +73,19 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
listCertReq := &ctyunao.ListCertRequest{
|
listCertsReq := &ctyunao.ListCertsRequest{
|
||||||
Page: typeutil.ToPtr(listCertPage),
|
Page: typeutil.ToPtr(listCertPage),
|
||||||
PerPage: typeutil.ToPtr(listCertPerPage),
|
PerPage: typeutil.ToPtr(listCertPerPage),
|
||||||
UsageMode: typeutil.ToPtr(int32(0)),
|
UsageMode: typeutil.ToPtr(int32(0)),
|
||||||
}
|
}
|
||||||
listCertResp, err := u.sdkClient.ListCert(listCertReq)
|
listCertsResp, err := u.sdkClient.ListCerts(listCertsReq)
|
||||||
u.logger.Debug("sdk request 'ao.ListCert'", slog.Any("request", listCertReq), slog.Any("response", listCertResp))
|
u.logger.Debug("sdk request 'ao.ListCerts'", slog.Any("request", listCertsReq), slog.Any("response", listCertsResp))
|
||||||
if err != nil {
|
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 {
|
if listCertsResp.ReturnObj != nil {
|
||||||
for _, certRecord := range listCertResp.ReturnObj.Results {
|
for _, certRecord := range listCertsResp.ReturnObj.Results {
|
||||||
// 对比证书通用名称
|
// 对比证书通用名称
|
||||||
if !strings.EqualFold(certX509.Subject.CommonName, certRecord.CN) {
|
if !strings.EqualFold(certX509.Subject.CommonName, certRecord.CN) {
|
||||||
continue
|
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
|
break
|
||||||
} else {
|
} else {
|
||||||
listCertPage++
|
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
|
// 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),
|
RegionID: typeutil.ToPtr(u.config.RegionId),
|
||||||
}
|
}
|
||||||
listCertificateResp, err := u.sdkClient.ListCertificate(listCertificateReq)
|
listCertificatesResp, err := u.sdkClient.ListCertificates(listCertificatesReq)
|
||||||
u.logger.Debug("sdk request 'elb.ListCertificate'", slog.Any("request", listCertificateReq), slog.Any("response", listCertificateResp))
|
u.logger.Debug("sdk request 'elb.ListCertificates'", slog.Any("request", listCertificatesReq), slog.Any("response", listCertificatesResp))
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
for _, certRecord := range listCertificateResp.ReturnObj {
|
for _, certRecord := range listCertificatesResp.ReturnObj {
|
||||||
var isSameCert bool
|
var isSameCert bool
|
||||||
if certRecord.Certificate == certPEM {
|
if certRecord.Certificate == certPEM {
|
||||||
isSameCert = true
|
isSameCert = true
|
||||||
|
@ -31,7 +31,7 @@ func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigR
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetDomainConfigWithContext(ctx context.Context, req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,13 +6,13 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListCertRequest struct {
|
type ListCertsRequest struct {
|
||||||
Page *int32 `json:"page,omitempty"`
|
Page *int32 `json:"page,omitempty"`
|
||||||
PerPage *int32 `json:"per_page,omitempty"`
|
PerPage *int32 `json:"per_page,omitempty"`
|
||||||
UsageMode *int32 `json:"usage_mode,omitempty"`
|
UsageMode *int32 `json:"usage_mode,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCertResponse struct {
|
type ListCertsResponse struct {
|
||||||
baseResult
|
baseResult
|
||||||
|
|
||||||
ReturnObj *struct {
|
ReturnObj *struct {
|
||||||
@ -24,11 +24,11 @@ type ListCertResponse struct {
|
|||||||
} `json:"returnObj,omitempty"`
|
} `json:"returnObj,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ListCert(req *ListCertRequest) (*ListCertResponse, error) {
|
func (c *Client) ListCerts(req *ListCertsRequest) (*ListCertsResponse, error) {
|
||||||
return c.ListCertWithContext(context.Background(), req)
|
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")
|
httpreq, err := c.newRequest(http.MethodGet, "/ctapi/v1/accessone/cert/list")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -46,7 +46,7 @@ func (c *Client) ListCertWithContext(ctx context.Context, req *ListCertRequest)
|
|||||||
httpreq.SetContext(ctx)
|
httpreq.SetContext(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := &ListCertResponse{}
|
result := &ListCertsResponse{}
|
||||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListCertificateRequest struct {
|
type ListCertificatesRequest struct {
|
||||||
ClientToken *string `json:"clientToken,omitempty"`
|
ClientToken *string `json:"clientToken,omitempty"`
|
||||||
RegionID *string `json:"regionID,omitempty"`
|
RegionID *string `json:"regionID,omitempty"`
|
||||||
IDs *string `json:"IDs,omitempty"`
|
IDs *string `json:"IDs,omitempty"`
|
||||||
@ -13,17 +13,17 @@ type ListCertificateRequest struct {
|
|||||||
Type *string `json:"type,omitempty"`
|
Type *string `json:"type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCertificateResponse struct {
|
type ListCertificatesResponse struct {
|
||||||
baseResult
|
baseResult
|
||||||
|
|
||||||
ReturnObj []*CertificateRecord `json:"returnObj,omitempty"`
|
ReturnObj []*CertificateRecord `json:"returnObj,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ListCertificate(req *ListCertificateRequest) (*ListCertificateResponse, error) {
|
func (c *Client) ListCertificates(req *ListCertificatesRequest) (*ListCertificatesResponse, error) {
|
||||||
return c.ListCertificateWithContext(context.Background(), req)
|
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")
|
httpreq, err := c.newRequest(http.MethodGet, "/v4/elb/list-certificate")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -47,7 +47,7 @@ func (c *Client) ListCertificateWithContext(ctx context.Context, req *ListCertif
|
|||||||
httpreq.SetContext(ctx)
|
httpreq.SetContext(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := &ListCertificateResponse{}
|
result := &ListCertificatesResponse{}
|
||||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListListenerRequest struct {
|
type ListListenersRequest struct {
|
||||||
ClientToken *string `json:"clientToken,omitempty"`
|
ClientToken *string `json:"clientToken,omitempty"`
|
||||||
RegionID *string `json:"regionID,omitempty"`
|
RegionID *string `json:"regionID,omitempty"`
|
||||||
ProjectID *string `json:"projectID,omitempty"`
|
ProjectID *string `json:"projectID,omitempty"`
|
||||||
@ -15,17 +15,17 @@ type ListListenerRequest struct {
|
|||||||
AccessControlID *string `json:"accessControlID,omitempty"`
|
AccessControlID *string `json:"accessControlID,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListListenerResponse struct {
|
type ListListenersResponse struct {
|
||||||
baseResult
|
baseResult
|
||||||
|
|
||||||
ReturnObj []*ListenerRecord `json:"returnObj,omitempty"`
|
ReturnObj []*ListenerRecord `json:"returnObj,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ListListener(req *ListListenerRequest) (*ListListenerResponse, error) {
|
func (c *Client) ListListeners(req *ListListenersRequest) (*ListListenersResponse, error) {
|
||||||
return c.ListListenerWithContext(context.Background(), req)
|
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")
|
httpreq, err := c.newRequest(http.MethodGet, "/v4/elb/list-listener")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -55,7 +55,7 @@ func (c *Client) ListListenerWithContext(ctx context.Context, req *ListListenerR
|
|||||||
httpreq.SetContext(ctx)
|
httpreq.SetContext(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := &ListListenerResponse{}
|
result := &ListListenersResponse{}
|
||||||
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user