Skip to content

Commit

Permalink
feat: 自动续签面板证书
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Jan 2, 2025
1 parent 8e3d929 commit 50d988a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/job/cert_renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package job

import (
"log/slog"
"path/filepath"
"time"

"gorm.io/gorm"

"github.com/tnb-labs/panel/internal/app"
"github.com/tnb-labs/panel/internal/biz"
pkgcert "github.com/tnb-labs/panel/pkg/cert"
"github.com/tnb-labs/panel/pkg/io"
"github.com/tnb-labs/panel/pkg/shell"
)

// CertRenew 证书续签
Expand Down Expand Up @@ -58,4 +61,19 @@ func (r *CertRenew) Run() {
r.log.Warn("续签证书失败", slog.Any("err", err))
}
}

// 续签面板证书
panelCert, err := io.Read(filepath.Join(app.Root, "panel/storage/cert.pem"))
if err != nil {
r.log.Warn("读取面板证书失败", slog.Any("err", err))
return
}
decode, err := pkgcert.ParseCert(panelCert)
if err != nil {
r.log.Warn("解析面板证书失败", slog.Any("err", err))
return
}
if decode.NotAfter.Sub(time.Now()).Hours() < 24*7 {

Check failure on line 76 in internal/job/cert_renew.go

View workflow job for this annotation

GitHub Actions / golanci-lint

S1024: should use time.Until instead of t.Sub(time.Now()) (gosimple)
_, err = shell.Exec("panel-cli https generate")

Check failure on line 77 in internal/job/cert_renew.go

View workflow job for this annotation

GitHub Actions / golanci-lint

ineffectual assignment to err (ineffassign)
}
}

0 comments on commit 50d988a

Please sign in to comment.