-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_certs.go
51 lines (39 loc) · 1.08 KB
/
check_certs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"time"
"github.com/sirupsen/logrus"
)
func checkCerts(certs []Cert, t time.Time) []Cert {
expiringCerts := make([]Cert, 0, len(certs))
for _, cert := range certs {
cert := cert
flagged := isCertFlagged(minCertLengthInDays, expiresInDays, maxExpiredInDays, cert, t)
if flagged {
expiringCerts = append(expiringCerts, cert)
}
}
return expiringCerts
}
func isCertFlagged(minCert, expires, expired int, cert Cert, t time.Time) bool {
log := logrus.WithFields(logrus.Fields{
"namespace": cert.Namespace,
"name": cert.Name,
"key": cert.Key,
"subject": cert.X509.Subject,
})
certExpires := cert.ExpiresInDays(t)
log.Infof("Expires in %v", certExpires)
validPeriod := cert.ValidPeriodInDays()
if validPeriod < minCert {
log.Infof("Cert valid period too short: %v", validPeriod)
return false
}
if certExpires <= expires {
log.Infof("Cert expires within: %v (%v)", certExpires, expires)
if certExpires >= -(expired) {
return true
}
log.Infof("Cert expired for too long: %v (%v)", certExpires, expired)
}
return false
}