Skip to content

Commit

Permalink
fix: fixes bug with adding new lines and comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Jul 22, 2022
1 parent 627dfb2 commit 7c5878b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Certificate) Process(logger zerolog.Logger) (bool, error) {
if c.Paths.Certificate == "" {
logger.Info().Msg("Not saving certificate file because no path defined")
} else {
err = os.WriteFile(c.Paths.Certificate, []byte(metadata.Files.Certificate+"\n"), 0644)
err = os.WriteFile(c.Paths.Certificate, []byte(metadata.Files.Certificate), 0644)
if err != nil {
logger.Error().Err(err).Str("path", c.Paths.Certificate).Msg("Failed to write certificate file")
return true, err
Expand All @@ -43,7 +43,7 @@ func (c *Certificate) Process(logger zerolog.Logger) (bool, error) {
if c.Paths.PrivateKey == "" {
logger.Info().Msg("Not saving private key file because no path defined")
} else {
err = os.WriteFile(c.Paths.PrivateKey, []byte(metadata.Files.PrivateKey+"\n"), 0600)
err = os.WriteFile(c.Paths.PrivateKey, []byte(metadata.Files.PrivateKey), 0600)
if err != nil {
logger.Error().Err(err).Str("path", c.Paths.PrivateKey).Msg("Failed to write private key file")
return true, err
Expand All @@ -57,7 +57,7 @@ func (c *Certificate) Process(logger zerolog.Logger) (bool, error) {
if metadata.Files.Chain == "" {
logger.Info().Msg("No chain file provided")
} else {
err = os.WriteFile(c.Paths.Chain, []byte(metadata.Files.Chain+"\n"), 0600)
err = os.WriteFile(c.Paths.Chain, []byte(metadata.Files.Chain), 0600)
if err != nil {
logger.Error().Err(err).Str("path", c.Paths.Chain).Msg("Failed to write chain file")
return true, err
Expand All @@ -69,7 +69,7 @@ func (c *Certificate) Process(logger zerolog.Logger) (bool, error) {
if c.Paths.CertificateWithChain == "" {
logger.Info().Msg("Not saving certificate with chain file because no path defined")
} else {
err = os.WriteFile(c.Paths.CertificateWithChain, []byte(metadata.Files.CertificateWithChain()+"\n"), 0600)
err = os.WriteFile(c.Paths.CertificateWithChain, []byte(metadata.Files.CertificateWithChain()), 0600)
if err != nil {
logger.Error().Err(err).Str("path", c.Paths.CertificateWithChain).Msg("Failed to write certificate with chain file")
return true, err
Expand Down
8 changes: 4 additions & 4 deletions certificate_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (cmu *CertificateMetadataFiles) CertificateWithChain() string {
return cmu.Certificate
}

return cmu.Certificate + "\n" + cmu.Chain
return cmu.Certificate + "\n" + cmu.Chain + "\n"
}

// getCertificate downloads the certificate data
Expand All @@ -59,7 +59,7 @@ func (cmu *CertificateMetadataFiles) getCertificate(logger zerolog.Logger) error
if err != nil {
return err
}
cmu.Certificate = strings.TrimSpace(string(body))
cmu.Certificate = strings.TrimSpace(string(body)) + "\n"
return nil
}

Expand All @@ -71,7 +71,7 @@ func (cmu *CertificateMetadataFiles) getPrivateKey(logger zerolog.Logger) error
return err
}

cmu.PrivateKey = strings.TrimSpace(string(body))
cmu.PrivateKey = strings.TrimSpace(string(body)) + "\n"
return nil
}

Expand All @@ -83,6 +83,6 @@ func (cmu *CertificateMetadataFiles) getChain(logger zerolog.Logger) error {
return err
}

cmu.Chain = strings.TrimSpace(string(body))
cmu.Chain = strings.TrimSpace(string(body)) + "\n"
return nil
}

0 comments on commit 7c5878b

Please sign in to comment.