added date comparison
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2021-01-24 17:03:48 +01:00
parent 69e0a6d3f4
commit 90650aacfa
2 changed files with 8 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import (
"encoding/pem"
"fmt"
"log"
"time"
"git.paulbsd.com/paulbsd/pki/src/cert"
"git.paulbsd.com/paulbsd/pki/src/config"
@ -29,7 +30,13 @@ func (u *User) Init(cfg *config.Config) (err error) {
// GetEntry returns requested acme ressource in database relative to domain
func (u *User) GetEntry(cfg *config.Config, domain string) (Entry cert.Entry, err error) {
has, err := cfg.Db.Where("domain = ?", domain).Get(&Entry)
todaydate := time.Now().Format("2006-01-02")
requireddate := time.Now().AddDate(0, 0, -cfg.ACME.MaxDaysBefore).Format("2006-01-02")
has, err := cfg.Db.Where("domain = ?", domain).Where(
"validity_begin < ?::date", todaydate).Where(
"validity_end > ?::date", requireddate).Where(
"auth_url = ?", cfg.ACME.AuthURL).Get(&Entry)
if !has {
err = fmt.Errorf("Entry doesn't exists")
}

View File

@ -69,11 +69,6 @@ func GetDates(cert []byte) (NotBefore time.Time, NotAfter time.Time, err error)
return
}
// NeedRenewal is an unimplemented method
func NeedRenewal(cfg config.Config) (res bool, err error) {
return
}
// convertEntryToResponse converts database ACME entry to JSON ACME entry
func convertEntryToResponse(in cert.Entry) (out EntryResponse) {
out.Domain = in.Domain