mirror of
https://github.com/usual2970/certimate.git
synced 2025-09-21 15:36:01 +00:00
refactor: clean code
This commit is contained in:
@@ -29,10 +29,10 @@ func NewApplyNode(node *domain.WorkflowNode) *applyNode {
|
||||
|
||||
type WorkflowOutputRepository interface {
|
||||
// 查询节点输出
|
||||
Get(ctx context.Context, nodeId string) (*domain.WorkflowOutput, error)
|
||||
GetByNodeId(ctx context.Context, nodeId string) (*domain.WorkflowOutput, error)
|
||||
|
||||
// 查询申请节点的证书
|
||||
GetCertificate(ctx context.Context, nodeId string) (*domain.Certificate, error)
|
||||
GetCertificateByNodeId(ctx context.Context, nodeId string) (*domain.Certificate, error)
|
||||
|
||||
// 保存节点输出
|
||||
Save(ctx context.Context, output *domain.WorkflowOutput, certificate *domain.Certificate, cb func(id string) error) error
|
||||
@@ -42,14 +42,14 @@ type WorkflowOutputRepository interface {
|
||||
func (a *applyNode) Run(ctx context.Context) error {
|
||||
a.AddOutput(ctx, a.node.Name, "开始执行")
|
||||
// 查询是否申请过,已申请过则直接返回(先保持和 v0.2 一致)
|
||||
output, err := a.outputRepo.Get(ctx, a.node.Id)
|
||||
output, err := a.outputRepo.GetByNodeId(ctx, a.node.Id)
|
||||
if err != nil && !domain.IsRecordNotFound(err) {
|
||||
a.AddOutput(ctx, a.node.Name, "查询申请记录失败", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if output != nil && output.Succeeded {
|
||||
cert, err := a.outputRepo.GetCertificate(ctx, a.node.Id)
|
||||
cert, err := a.outputRepo.GetCertificateByNodeId(ctx, a.node.Id)
|
||||
if err != nil {
|
||||
a.AddOutput(ctx, a.node.Name, "获取证书失败", err.Error())
|
||||
return err
|
||||
@@ -62,14 +62,14 @@ func (a *applyNode) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// 获取Applicant
|
||||
apply, err := applicant.GetWithApplyNode(a.node)
|
||||
applicant, err := applicant.GetWithApplyNode(a.node)
|
||||
if err != nil {
|
||||
a.AddOutput(ctx, a.node.Name, "获取申请对象失败", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
// 申请
|
||||
certificate, err := apply.Apply()
|
||||
certificate, err := applicant.Apply()
|
||||
if err != nil {
|
||||
a.AddOutput(ctx, a.node.Name, "申请失败", err.Error())
|
||||
return err
|
||||
@@ -103,8 +103,8 @@ func (a *applyNode) Run(ctx context.Context) error {
|
||||
Certificate: certificate.Certificate,
|
||||
PrivateKey: certificate.PrivateKey,
|
||||
IssuerCertificate: certificate.IssuerCertificate,
|
||||
AcmeCertUrl: certificate.CertUrl,
|
||||
AcmeCertStableUrl: certificate.CertStableUrl,
|
||||
ACMECertUrl: certificate.CertUrl,
|
||||
ACMECertStableUrl: certificate.CertStableUrl,
|
||||
EffectAt: certX509.NotBefore,
|
||||
ExpireAt: certX509.NotAfter,
|
||||
WorkflowId: GetWorkflowId(ctx),
|
||||
|
@@ -28,7 +28,7 @@ func NewDeployNode(node *domain.WorkflowNode) *deployNode {
|
||||
func (d *deployNode) Run(ctx context.Context) error {
|
||||
d.AddOutput(ctx, d.node.Name, "开始执行")
|
||||
// 检查是否部署过(部署过则直接返回,和 v0.2 暂时保持一致)
|
||||
output, err := d.outputRepo.Get(ctx, d.node.Id)
|
||||
output, err := d.outputRepo.GetByNodeId(ctx, d.node.Id)
|
||||
if err != nil && !domain.IsRecordNotFound(err) {
|
||||
d.AddOutput(ctx, d.node.Name, "查询部署记录失败", err.Error())
|
||||
return err
|
||||
@@ -43,7 +43,7 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
return fmt.Errorf("证书来源配置错误: %s", certSource)
|
||||
}
|
||||
|
||||
cert, err := d.outputRepo.GetCertificate(ctx, certSourceSlice[0])
|
||||
cert, err := d.outputRepo.GetCertificateByNodeId(ctx, certSourceSlice[0])
|
||||
if err != nil {
|
||||
d.AddOutput(ctx, d.node.Name, "获取证书失败", err.Error())
|
||||
return err
|
||||
@@ -71,8 +71,8 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
AccessConfig: access.Config,
|
||||
AccessRecord: access,
|
||||
Certificate: applicant.Certificate{
|
||||
CertUrl: cert.AcmeCertUrl,
|
||||
CertStableUrl: cert.AcmeCertStableUrl,
|
||||
CertUrl: cert.ACMECertUrl,
|
||||
CertStableUrl: cert.ACMECertStableUrl,
|
||||
PrivateKey: cert.PrivateKey,
|
||||
Certificate: cert.Certificate,
|
||||
IssuerCertificate: cert.IssuerCertificate,
|
||||
@@ -85,7 +85,7 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
},
|
||||
}
|
||||
|
||||
deploy, err := deployer.GetWithTypeAndOption(d.node.GetConfigString("provider"), option)
|
||||
deploy, err := deployer.GetWithProviderAndOption(d.node.GetConfigString("provider"), option)
|
||||
if err != nil {
|
||||
d.AddOutput(ctx, d.node.Name, "获取部署对象失败", err.Error())
|
||||
return err
|
||||
|
Reference in New Issue
Block a user