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:
bllfr0g 2025-07-22 15:47:44 -07:00 committed by GitHub
commit c689b20fee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -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.

View file

@ -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)
})