mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
feat: log when dynamic renew date not yet reached (#2597)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
8a75475894
commit
c689b20fee
2 changed files with 11 additions and 4 deletions
|
|
@ -357,7 +357,7 @@ func needRenewal(x509Cert *x509.Certificate, domain string, days int, dynamic bo
|
|||
}
|
||||
|
||||
if dynamic {
|
||||
return needRenewalDynamic(x509Cert, time.Now())
|
||||
return needRenewalDynamic(x509Cert, domain, time.Now())
|
||||
}
|
||||
|
||||
if days < 0 {
|
||||
|
|
@ -375,7 +375,7 @@ func needRenewal(x509Cert *x509.Certificate, domain string, days int, dynamic bo
|
|||
return false
|
||||
}
|
||||
|
||||
func needRenewalDynamic(x509Cert *x509.Certificate, now time.Time) bool {
|
||||
func needRenewalDynamic(x509Cert *x509.Certificate, domain string, now time.Time) bool {
|
||||
lifetime := x509Cert.NotAfter.Sub(x509Cert.NotBefore)
|
||||
|
||||
var divisor int64 = 3
|
||||
|
|
@ -385,7 +385,14 @@ func needRenewalDynamic(x509Cert *x509.Certificate, now time.Time) bool {
|
|||
|
||||
dueDate := x509Cert.NotAfter.Add(-1 * time.Duration(lifetime.Nanoseconds()/divisor))
|
||||
|
||||
return dueDate.Before(now)
|
||||
if dueDate.Before(now) {
|
||||
return true
|
||||
}
|
||||
|
||||
log.Infof("[%s] The certificate expires at %s, the renewal can be performed in %s: no renewal.",
|
||||
domain, x509Cert.NotAfter.Format(time.RFC3339), dueDate.Sub(now))
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// getARIRenewalTime checks if the certificate needs to be renewed using the renewalInfo endpoint.
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func Test_needRenewalDynamic(t *testing.T) {
|
|||
NotAfter: test.notAfter,
|
||||
}
|
||||
|
||||
ok := needRenewalDynamic(x509Cert, test.now)
|
||||
ok := needRenewalDynamic(x509Cert, "example.com", test.now)
|
||||
|
||||
test.expected(t, ok)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue