mirror of
https://github.com/certimate-go/certimate.git
synced 2026-09-24 23:10:13 +08:00
refactor: clean code
This commit is contained in:
@@ -98,7 +98,7 @@ func (ne *bizApplyNodeExecutor) Execute(execCtx *NodeExecutionContext) (*NodeExe
|
||||
}
|
||||
|
||||
// 申请证书
|
||||
obtainResp, err := ne.executeObtain(execCtx, &nodeCfg, lastCertificate)
|
||||
obtainResp, err := ne.execObtainCertificate(execCtx, &nodeCfg, lastCertificate)
|
||||
if err != nil {
|
||||
return execRes, err
|
||||
}
|
||||
@@ -228,7 +228,7 @@ func (ne *bizApplyNodeExecutor) checkCanSkip(execCtx *NodeExecutionContext, last
|
||||
return false, ""
|
||||
}
|
||||
|
||||
func (ne *bizApplyNodeExecutor) executeObtain(execCtx *NodeExecutionContext, nodeCfg *domain.WorkflowNodeConfigForBizApply, lastCertificate *domain.Certificate) (*certacme.ObtainCertificateResponse, error) {
|
||||
func (ne *bizApplyNodeExecutor) execObtainCertificate(execCtx *NodeExecutionContext, nodeCfg *domain.WorkflowNodeConfigForBizApply, lastCertificate *domain.Certificate) (*certacme.ObtainCertificateResponse, error) {
|
||||
// 读取私钥算法
|
||||
// 如果复用私钥,则保持算法一致
|
||||
keyAlgorithm := domain.CertificateKeyAlgorithmType(nodeCfg.KeyAlgorithm)
|
||||
|
||||
@@ -68,7 +68,7 @@ func (ne *bizMonitorNodeExecutor) Execute(execCtx *NodeExecutionContext) (*NodeE
|
||||
}
|
||||
}
|
||||
|
||||
certs, err = ne.tryRetrievePeerCertificates(execCtx, targetAddr, targetDomain, nodeCfg.RequestPath)
|
||||
certs, err = ne.execRetrieveCertificates(execCtx, targetAddr, targetDomain, nodeCfg.RequestPath)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (ne *bizMonitorNodeExecutor) Execute(execCtx *NodeExecutionContext) (*NodeE
|
||||
return execRes, nil
|
||||
}
|
||||
|
||||
func (ne *bizMonitorNodeExecutor) tryRetrievePeerCertificates(execCtx *NodeExecutionContext, addr, domain, requestPath string) ([]*x509.Certificate, error) {
|
||||
func (ne *bizMonitorNodeExecutor) execRetrieveCertificates(execCtx *NodeExecutionContext, addr, domain, requestPath string) ([]*x509.Certificate, error) {
|
||||
transport := xhttp.NewDefaultTransport()
|
||||
transport.DisableKeepAlives = true
|
||||
transport.TLSClientConfig = xtls.NewInsecureConfig()
|
||||
|
||||
@@ -132,6 +132,14 @@ func (ne *bizUploadNodeExecutor) Execute(execCtx *NodeExecutionContext) (*NodeEx
|
||||
return execRes, fmt.Errorf("unsupported upload source: '%s'", nodeCfg.Source)
|
||||
}
|
||||
|
||||
// 二次检测是否可以跳过执行
|
||||
if lastCertificate != nil {
|
||||
if xcert.EqualCertificatesFromPEM(certPEM, lastCertificate.Certificate) {
|
||||
ne.logger.Info("skip this uploading, because the last uploaded certificate already exists")
|
||||
return execRes, nil
|
||||
}
|
||||
}
|
||||
|
||||
// 验证证书
|
||||
certX509, err := xcert.ParseCertificateFromPEM(certPEM)
|
||||
if err != nil {
|
||||
@@ -143,7 +151,7 @@ func (ne *bizUploadNodeExecutor) Execute(execCtx *NodeExecutionContext) (*NodeEx
|
||||
// 验证私钥
|
||||
privkey, err := xcert.ParsePrivateKeyFromPEM(privkeyPEM)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return execRes, err
|
||||
} else {
|
||||
matched := false
|
||||
switch pub := certX509.PublicKey.(type) {
|
||||
@@ -165,14 +173,6 @@ func (ne *bizUploadNodeExecutor) Execute(execCtx *NodeExecutionContext) (*NodeEx
|
||||
}
|
||||
}
|
||||
|
||||
// 二次检测是否可以跳过执行
|
||||
if lastCertificate != nil {
|
||||
if xcert.EqualCertificatesFromPEM(certPEM, lastCertificate.Certificate) {
|
||||
ne.logger.Info("skip this uploading, because the last uploaded certificate already exists")
|
||||
return execRes, nil
|
||||
}
|
||||
}
|
||||
|
||||
// 保存证书实体
|
||||
certificate := &domain.Certificate{
|
||||
Source: domain.CertificateSourceTypeUpload,
|
||||
|
||||
Reference in New Issue
Block a user