Skip to content

Commit

Permalink
feat: fills LEGO_CERT_PFX_PATH and LEGO_CERT_PEM_PATH only when needed (
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Apr 16, 2024
1 parent 55dd478 commit d60c335
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ linters-settings:
disable:
- require-error
- go-require
perfsprint:
err-error: true
errorf: true
sprintf1: true
strconcat: false

linters:
enable-all: true
Expand Down Expand Up @@ -149,7 +154,6 @@ issues:
- 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked'
- 'exported (type|method|function) (.+) should have comment or be unexported'
- 'ST1000: at least one file in a package should have a package comment'
- 'fmt.Sprintf can be replaced with string'
exclude-rules:
- path: (.+)_test.go
linters:
Expand Down Expand Up @@ -227,6 +231,6 @@ issues:
- path: providers/dns/hosttech/internal/client_test.go
text: 'Duplicate words \(0\) found'
- path: cmd/cmd_renew.go
text: 'cyclomatic complexity \d+ of func `renewForDomains` is high'
text: 'cyclomatic complexity \d+ of func `(renewForDomains|renewForCSR)` is high'
- path: providers/dns/cpanel/cpanel.go
text: 'cyclomatic complexity 13 of func `\(\*DNSProvider\)\.CleanUp` is high'
18 changes: 16 additions & 2 deletions cmd/cmd_renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,14 @@ func renewForDomains(ctx *cli.Context, client *lego.Client, certsStorage *Certif
meta[renewEnvCertDomain] = domain
meta[renewEnvCertPath] = certsStorage.GetFileName(domain, ".crt")
meta[renewEnvCertKeyPath] = certsStorage.GetFileName(domain, ".key")
meta[renewEnvCertPEMPath] = certsStorage.GetFileName(domain, ".pem")
meta[renewEnvCertPFXPath] = certsStorage.GetFileName(domain, ".pfx")

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

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

return launchHook(ctx.String("renew-hook"), meta)
}
Expand Down Expand Up @@ -290,6 +296,14 @@ func renewForCSR(ctx *cli.Context, client *lego.Client, certsStorage *Certificat
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")
}

return launchHook(ctx.String("renew-hook"), meta)
}

Expand Down
2 changes: 2 additions & 0 deletions docs/content/usage/cli/Obtain-a-Certificate.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Some information is provided through environment variables:
- `LEGO_CERT_DOMAIN`: the main domain of the certificate.
- `LEGO_CERT_PATH`: the path of the certificate.
- `LEGO_CERT_KEY_PATH`: the path of the certificate key.
- `LEGO_CERT_PEM_PATH`: (only with `--pem`) the path to the PEM certificate.
- `LEGO_CERT_PFX_PATH`: (only with `--pfx`) the path to the PFX certificate.

### Use case

Expand Down
2 changes: 2 additions & 0 deletions docs/content/usage/cli/Renew-a-Certificate.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Some information is provided through environment variables:
- `LEGO_CERT_DOMAIN`: the main domain of the certificate.
- `LEGO_CERT_PATH`: the path of the certificate.
- `LEGO_CERT_KEY_PATH`: the path of the certificate key.
- `LEGO_CERT_PEM_PATH`: (only with `--pem`) the path to the PEM certificate.
- `LEGO_CERT_PFX_PATH`: (only with `--pfx`) the path to the PFX certificate.

See [Obtain a Certificate → Use case]({{< ref "usage/cli/Obtain-a-Certificate#use-case" >}}) for an example script.

Expand Down

0 comments on commit d60c335

Please sign in to comment.