Update dependencies and fix some linter warnings

This commit is contained in:
2022-08-28 02:23:36 +02:00
parent 0ed71be705
commit d2fa727990
14 changed files with 148 additions and 42 deletions

View File

@@ -41,7 +41,7 @@ func (s *PostgresStore) Add(attempt *ConnectionAttempt) error {
if err != nil {
return err
}
defer tx.Rollback()
defer tx.Rollback() // nolint: errcheck
_, err = tx.Exec(stmt, time.Now(), attempt.From, attempt.Port)
if err != nil {

View File

@@ -25,7 +25,11 @@ func New(store Store) *Server {
func (s *Server) Start(ctx context.Context) error {
for _, port := range s.EnabledPortsTCP {
portCtx, cancel := context.WithCancel(ctx)
go s.doListenTCP(portCtx, port)
go func() {
if err := s.doListenTCP(portCtx, port); err != nil {
s.Logger.Errorw("Unable to listen to port.", "err", err)
}
}()
defer cancel()
}
@@ -72,7 +76,9 @@ func (s *Server) doListenTCP(ctx context.Context, port string) error {
s.Logger.Infow("Got connection on port.", "port", port, "network", "tcp", "remote_addr", conn.RemoteAddr().String())
conn.SetReadDeadline(time.Now().Add(time.Second * 15))
if err := conn.SetReadDeadline(time.Now().Add(time.Second * 15)); err != nil {
s.Logger.Warnw("Error setting connection read deadline.", "err", err)
}
buf := make([]byte, 256)

View File

@@ -1,12 +1,12 @@
// nolint: errcheck
package ports_test
import (
"context"
"net"
"testing"
"time"
"context"
"git.t-juice.club/torjus/apiary/honeypot/ports"
)

View File

@@ -124,7 +124,7 @@ func (s *HoneypotServer) connCallback(ctx sshlib.Context, conn net.Conn) net.Con
func handler(session sshlib.Session) {
_, _ = io.WriteString(session, "[root@hostname ~]#")
session.Exit(1)
_ = session.Exit(1)
}
func ipFromAddr(addr string) net.IP {

View File

@@ -77,7 +77,7 @@ func NewMetricsCollectingStore(ctx context.Context, store LoginAttemptStore) *Me
case <-ctx.Done():
return
case <-mcs.statsTicker.C:
mcs.Stats(LoginStatsTotals, 0)
mcs.Stats(LoginStatsTotals, 0) // nolint: errcheck
}
}
}()
@@ -116,7 +116,6 @@ func (s *MetricsCollectingStore) Stats(statType LoginStats, limit int) ([]StatsR
}
}
return stats, err
}
func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) {

View File

@@ -53,7 +53,7 @@ RETURNING id;`
if err != nil {
return err
}
defer tx.Rollback()
defer tx.Rollback() // nolint: errcheck
var id int
if err := tx.QueryRow(stmt, l.Date, l.RemoteIP.String(), l.Username, l.Password, l.SSHClientVersion, l.ConnectionUUID, l.Country).Scan(&id); err != nil {

View File

@@ -1,3 +1,4 @@
// nolint: errcheck
package store_test
import (
@@ -27,6 +28,7 @@ func TestPostgresStore(t *testing.T) {
testLoginAttemptStore(s, t)
}
func TestPostgresStoreWithCache(t *testing.T) {
var dsn string
var found bool
@@ -47,6 +49,7 @@ func TestPostgresStoreWithCache(t *testing.T) {
testLoginAttemptStore(s, t)
}
func BenchmarkPostgresStore(b *testing.B) {
var dsn string
var found bool