refactor: update golintci-lint and linter issues

* Update golangci-lint

Update golangci-lint to v2.

Signed-off-by: SuperQ <superq@gmail.com>

* Fixup various linter issues.

Signed-off-by: SuperQ <superq@gmail.com>

---------

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
Ben Kochie
2025-04-13 02:55:30 +01:00
committed by GitHub
parent 951e673e0c
commit 009b0abbe9
11 changed files with 72 additions and 54 deletions

View File

@@ -49,12 +49,12 @@ func (s *CertStore) ensureStorePath() error {
s.log.Trace().Str("path", s.storePath).Msg("TLS store directory does not exist, creating directory")
err = os.MkdirAll(s.storePath, 0755)
if err != nil {
return fmt.Errorf("Failed to create TLS store path: %w", err)
return fmt.Errorf("failed to create TLS store path: %w", err)
}
return nil
}
return fmt.Errorf("Failed to check TLS store path: %w", err)
return fmt.Errorf("failed to check TLS store path: %w", err)
}
func (s *CertStore) LoadCertificates() {
@@ -115,7 +115,7 @@ func (s *CertStore) GetCertificate(hostname string) *tls.Certificate {
func (s *CertStore) ValidateAndSaveCertificate(hostname string, cert string, key string, ignoreWarning bool) (error, error) {
tlsCert, err := tls.X509KeyPair([]byte(cert), []byte(key))
if err != nil {
return fmt.Errorf("Failed to parse certificate: %w", err), nil
return fmt.Errorf("failed to parse certificate: %w", err), nil
}
// this can be skipped as current implementation supports one custom certificate only
@@ -129,7 +129,7 @@ func (s *CertStore) ValidateAndSaveCertificate(hostname string, cert string, key
if err = tlsCert.Leaf.VerifyHostname(hostname); err != nil {
if !ignoreWarning {
return nil, fmt.Errorf("Certificate does not match hostname: %w", err)
return nil, fmt.Errorf("certificate does not match hostname: %w", err)
}
s.log.Warn().Err(err).Msg("Certificate does not match hostname")
}

View File

@@ -35,7 +35,7 @@ func keyToFile(cert *tls.Certificate, filename string) error {
case *ecdsa.PrivateKey:
b, e := x509.MarshalECPrivateKey(k)
if e != nil {
return fmt.Errorf("Failed to marshal EC private key: %v", e)
return fmt.Errorf("failed to marshal EC private key: %v", e)
}
keyBlock = pem.Block{
@@ -43,7 +43,7 @@ func keyToFile(cert *tls.Certificate, filename string) error {
Bytes: b,
}
default:
return fmt.Errorf("Unknown private key type: %T", k)
return fmt.Errorf("unknown private key type: %T", k)
}
err := withSecretFile(filename, func(file *os.File) error {
@@ -51,7 +51,7 @@ func keyToFile(cert *tls.Certificate, filename string) error {
})
if err != nil {
return fmt.Errorf("Failed to save private key: %w", err)
return fmt.Errorf("failed to save private key: %w", err)
}
return nil
@@ -67,7 +67,7 @@ func certToFile(cert *tls.Certificate, filename string) error {
err := pem.Encode(file, &block)
if err != nil {
return fmt.Errorf("Failed to save certificate: %w", err)
return fmt.Errorf("failed to save certificate: %w", err)
}
}