Skip to content

Commit

Permalink
Add isCertNearExpire()
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeguy committed Jan 13, 2024
1 parent 42fb147 commit 2ad9859
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions object/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package object

import (
"fmt"
"time"

"github.com/casbin/caswaf/certificate"
"github.com/casbin/caswaf/util"
Expand Down Expand Up @@ -183,3 +184,20 @@ func RenewCert(cert *Cert) (bool, error) {

return UpdateCert(cert.GetId(), cert)
}

func (cert *Cert) isCertNearExpire() (bool, error) {
if cert.ExpireTime == "" {
return true, nil
}

expireTime, err := time.Parse(time.RFC3339, cert.ExpireTime)
if err != nil {
return false, err
}

now := time.Now()
duration := expireTime.Sub(now)
res := duration <= 7*24*time.Hour

return res, nil
}
10 changes: 9 additions & 1 deletion object/site_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,15 @@ func (site *Site) checkCerts() error {
}

if cert != nil {
continue
var nearExpire bool
nearExpire, err = cert.isCertNearExpire()
if err != nil {
return err
}

if !nearExpire {
continue
}
}

err = site.updateCertForDomain(domain)
Expand Down

0 comments on commit 2ad9859

Please sign in to comment.