mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
refactor: rename extension constants
This commit is contained in:
parent
1ed3b62999
commit
e94c96760a
8 changed files with 25 additions and 25 deletions
|
|
@ -77,7 +77,7 @@ func listCertificates(_ context.Context, cmd *cli.Command) error {
|
|||
}
|
||||
|
||||
for _, filename := range matches {
|
||||
if strings.HasSuffix(filename, storage.IssuerExt) {
|
||||
if strings.HasSuffix(filename, storage.ExtIssuer) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ func renewForDomains(ctx context.Context, cmd *cli.Command, account *storage.Acc
|
|||
// load the cert resource from files.
|
||||
// We store the certificate, private key and metadata in different files
|
||||
// as web servers would not be able to work with a combined file.
|
||||
certificates, err := certsStorage.ReadCertificate(domain, storage.CertExt)
|
||||
certificates, err := certsStorage.ReadCertificate(domain, storage.ExtCert)
|
||||
if err != nil {
|
||||
log.Fatal("Error while loading the certificate.", log.DomainAttr(domain), log.ErrorAttr(err))
|
||||
}
|
||||
|
|
@ -243,7 +243,7 @@ func renewForDomains(ctx context.Context, cmd *cli.Command, account *storage.Acc
|
|||
var privateKey crypto.PrivateKey
|
||||
|
||||
if cmd.Bool(flgReuseKey) {
|
||||
keyBytes, errR := certsStorage.ReadFile(domain, storage.KeyExt)
|
||||
keyBytes, errR := certsStorage.ReadFile(domain, storage.ExtKey)
|
||||
if errR != nil {
|
||||
log.Fatal("Error while loading the private key.",
|
||||
log.DomainAttr(domain),
|
||||
|
|
@ -323,7 +323,7 @@ func renewForCSR(ctx context.Context, cmd *cli.Command, account *storage.Account
|
|||
// load the cert resource from files.
|
||||
// We store the certificate, private key and metadata in different files
|
||||
// as web servers would not be able to work with a combined file.
|
||||
certificates, err := certsStorage.ReadCertificate(domain, storage.CertExt)
|
||||
certificates, err := certsStorage.ReadCertificate(domain, storage.ExtCert)
|
||||
if err != nil {
|
||||
log.Fatal("Error while loading the certificate.",
|
||||
log.DomainAttr(domain),
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func revoke(ctx context.Context, cmd *cli.Command) error {
|
|||
for _, domain := range cmd.StringSlice(flgDomains) {
|
||||
log.Info("Trying to revoke the certificate.", log.DomainAttr(domain))
|
||||
|
||||
certBytes, err := certsStorage.ReadFile(domain, storage.CertExt)
|
||||
certBytes, err := certsStorage.ReadFile(domain, storage.ExtCert)
|
||||
if err != nil {
|
||||
log.Fatal("Error while revoking the certificate.", log.DomainAttr(domain), log.ErrorAttr(err))
|
||||
}
|
||||
|
|
|
|||
10
cmd/hook.go
10
cmd/hook.go
|
|
@ -88,18 +88,18 @@ func metaToEnv(meta map[string]string) []string {
|
|||
|
||||
func addPathToMetadata(meta map[string]string, domain string, certRes *certificate.Resource, certsStorage *CertificatesStorage) {
|
||||
meta[hookEnvCertDomain] = domain
|
||||
meta[hookEnvCertPath] = certsStorage.GetFileName(domain, storage.CertExt)
|
||||
meta[hookEnvCertKeyPath] = certsStorage.GetFileName(domain, storage.KeyExt)
|
||||
meta[hookEnvCertPath] = certsStorage.GetFileName(domain, storage.ExtCert)
|
||||
meta[hookEnvCertKeyPath] = certsStorage.GetFileName(domain, storage.ExtKey)
|
||||
|
||||
if certRes.IssuerCertificate != nil {
|
||||
meta[hookEnvIssuerCertKeyPath] = certsStorage.GetFileName(domain, storage.IssuerExt)
|
||||
meta[hookEnvIssuerCertKeyPath] = certsStorage.GetFileName(domain, storage.ExtIssuer)
|
||||
}
|
||||
|
||||
if certsStorage.IsPEM() {
|
||||
meta[hookEnvCertPEMPath] = certsStorage.GetFileName(domain, storage.PEMExt)
|
||||
meta[hookEnvCertPEMPath] = certsStorage.GetFileName(domain, storage.ExtPEM)
|
||||
}
|
||||
|
||||
if certsStorage.IsPFX() {
|
||||
meta[hookEnvCertPFXPath] = certsStorage.GetFileName(domain, storage.PFXExt)
|
||||
meta[hookEnvCertPFXPath] = certsStorage.GetFileName(domain, storage.ExtPFX)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
IssuerExt = ".issuer.crt"
|
||||
CertExt = ".crt"
|
||||
KeyExt = ".key"
|
||||
PEMExt = ".pem"
|
||||
PFXExt = ".pfx"
|
||||
ResourceExt = ".json"
|
||||
ExtIssuer = ".issuer.crt"
|
||||
ExtCert = ".crt"
|
||||
ExtKey = ".key"
|
||||
ExtPEM = ".pem"
|
||||
ExtPFX = ".pfx"
|
||||
ExtResource = ".json"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ func NewCertificatesReader(basePath string) *CertificatesReader {
|
|||
}
|
||||
|
||||
func (s *CertificatesReader) ReadResource(domain string) certificate.Resource {
|
||||
raw, err := s.ReadFile(domain, ResourceExt)
|
||||
raw, err := s.ReadFile(domain, ExtResource)
|
||||
if err != nil {
|
||||
log.Fatal("Error while loading the metadata.",
|
||||
log.DomainAttr(domain),
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ func (s *CertificatesWriter) SaveResource(certRes *certificate.Resource) {
|
|||
|
||||
// We store the certificate, private key and metadata in different files
|
||||
// as web servers would not be able to work with a combined file.
|
||||
err := s.writeFile(domain, CertExt, certRes.Certificate)
|
||||
err := s.writeFile(domain, ExtCert, certRes.Certificate)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to save Certificate.",
|
||||
log.DomainAttr(domain),
|
||||
|
|
@ -114,7 +114,7 @@ func (s *CertificatesWriter) SaveResource(certRes *certificate.Resource) {
|
|||
}
|
||||
|
||||
if certRes.IssuerCertificate != nil {
|
||||
err = s.writeFile(domain, IssuerExt, certRes.IssuerCertificate)
|
||||
err = s.writeFile(domain, ExtIssuer, certRes.IssuerCertificate)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to save IssuerCertificate.",
|
||||
log.DomainAttr(domain),
|
||||
|
|
@ -142,7 +142,7 @@ func (s *CertificatesWriter) SaveResource(certRes *certificate.Resource) {
|
|||
)
|
||||
}
|
||||
|
||||
err = s.writeFile(domain, ResourceExt, jsonBytes)
|
||||
err = s.writeFile(domain, ExtResource, jsonBytes)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to save CertResource.",
|
||||
log.DomainAttr(domain),
|
||||
|
|
@ -160,7 +160,7 @@ func (s *CertificatesWriter) MoveToArchive(domain string) error {
|
|||
}
|
||||
|
||||
for _, oldFile := range matches {
|
||||
if strings.TrimSuffix(oldFile, filepath.Ext(oldFile)) != baseFilename && oldFile != baseFilename+IssuerExt {
|
||||
if strings.TrimSuffix(oldFile, filepath.Ext(oldFile)) != baseFilename && oldFile != baseFilename+ExtIssuer {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -190,13 +190,13 @@ func (s *CertificatesWriter) IsPFX() bool {
|
|||
}
|
||||
|
||||
func (s *CertificatesWriter) writeCertificateFiles(domain string, certRes *certificate.Resource) error {
|
||||
err := s.writeFile(domain, KeyExt, certRes.PrivateKey)
|
||||
err := s.writeFile(domain, ExtKey, certRes.PrivateKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save key file: %w", err)
|
||||
}
|
||||
|
||||
if s.pem {
|
||||
err = s.writeFile(domain, PEMExt, bytes.Join([][]byte{certRes.Certificate, certRes.PrivateKey}, nil))
|
||||
err = s.writeFile(domain, ExtPEM, bytes.Join([][]byte{certRes.Certificate, certRes.PrivateKey}, nil))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save PEM file: %w", err)
|
||||
}
|
||||
|
|
@ -243,7 +243,7 @@ func (s *CertificatesWriter) writePFXFile(domain string, certRes *certificate.Re
|
|||
return fmt.Errorf("unable to encode PFX data for domain %s: %w", domain, err)
|
||||
}
|
||||
|
||||
return s.writeFile(domain, PFXExt, pfxBytes)
|
||||
return s.writeFile(domain, ExtPFX, pfxBytes)
|
||||
}
|
||||
|
||||
func (s *CertificatesWriter) writeFile(domain, extension string, data []byte) error {
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ func generateTestFiles(t *testing.T, dir, domain string) []string {
|
|||
|
||||
var filenames []string
|
||||
|
||||
for _, ext := range []string{storage.IssuerExt, storage.CertExt, storage.KeyExt, storage.PEMExt, storage.PFXExt, storage.ResourceExt} {
|
||||
for _, ext := range []string{storage.ExtIssuer, storage.ExtCert, storage.ExtKey, storage.ExtPEM, storage.ExtPFX, storage.ExtResource} {
|
||||
filename := filepath.Join(dir, domain+ext)
|
||||
err := os.WriteFile(filename, []byte("test"), 0o666)
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue