MCPcopy
hub / github.com/caddyserver/caddy / needsRenewal

Method needsRenewal

modules/caddypki/maintain.go:106–115  ·  view source on GitHub ↗

needsRenewal reports whether the certificate is within its renewal window (i.e. the fraction of lifetime remaining is less than or equal to RenewalWindowRatio).

(cert *x509.Certificate)

Source from the content-addressed store, hash-verified

104// needsRenewal reports whether the certificate is within its renewal window
105// (i.e. the fraction of lifetime remaining is less than or equal to RenewalWindowRatio).
106func (ca *CA) needsRenewal(cert *x509.Certificate) bool {
107 ratio := ca.RenewalWindowRatio
108 if ratio <= 0 {
109 ratio = defaultRenewalWindowRatio
110 }
111 lifetime := cert.NotAfter.Sub(cert.NotBefore)
112 renewalWindow := time.Duration(float64(lifetime) * ratio)
113 renewalWindowStart := cert.NotAfter.Add(-renewalWindow)
114 return time.Now().After(renewalWindowStart)
115}

Callers 2

renewCertsForCAMethod · 0.80
TestCA_needsRenewalFunction · 0.80

Calls 2

DurationMethod · 0.80
AddMethod · 0.45

Tested by 1

TestCA_needsRenewalFunction · 0.64