Skip to content

Commit 2f6011a

Browse files
Provide more detailed information in certificate events (#150)
* Provide more detailed information in certificate events The `cert_*` events were only providing the domain. This was pretty limited, because not much can be done with it without also knowing the issuer, since that affects where the cert is stored. Providing both the `issuerKey` and `certKey` makes it possible for the event listener to call `StorageKeys.SiteCert(issuerKey, certKey)` to get the actual location of the cert (and similarly the private key). Particularly useful in situations where the user wants to copy the cert/key to some location for another app to use the cert that is being managed. A similar change could probably also be done for `cached_managed_cert` and `cached_unmanaged_cert` events to provide more detail, because `cert.Names` string slice doesn't seem that useful, can't do much with that alone. But I'm not sure I understand the usefulness of those events, so meh. Caching seems like pretty much an internal implementation detail of certmagic. * Adjust struct and field naming * Mark CertificateEventData as experimental
1 parent 55be6d8 commit 2f6011a

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

config.go

+29-3
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,11 @@ func (cfg *Config) obtainCert(ctx context.Context, name string, interactive bool
573573
return fmt.Errorf("[%s] Obtain: saving assets: %v", name, err)
574574
}
575575

576-
cfg.emit("cert_obtained", name)
576+
cfg.emit("cert_obtained", CertificateEventData{
577+
Name: name,
578+
IssuerKey: issuerUsed.IssuerKey(),
579+
StorageKey: certRes.NamesKey(),
580+
})
577581

578582
if log != nil {
579583
log.Info("certificate obtained successfully", zap.String("identifier", name))
@@ -789,7 +793,11 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
789793
return fmt.Errorf("[%s] Renew: saving assets: %v", name, err)
790794
}
791795

792-
cfg.emit("cert_renewed", name)
796+
cfg.emit("cert_renewed", CertificateEventData{
797+
Name: name,
798+
IssuerKey: issuerUsed.IssuerKey(),
799+
StorageKey: certRes.NamesKey(),
800+
})
793801

794802
if log != nil {
795803
log.Info("certificate renewed successfully", zap.String("identifier", name))
@@ -868,7 +876,11 @@ func (cfg *Config) RevokeCert(ctx context.Context, domain string, reason int, in
868876
return fmt.Errorf("issuer %d (%s): %v", i, issuerKey, err)
869877
}
870878

871-
cfg.emit("cert_revoked", domain)
879+
cfg.emit("cert_revoked", CertificateEventData{
880+
Name: domain,
881+
IssuerKey: issuerKey,
882+
StorageKey: certRes.NamesKey(),
883+
})
872884

873885
err = cfg.deleteSiteAssets(ctx, issuerKey, domain)
874886
if err != nil {
@@ -1093,6 +1105,20 @@ type OCSPConfig struct {
10931105
ResponderOverrides map[string]string
10941106
}
10951107

1108+
// CertificateEventData contains contextual information for
1109+
// an obtained, renewed or revoked certificate.
1110+
// EXPERIMENTAL: subject to change.
1111+
type CertificateEventData struct {
1112+
// Domain or subject name of the certificate.
1113+
Name string
1114+
1115+
// Storage key for the issuer used for this certificate.
1116+
IssuerKey string
1117+
1118+
// Location in storage at which the certificate could be found.
1119+
StorageKey string
1120+
}
1121+
10961122
// certIssueLockOp is the name of the operation used
10971123
// when naming a lock to make it mutually exclusive
10981124
// with other certificate issuance operations for a

0 commit comments

Comments
 (0)