Skip to content

Commit

Permalink
Fix cert_obtained event info
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jun 9, 2023
1 parent d37847a commit 25bb2af
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions config.go
Expand Up @@ -593,6 +593,7 @@ func (cfg *Config) obtainCert(ctx context.Context, name string, interactive bool
// only the error from the last issuer will be returned, but we logged the others
return fmt.Errorf("[%s] Obtain: %w", name, err)
}
issuerKey := issuerUsed.IssuerKey()

// success - immediately save the certificate resource
certRes := CertificateResource{
Expand All @@ -609,11 +610,16 @@ func (cfg *Config) obtainCert(ctx context.Context, name string, interactive bool

log.Info("certificate obtained successfully", zap.String("identifier", name))

certKey := certRes.NamesKey()

cfg.emit(ctx, "cert_obtained", map[string]any{
"renewal": false,
"identifier": name,
"issuers": issuerUsed.IssuerKey(),
"storage_key": certRes.NamesKey(),
"renewal": false,
"identifier": name,
"issuer": issuerUsed.IssuerKey(),
"storage_path": StorageKeys.CertsSitePrefix(issuerKey, certKey),
"private_key_path": StorageKeys.SitePrivateKey(issuerKey, certKey),
"certificate_path": StorageKeys.SiteCert(issuerKey, certKey),
"metadata_path": StorageKeys.SiteMeta(issuerKey, certKey),
})

return nil
Expand Down Expand Up @@ -819,14 +825,15 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
// only the error from the last issuer will be returned, but we logged the others
return fmt.Errorf("[%s] Renew: %w", name, err)
}
issuerKey := issuerUsed.IssuerKey()

// success - immediately save the renewed certificate resource
newCertRes := CertificateResource{
SANs: namesFromCSR(csr),
CertificatePEM: issuedCert.Certificate,
PrivateKeyPEM: certRes.PrivateKeyPEM,
IssuerData: issuedCert.Metadata,
issuerKey: issuerUsed.IssuerKey(),
issuerKey: issuerKey,
}
err = cfg.saveCertResource(ctx, issuerUsed, newCertRes)
if err != nil {
Expand All @@ -835,12 +842,17 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv

log.Info("certificate renewed successfully", zap.String("identifier", name))

certKey := newCertRes.NamesKey()

cfg.emit(ctx, "cert_obtained", map[string]any{
"renewal": true,
"remaining": timeLeft,
"identifier": name,
"issuer": issuerUsed.IssuerKey(),
"storage_key": certRes.NamesKey(),
"renewal": true,
"remaining": timeLeft,
"identifier": name,
"issuer": issuerKey,
"storage_path": StorageKeys.CertsSitePrefix(issuerKey, certKey),
"private_key_path": StorageKeys.SitePrivateKey(issuerKey, certKey),
"certificate_path": StorageKeys.SiteCert(issuerKey, certKey),
"metadata_path": StorageKeys.SiteMeta(issuerKey, certKey),
})

return nil
Expand Down

0 comments on commit 25bb2af

Please sign in to comment.