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():
return nil
case frame := <-in:
switch response.Announce.Code {
case messages.RespHealth:
var resp messages.HealthResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal health response data: %w", err)
}
err := handleIncomingFrame(response, frame)
if err != nil {
return err
}
case <-time.After(s.config.ResponseDataTimeout):
return protocol.ErrResponseDataTimeoutExpired
}
response.Response = &resp
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)
}
return nil
}
response.Response = &resp
case messages.RespFetchCRL:
var resp messages.FetchCRLResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err)
}
func handleIncomingFrame(response *protocol.Response, frame []byte) error {
switch response.Announce.Code {
case messages.RespHealth:
var resp messages.HealthResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal health response data: %w", err)
}
response.Response = &resp
case messages.RespSignCertificate:
var resp messages.SignCertificateResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal sign certificate response data: %w", err)
}
response.Response = &resp
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
case messages.RespSignOpenPGP:
var resp messages.SignOpenPGPResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal sign OpenPGP response data: %w", err)
}
response.Response = &resp
case messages.RespFetchCRL:
var resp messages.FetchCRLResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err)
}
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
case messages.RespSignCertificate:
var resp messages.SignCertificateResponse
if err := msgpack.Unmarshal(frame, &resp); err != nil {
return fmt.Errorf("could not unmarshal sign certificate response data: %w", err)
}
response.Response = &resp
default:
return fmt.Errorf("unhandled response code %s", response.Announce.Code)
response.Response = &resp
case messages.RespSignOpenPGP:
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

@ -548,7 +548,10 @@ func (d *LegacyDB) requestSignedOpenPGPKeys(ctx context.Context) error {
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]
if !ok {
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" {
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)
@ -700,6 +705,7 @@ func buildSignCertificateCommand(
if len(subjParts.Subject.Country) > 0 {
signCertCommand.Country = subjParts.Subject.Country[0]
}
return signCertCommand
}
@ -789,28 +795,32 @@ func parseSubjectStringComponent(identifier, value string, res *x509.Certificate
func (d *LegacyDB) revokePersonalClientCerts(_ context.Context) error {
logrus.Debug("not implemented")
return nil
}
func (d *LegacyDB) revokePersonalServerCerts(_ context.Context) error {
logrus.Debug("not implemented")
return nil
}
func (d *LegacyDB) revokeOrganizationClientCerts(_ context.Context) error {
logrus.Debug("not implemented")
return nil
}
func (d *LegacyDB) revokeOrganizationServerCerts(_ context.Context) error {
logrus.Debug("not implemented")
return nil
}
func (d *LegacyDB) writeCertificate(prefix string, rowID int, signatureData []byte) (string, error) {
crtDir := path.Join("..", "crt", prefix, strconv.Itoa(rowID/1000))
err := os.MkdirAll(crtDir, 0o755)
err := os.MkdirAll(crtDir, 0o755) //nolint:gomnd
if err != nil {
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
serial := certificate.SerialNumber.Text(16) //nolint:gomnd
serial := certificate.SerialNumber.Text(16)
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
c, err := mail.NewClient("localhost", mail.WithPort(smtpPort))
if err != nil {
return fmt.Errorf("could not create mail client: %w", err)

Loading…
Cancel
Save