Skip to content

Commit

Permalink
Merge pull request #74 from usual2970/hotfix/bug_0922
Browse files Browse the repository at this point in the history
fix some bugs
  • Loading branch information
usual2970 authored Sep 22, 2024
2 parents 2cca82e + a259ccd commit 5eec1cf
Show file tree
Hide file tree
Showing 10 changed files with 756 additions and 30 deletions.
3 changes: 2 additions & 1 deletion internal/deployer/tencent_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deployer

import (
"certimate/internal/domain"
"certimate/internal/utils/rand"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -82,7 +83,7 @@ func (t *tencentCdn) uploadCert() (string, error) {

request.CertificatePublicKey = common.StringPtr(t.option.Certificate.Certificate)
request.CertificatePrivateKey = common.StringPtr(t.option.Certificate.PrivateKey)
request.Alias = common.StringPtr(t.option.Domain)
request.Alias = common.StringPtr(t.option.Domain + "_" + rand.RandStr(6))
request.Repeatable = common.BoolPtr(true)

response, err := client.UploadCertificate(request)
Expand Down
7 changes: 6 additions & 1 deletion internal/domains/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func deploy(ctx context.Context, record *models.Record) error {
history.record(checkPhase, "证书在有效期内且已部署,跳过", &RecordInfo{
Info: []string{fmt.Sprintf("证书有效期至 %s", expiredAt.Format("2006-01-02"))},
}, true)
return err

// 跳过的情况也算成功
history.setWholeSuccess(true)
return nil
}
history.record(checkPhase, "检查通过", nil, true)

Expand Down Expand Up @@ -119,5 +122,7 @@ func deploy(ctx context.Context, record *models.Record) error {
app.GetApp().Logger().Info("部署成功")
history.record(deployPhase, "部署成功", nil, true)

history.setWholeSuccess(true)

return nil
}
6 changes: 6 additions & 0 deletions internal/domains/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type history struct {
PhaseSuccess bool `json:"phaseSuccess"`
DeployedAt string `json:"deployedAt"`
Cert *applicant.Certificate `json:"cert"`
WholeSuccess bool `json:"wholeSuccess"`
}

func NewHistory(record *models.Record) *history {
Expand Down Expand Up @@ -68,6 +69,10 @@ func (a *history) setCert(cert *applicant.Certificate) {
a.Cert = cert
}

func (a *history) setWholeSuccess(success bool) {
a.WholeSuccess = success
}

func (a *history) commit() error {
collection, err := app.GetApp().Dao().FindCollectionByNameOrId("deployments")
if err != nil {
Expand All @@ -81,6 +86,7 @@ func (a *history) commit() error {
record.Set("log", a.Log)
record.Set("phase", string(a.Phase))
record.Set("phaseSuccess", a.PhaseSuccess)
record.Set("wholeSuccess", a.WholeSuccess)

if err := app.GetApp().Dao().SaveRecord(record); err != nil {
return err
Expand Down
Loading

0 comments on commit 5eec1cf

Please sign in to comment.