Fix linter error in certauthority.

The error was:
```
internal/certauthority/certauthority.go:68:15: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"expected CA to be a single certificate, found %d certificates\", certCount)" (goerr113)
		return nil, fmt.Errorf("expected CA to be a single certificate, found %d certificates", certCount)
		            ^
exit status 1
```

I'm not sure if I love this err113 linter.
This commit is contained in:
Matt Moyer 2020-07-27 08:18:37 -05:00
parent 8606cc9662
commit a1593c4b7b
2 changed files with 5 additions and 2 deletions

View File

@ -58,6 +58,9 @@ func secureEnv() env {
} }
} }
// ErrInvalidCACertificate is returned when the contents of the loaded CA certificate do not meet our assumptions.
var ErrInvalidCACertificate = fmt.Errorf("invalid CA certificate")
// Load a certificate authority from an existing certificate and private key (in PEM format). // Load a certificate authority from an existing certificate and private key (in PEM format).
func Load(certPath string, keyPath string) (*CA, error) { func Load(certPath string, keyPath string) (*CA, error) {
cert, err := tls.LoadX509KeyPair(certPath, keyPath) cert, err := tls.LoadX509KeyPair(certPath, keyPath)
@ -65,7 +68,7 @@ func Load(certPath string, keyPath string) (*CA, error) {
return nil, fmt.Errorf("could not load CA: %w", err) return nil, fmt.Errorf("could not load CA: %w", err)
} }
if certCount := len(cert.Certificate); certCount != 1 { if certCount := len(cert.Certificate); certCount != 1 {
return nil, fmt.Errorf("expected CA to be a single certificate, found %d certificates", certCount) return nil, fmt.Errorf("%w: expected a single certificate, found %d certificates", ErrInvalidCACertificate, certCount)
} }
return &CA{ return &CA{
caCertBytes: cert.Certificate[0], caCertBytes: cert.Certificate[0],

View File

@ -72,7 +72,7 @@ func TestLoad(t *testing.T) {
name: "multiple certs", name: "multiple certs",
certPath: "./testdata/multiple.crt", certPath: "./testdata/multiple.crt",
keyPath: "./testdata/test.key", keyPath: "./testdata/test.key",
wantErr: "expected CA to be a single certificate, found 2 certificates", wantErr: "invalid CA certificate: expected a single certificate, found 2 certificates",
}, },
{ {
name: "success", name: "success",