Improve API from previous commit to pair Subject with Issuer

This commit is contained in:
Matthew Holt 2024-04-23 11:25:19 -06:00
parent 81683c8d20
commit 140a6fa920
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5

View File

@ -394,18 +394,24 @@ func (certCache *Cache) AllMatchingCertificates(name string) []Certificate {
return certs return certs
} }
// SubjectIssuer pairs a subject name with an issuer ID/key.
type SubjectIssuer struct {
Subject, IssuerKey string
}
// RemoveManaged removes managed certificates for the given subjects from the cache. // RemoveManaged removes managed certificates for the given subjects from the cache.
// This effectively stops maintenance of those certificates. Optionally pass an issuer // This effectively stops maintenance of those certificates. If an IssuerKey is
// key to remove only certs managed with a certain issuer. // specified alongside the subject, only certificates for that subject from the
func (certCache *Cache) RemoveManaged(subjects []string, issuerKey string) { // specified issuer will be removed.
func (certCache *Cache) RemoveManaged(subjects []SubjectIssuer) {
deleteQueue := make([]string, 0, len(subjects)) deleteQueue := make([]string, 0, len(subjects))
for _, subject := range subjects { for _, subj := range subjects {
certs := certCache.getAllMatchingCerts(subject) // does NOT expand wildcards; exact matches only certs := certCache.getAllMatchingCerts(subj.Subject) // does NOT expand wildcards; exact matches only
for _, cert := range certs { for _, cert := range certs {
if !cert.managed { if !cert.managed {
continue continue
} }
if issuerKey == "" || cert.issuerKey == issuerKey { if subj.IssuerKey == "" || cert.issuerKey == subj.IssuerKey {
deleteQueue = append(deleteQueue, cert.hash) deleteQueue = append(deleteQueue, cert.hash)
} }
} }