Skip to content

Commit

Permalink
feat: add LEGO_ISSUER_CERT_PATH to hook (#2164)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Apr 17, 2024
1 parent d60c335 commit 76eb1ea
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions cmd/cmd_renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import (
)

const (
renewEnvAccountEmail = "LEGO_ACCOUNT_EMAIL"
renewEnvCertDomain = "LEGO_CERT_DOMAIN"
renewEnvCertPath = "LEGO_CERT_PATH"
renewEnvCertKeyPath = "LEGO_CERT_KEY_PATH"
renewEnvCertPEMPath = "LEGO_CERT_PEM_PATH"
renewEnvCertPFXPath = "LEGO_CERT_PFX_PATH"
renewEnvAccountEmail = "LEGO_ACCOUNT_EMAIL"
renewEnvCertDomain = "LEGO_CERT_DOMAIN"
renewEnvCertPath = "LEGO_CERT_PATH"
renewEnvCertKeyPath = "LEGO_CERT_KEY_PATH"
renewEnvIssuerCertKeyPath = "LEGO_ISSUER_CERT_PATH"
renewEnvCertPEMPath = "LEGO_CERT_PEM_PATH"
renewEnvCertPFXPath = "LEGO_CERT_PFX_PATH"
)

func createRenew() *cli.Command {
Expand Down Expand Up @@ -212,17 +213,7 @@ func renewForDomains(ctx *cli.Context, client *lego.Client, certsStorage *Certif

certsStorage.SaveResource(certRes)

meta[renewEnvCertDomain] = domain
meta[renewEnvCertPath] = certsStorage.GetFileName(domain, ".crt")
meta[renewEnvCertKeyPath] = certsStorage.GetFileName(domain, ".key")

if certsStorage.pem {
meta[renewEnvCertPEMPath] = certsStorage.GetFileName(domain, ".pem")
}

if certsStorage.pfx {
meta[renewEnvCertPFXPath] = certsStorage.GetFileName(domain, ".pfx")
}
addPathToMetadata(meta, domain, certRes, certsStorage)

return launchHook(ctx.String("renew-hook"), meta)
}
Expand Down Expand Up @@ -292,17 +283,7 @@ func renewForCSR(ctx *cli.Context, client *lego.Client, certsStorage *Certificat

certsStorage.SaveResource(certRes)

meta[renewEnvCertDomain] = domain
meta[renewEnvCertPath] = certsStorage.GetFileName(domain, ".crt")
meta[renewEnvCertKeyPath] = certsStorage.GetFileName(domain, ".key")

if certsStorage.pem {
meta[renewEnvCertPEMPath] = certsStorage.GetFileName(domain, ".pem")
}

if certsStorage.pfx {
meta[renewEnvCertPFXPath] = certsStorage.GetFileName(domain, ".pfx")
}
addPathToMetadata(meta, domain, certRes, certsStorage)

return launchHook(ctx.String("renew-hook"), meta)
}
Expand Down Expand Up @@ -356,6 +337,24 @@ func getARIRenewalTime(ctx *cli.Context, cert *x509.Certificate, domain string,
return renewalTime
}

func addPathToMetadata(meta map[string]string, domain string, certRes *certificate.Resource, certsStorage *CertificatesStorage) {
meta[renewEnvCertDomain] = domain
meta[renewEnvCertPath] = certsStorage.GetFileName(domain, certExt)
meta[renewEnvCertKeyPath] = certsStorage.GetFileName(domain, keyExt)

if certRes.IssuerCertificate != nil {
meta[renewEnvIssuerCertKeyPath] = certsStorage.GetFileName(domain, issuerExt)
}

if certsStorage.pem {
meta[renewEnvCertPEMPath] = certsStorage.GetFileName(domain, pemExt)
}

if certsStorage.pfx {
meta[renewEnvCertPFXPath] = certsStorage.GetFileName(domain, pfxExt)
}
}

func merge(prevDomains, nextDomains []string) []string {
for _, next := range nextDomains {
var found bool
Expand Down

0 comments on commit 76eb1ea

Please sign in to comment.