Fix golangci-lint warnings

main
Jan Dittberner 4 months ago
parent 8c99fe2fab
commit 6ded9c40ab

@ -111,54 +111,63 @@ func (s *SignerClientHandler) ResponseData(ctx context.Context, in <-chan []byte
case <-ctx.Done(): case <-ctx.Done():
return nil return nil
case frame := <-in: case frame := <-in:
switch response.Announce.Code { err := handleIncomingFrame(response, frame)
case messages.RespHealth: if err != nil {
var resp messages.HealthResponse return err
if err := msgpack.Unmarshal(frame, &resp); err != nil { }
return fmt.Errorf("could not unmarshal health response data: %w", err) case <-time.After(s.config.ResponseDataTimeout):
} return protocol.ErrResponseDataTimeoutExpired
}
response.Response = &resp return nil
case messages.RespCAInfo: }
var resp messages.CAInfoResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal CA info response data: %w", err)
}
response.Response = &resp func handleIncomingFrame(response *protocol.Response, frame []byte) error {
case messages.RespFetchCRL: switch response.Announce.Code {
var resp messages.FetchCRLResponse case messages.RespHealth:
if err := msgpack.Unmarshal(frame, &resp); err != nil { var resp messages.HealthResponse
return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err) if err := msgpack.Unmarshal(frame, &resp); err != nil {
} return fmt.Errorf("could not unmarshal health response data: %w", err)
}
response.Response = &resp response.Response = &resp
case messages.RespSignCertificate: case messages.RespCAInfo:
var resp messages.SignCertificateResponse var resp messages.CAInfoResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil { if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal sign certificate response data: %w", err) return fmt.Errorf("could not unmarshal CA info response data: %w", err)
} }
response.Response = &resp response.Response = &resp
case messages.RespSignOpenPGP: case messages.RespFetchCRL:
var resp messages.SignOpenPGPResponse var resp messages.FetchCRLResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil { if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal sign OpenPGP response data: %w", err) return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err)
} }
response.Response = &resp response.Response = &resp
case messages.RespError: case messages.RespSignCertificate:
var resp messages.ErrorResponse var resp messages.SignCertificateResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil { if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal error response data: %w", err) return fmt.Errorf("could not unmarshal sign certificate response data: %w", err)
} }
response.Response = &resp response.Response = &resp
default: case messages.RespSignOpenPGP:
return fmt.Errorf("unhandled response code %s", response.Announce.Code) var resp messages.SignOpenPGPResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal sign OpenPGP response data: %w", err)
} }
case <-time.After(s.config.ResponseDataTimeout):
return protocol.ErrResponseDataTimeoutExpired response.Response = &resp
case messages.RespError:
var resp messages.ErrorResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal error response data: %w", err)
}
response.Response = &resp
default:
return fmt.Errorf("unhandled response code %s", response.Announce.Code)
} }
return nil return nil

@ -548,7 +548,10 @@ func (d *LegacyDB) requestSignedOpenPGPKeys(ctx context.Context) error {
return nil return nil
} }
func (d *LegacyDB) requestCerts(ctx context.Context, query string, rt responseType, recordFailureCallback func(ctx context.Context, rowID int)) error { func (d *LegacyDB) requestCerts(
ctx context.Context, query string, rt responseType,
recordFailureCallback func(ctx context.Context, rowID int),
) error {
issuerID, ok := d.issuerIDs[rt] issuerID, ok := d.issuerIDs[rt]
if !ok { if !ok {
return fmt.Errorf("no known issuer id for type %s", rt) return fmt.Errorf("no known issuer id for type %s", rt)
@ -608,7 +611,9 @@ func (d *LegacyDB) requestCerts(ctx context.Context, query string, rt responseTy
} }
if csrBlock.Type != "CERTIFICATE REQUEST" { if csrBlock.Type != "CERTIFICATE REQUEST" {
d.logger.WithFields(logrus.Fields{"id": csrID, "file_name": csrFileName, "pem_block_type": csrBlock.Type}).Warn("unhandled PEM block type") d.logger.WithFields(
logrus.Fields{"id": csrID, "file_name": csrFileName, "pem_block_type": csrBlock.Type},
).Warn("unhandled PEM block type")
idsWithIssues = append(idsWithIssues, csrID) idsWithIssues = append(idsWithIssues, csrID)
@ -700,6 +705,7 @@ func buildSignCertificateCommand(
if len(subjParts.Subject.Country) > 0 { if len(subjParts.Subject.Country) > 0 {
signCertCommand.Country = subjParts.Subject.Country[0] signCertCommand.Country = subjParts.Subject.Country[0]
} }
return signCertCommand return signCertCommand
} }
@ -789,28 +795,32 @@ func parseSubjectStringComponent(identifier, value string, res *x509.Certificate
func (d *LegacyDB) revokePersonalClientCerts(_ context.Context) error { func (d *LegacyDB) revokePersonalClientCerts(_ context.Context) error {
logrus.Debug("not implemented") logrus.Debug("not implemented")
return nil return nil
} }
func (d *LegacyDB) revokePersonalServerCerts(_ context.Context) error { func (d *LegacyDB) revokePersonalServerCerts(_ context.Context) error {
logrus.Debug("not implemented") logrus.Debug("not implemented")
return nil return nil
} }
func (d *LegacyDB) revokeOrganizationClientCerts(_ context.Context) error { func (d *LegacyDB) revokeOrganizationClientCerts(_ context.Context) error {
logrus.Debug("not implemented") logrus.Debug("not implemented")
return nil return nil
} }
func (d *LegacyDB) revokeOrganizationServerCerts(_ context.Context) error { func (d *LegacyDB) revokeOrganizationServerCerts(_ context.Context) error {
logrus.Debug("not implemented") logrus.Debug("not implemented")
return nil return nil
} }
func (d *LegacyDB) writeCertificate(prefix string, rowID int, signatureData []byte) (string, error) { func (d *LegacyDB) writeCertificate(prefix string, rowID int, signatureData []byte) (string, error) {
crtDir := path.Join("..", "crt", prefix, strconv.Itoa(rowID/1000)) crtDir := path.Join("..", "crt", prefix, strconv.Itoa(rowID/1000))
err := os.MkdirAll(crtDir, 0o755) err := os.MkdirAll(crtDir, 0o755) //nolint:gomnd
if err != nil { if err != nil {
return "", fmt.Errorf("could not create directory: %w", err) return "", fmt.Errorf("could not create directory: %w", err)
} }
@ -840,7 +850,7 @@ func (d *LegacyDB) recordCertificate(ctx context.Context, prefix, query string,
} }
expiry := certificate.NotAfter expiry := certificate.NotAfter
serial := certificate.SerialNumber.Text(16) //nolint:gomnd serial := certificate.SerialNumber.Text(16)
pemData := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes}) pemData := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes})
@ -1084,6 +1094,7 @@ func (d *LegacyDB) sendNotificationEmail(ctx context.Context, e emailData) error
} }
const smtpPort = 1025 const smtpPort = 1025
c, err := mail.NewClient("localhost", mail.WithPort(smtpPort)) c, err := mail.NewClient("localhost", mail.WithPort(smtpPort))
if err != nil { if err != nil {
return fmt.Errorf("could not create mail client: %w", err) return fmt.Errorf("could not create mail client: %w", err)

Loading…
Cancel
Save