mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
feat: update hook metadata
This commit is contained in:
parent
bb518f7a3b
commit
0382b80002
3 changed files with 22 additions and 19 deletions
|
|
@ -200,10 +200,7 @@ func renewForDomains(ctx context.Context, cmd *cli.Command, lazyClient lzSetUp,
|
|||
return fmt.Errorf("could not save the resource: %w", err)
|
||||
}
|
||||
|
||||
// FIXME replace EnvCertDomain by EnvCertDomains and create an env var for the certID.
|
||||
// FIXME remove certID/domain from AddPathToMetadata and use only certRes
|
||||
|
||||
hook.AddPathToMetadata(meta, certRes.ID, certRes, certsStorage, options)
|
||||
hook.AddPathToMetadata(meta, certRes, certsStorage, options)
|
||||
|
||||
return hook.Launch(ctx, cmd.String(flgDeployHook), cmd.Duration(flgDeployHookTimeout), meta)
|
||||
}
|
||||
|
|
@ -278,10 +275,7 @@ func renewForCSR(ctx context.Context, cmd *cli.Command, lazyClient lzSetUp, cert
|
|||
return fmt.Errorf("CSR: could not save the resource: %w", err)
|
||||
}
|
||||
|
||||
// FIXME replace EnvCertDomain by EnvCertDomains and create an env var for the certID.
|
||||
// FIXME remove certID/domain from AddPathToMetadata and use only certRes
|
||||
|
||||
hook.AddPathToMetadata(meta, certRes.ID, certRes, certsStorage, options)
|
||||
hook.AddPathToMetadata(meta, certRes, certsStorage, options)
|
||||
|
||||
return hook.Launch(ctx, cmd.String(flgDeployHook), cmd.Duration(flgDeployHookTimeout), meta)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,10 +103,7 @@ func run(ctx context.Context, cmd *cli.Command) error {
|
|||
hook.EnvAccountEmail: account.Email,
|
||||
}
|
||||
|
||||
// FIXME replace EnvCertDomain by EnvCertDomains and create an env var for the certID.
|
||||
// FIXME remove certID/domain from AddPathToMetadata and use only certRes
|
||||
|
||||
hook.AddPathToMetadata(meta, certRes.ID, certRes, certsStorage, options)
|
||||
hook.AddPathToMetadata(meta, certRes, certsStorage, options)
|
||||
|
||||
return hook.Launch(ctx, cmd.String(flgDeployHook), cmd.Duration(flgDeployHookTimeout), meta)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/go-acme/lego/v5/cmd/internal/storage"
|
||||
)
|
||||
|
||||
// TODO(ldez) rename the env vars with LEGO_HOOK_ prefix to avoid collisions with flag names.
|
||||
const (
|
||||
EnvAccountEmail = "LEGO_ACCOUNT_EMAIL"
|
||||
EnvCertDomain = "LEGO_CERT_DOMAIN"
|
||||
|
|
@ -24,6 +25,13 @@ const (
|
|||
EnvCertPFXPath = "LEGO_CERT_PFX_PATH"
|
||||
)
|
||||
|
||||
// TODO(ldez): merge this with the previous constant block.
|
||||
const (
|
||||
EnvCertNameSanitized = "LEGO_HOOK_CERT_NAME_SANITIZED"
|
||||
EnvCertID = "LEGO_HOOK_CERT_ID"
|
||||
EnvCertDomains = "LEGO_HOOK_CERT_DOMAINS"
|
||||
)
|
||||
|
||||
func Launch(ctx context.Context, hook string, timeout time.Duration, meta map[string]string) error {
|
||||
if hook == "" {
|
||||
return nil
|
||||
|
|
@ -87,20 +95,24 @@ func metaToEnv(meta map[string]string) []string {
|
|||
}
|
||||
|
||||
// AddPathToMetadata adds information about the certificate to the metadata map.
|
||||
func AddPathToMetadata(meta map[string]string, domain string, certRes *certificate.Resource, certsStorage *storage.CertificatesStorage, options *storage.SaveOptions) {
|
||||
meta[EnvCertDomain] = domain
|
||||
meta[EnvCertPath] = certsStorage.GetFileName(domain, storage.ExtCert)
|
||||
meta[EnvCertKeyPath] = certsStorage.GetFileName(domain, storage.ExtKey)
|
||||
func AddPathToMetadata(meta map[string]string, certRes *certificate.Resource, certsStorage *storage.CertificatesStorage, options *storage.SaveOptions) {
|
||||
meta[EnvCertID] = certRes.ID
|
||||
meta[EnvCertNameSanitized] = storage.SanitizedName(certRes.ID)
|
||||
|
||||
meta[EnvCertDomains] = strings.Join(certRes.Domains, ",")
|
||||
|
||||
meta[EnvCertPath] = certsStorage.GetFileName(certRes.ID, storage.ExtCert)
|
||||
meta[EnvCertKeyPath] = certsStorage.GetFileName(certRes.ID, storage.ExtKey)
|
||||
|
||||
if certRes.IssuerCertificate != nil {
|
||||
meta[EnvIssuerCertKeyPath] = certsStorage.GetFileName(domain, storage.ExtIssuer)
|
||||
meta[EnvIssuerCertKeyPath] = certsStorage.GetFileName(certRes.ID, storage.ExtIssuer)
|
||||
}
|
||||
|
||||
if options.PEM {
|
||||
meta[EnvCertPEMPath] = certsStorage.GetFileName(domain, storage.ExtPEM)
|
||||
meta[EnvCertPEMPath] = certsStorage.GetFileName(certRes.ID, storage.ExtPEM)
|
||||
}
|
||||
|
||||
if options.PFX {
|
||||
meta[EnvCertPFXPath] = certsStorage.GetFileName(domain, storage.ExtPFX)
|
||||
meta[EnvCertPFXPath] = certsStorage.GetFileName(certRes.ID, storage.ExtPFX)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue