diff --git a/.github/workflows/codeql_httpserver.yaml b/.github/workflows/codeql_httpserver.yaml index 69fbc80..4f82554 100644 --- a/.github/workflows/codeql_httpserver.yaml +++ b/.github/workflows/codeql_httpserver.yaml @@ -31,7 +31,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/lint-test_httpserver.yml b/.github/workflows/lint-test_httpserver.yml index d489fb8..0454591 100644 --- a/.github/workflows/lint-test_httpserver.yml +++ b/.github/workflows/lint-test_httpserver.yml @@ -9,7 +9,7 @@ on: env: PACKAGE: httpserver - GO_VERSION: 1.19 + GO_VERSION: stable name: test-httpserver jobs: @@ -18,15 +18,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - name: Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: version: latest args: --timeout=5m -c=$GITHUB_WORKSPACE/.golangci.yml @@ -37,10 +37,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} diff --git a/auth/Makefile b/auth/Makefile new file mode 100644 index 0000000..1c8faf9 --- /dev/null +++ b/auth/Makefile @@ -0,0 +1,4 @@ +test: + go test -race -timeout=10s ./... +lint: + golangci-lint run --fix -c=../.golangci.yml \ No newline at end of file diff --git a/auth/authentication.go b/auth/authentication.go index 9d213b9..d2f5cfd 100644 --- a/auth/authentication.go +++ b/auth/authentication.go @@ -5,24 +5,26 @@ import ( "log" "go.uber.org/zap" - + "google.golang.org/grpc" "google.golang.org/grpc/codes" - - "google.golang.org/grpc/status" - "google.golang.org/grpc/metadata" - - "google.golang.org/grpc" + "google.golang.org/grpc/status" ) -type AuthInterceptor struct { +// Interceptor is a server interceptor to authenticate and authorize requests. +type Interceptor struct { logger *zap.Logger jwtManager *JWTManager authRoles map[string][]string } -func NewAuthInterceptor(logger *zap.Logger, jwtManager *JWTManager, authRoles map[string][]string) *AuthInterceptor { - return &AuthInterceptor{ +// NewAuthInterceptor creates a new authorizer interceptor. +func NewAuthInterceptor( + logger *zap.Logger, + jwtManager *JWTManager, + authRoles map[string][]string, +) *Interceptor { + return &Interceptor{ logger: logger, jwtManager: jwtManager, authRoles: authRoles, @@ -30,13 +32,13 @@ func NewAuthInterceptor(logger *zap.Logger, jwtManager *JWTManager, authRoles ma } // Unary returns a server interceptor function to authenticate and authorize unary RPC. -func (i *AuthInterceptor) Unary() grpc.UnaryServerInterceptor { +func (i *Interceptor) Unary() grpc.UnaryServerInterceptor { return func( ctx context.Context, - req interface{}, + req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, - ) (interface{}, error) { + ) (any, error) { log.Println("--> unary interceptor: ", info.FullMethod) ctxAuth, err := i.authorize(ctx, info.FullMethod) @@ -48,7 +50,7 @@ func (i *AuthInterceptor) Unary() grpc.UnaryServerInterceptor { } } -func (i *AuthInterceptor) authorize(ctx context.Context, method string) (context.Context, error) { +func (i *Interceptor) authorize(ctx context.Context, method string) (context.Context, error) { authRoles, ok := i.authRoles[method] if !ok { // public route diff --git a/auth/authorization.go b/auth/authorization.go index 41ce946..a483c85 100644 --- a/auth/authorization.go +++ b/auth/authorization.go @@ -4,35 +4,39 @@ import ( "context" "github.com/dgrijalva/jwt-go" - "go.uber.org/zap" - + "google.golang.org/grpc" "google.golang.org/grpc/codes" - - "google.golang.org/grpc/status" - "google.golang.org/grpc/metadata" - - "google.golang.org/grpc" + "google.golang.org/grpc/status" ) +// AuthorizerConfig is the configuration for the authorizer interceptor. type AuthorizerConfig struct { Secret string } +// AuthorizerInterceptor is a server interceptor to authenticate and authorize requests. type AuthorizerInterceptor struct { logger *zap.Logger jwtManager *JWTManager config *AuthorizerConfig } +// ProviderClaims is a custom JWT claims that contains some provider's information. type ProviderClaims struct { jwt.StandardClaims } +// CtxProviderClaimsKey is a context key for provider claims. type CtxProviderClaimsKey struct{} -func NewAuthorizerInterceptor(logger *zap.Logger, jwtManager *JWTManager, config *AuthorizerConfig) *AuthorizerInterceptor { +// NewAuthorizerInterceptor creates a new authorizer interceptor. +func NewAuthorizerInterceptor( + logger *zap.Logger, + jwtManager *JWTManager, + config *AuthorizerConfig, +) *AuthorizerInterceptor { return &AuthorizerInterceptor{ logger: logger, jwtManager: jwtManager, @@ -44,10 +48,10 @@ func NewAuthorizerInterceptor(logger *zap.Logger, jwtManager *JWTManager, config func (i *AuthorizerInterceptor) Unary() grpc.UnaryServerInterceptor { return func( ctx context.Context, - req interface{}, + req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, - ) (interface{}, error) { + ) (any, error) { authorize, err := i.authorize(ctx, info.FullMethod) if err != nil { return nil, err @@ -57,7 +61,7 @@ func (i *AuthorizerInterceptor) Unary() grpc.UnaryServerInterceptor { } } -func (i *AuthorizerInterceptor) authorize(ctx context.Context, method string) (context.Context, error) { +func (i *AuthorizerInterceptor) authorize(ctx context.Context, _ string) (context.Context, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { @@ -74,14 +78,13 @@ func (i *AuthorizerInterceptor) authorize(ctx context.Context, method string) (c p := jwt.Parser{ValidMethods: []string{jwt.SigningMethodHS256.Name}} - _, err := p.ParseWithClaims(signature[0], &claims, func(token *jwt.Token) (interface{}, error) { + _, err := p.ParseWithClaims(signature[0], &claims, func(*jwt.Token) (any, error) { return []byte(i.config.Secret), nil }) if err != nil { + // nolint: revive return nil, status.Errorf(codes.Unauthenticated, "you are not authorized to access this resource") } - ctx = context.WithValue(ctx, CtxProviderClaimsKey{}, claims) - - return ctx, nil + return context.WithValue(ctx, CtxProviderClaimsKey{}, claims), nil } diff --git a/auth/go.mod b/auth/go.mod index 52e3a10..99e81f8 100644 --- a/auth/go.mod +++ b/auth/go.mod @@ -1,19 +1,24 @@ module github.com/purposeinplay/go-commons/auth -go 1.18 +go 1.22 + +toolchain go1.23.4 require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible - go.uber.org/zap v1.26.0 - google.golang.org/grpc v1.60.1 + github.com/stretchr/testify v1.8.1 + go.uber.org/zap v1.27.0 + google.golang.org/grpc v1.68.1 ) require ( - github.com/golang/protobuf v1.5.3 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect - google.golang.org/protobuf v1.32.0 // indirect + golang.org/x/net v0.32.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect + google.golang.org/protobuf v1.35.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/auth/go.sum b/auth/go.sum index fbcb489..811dd22 100644 --- a/auth/go.sum +++ b/auth/go.sum @@ -1,31 +1,41 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA= -google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= -google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 h1:IfdSdTcLFy4lqUQrQJLkLt1PB+AsqVz6lwkWPzWEz10= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= +google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0= +google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/auth/jwt_manager.go b/auth/jwt_manager.go index 70f884d..1e07a4e 100644 --- a/auth/jwt_manager.go +++ b/auth/jwt_manager.go @@ -2,6 +2,7 @@ package auth import ( "context" + "errors" "fmt" "time" @@ -40,15 +41,21 @@ func NewJWTManager(secretKey string, tokenDuration time.Duration) *JWTManager { return &JWTManager{secretKey, tokenDuration} } +// JWT parsing errors. +var ( + ErrInvalidTokenClaims = errors.New("invalid token claims") + ErrUnexpectedTokenSigningMethod = errors.New("unexpected token signing method") +) + // Verify verifies the access token string and return a user claim if the token is valid. func (m *JWTManager) Verify(accessToken string) (*UserClaims, error) { token, err := jwt.ParseWithClaims( accessToken, &UserClaims{}, - func(token *jwt.Token) (interface{}, error) { + func(token *jwt.Token) (any, error) { _, ok := token.Method.(*jwt.SigningMethodHMAC) if !ok { - return nil, fmt.Errorf("unexpected token signing method") + return nil, ErrUnexpectedTokenSigningMethod } return []byte(m.secretKey), nil @@ -60,7 +67,7 @@ func (m *JWTManager) Verify(accessToken string) (*UserClaims, error) { claims, ok := token.Claims.(*UserClaims) if !ok { - return nil, fmt.Errorf("invalid token claims") + return nil, ErrInvalidTokenClaims } return claims, nil diff --git a/auth/metadata.go b/auth/metadata.go index 52b131e..58dcd79 100644 --- a/auth/metadata.go +++ b/auth/metadata.go @@ -1,16 +1,23 @@ package auth import ( - "fmt" + "errors" "strings" "google.golang.org/grpc/metadata" ) +// GRPC Metadata auth errors. +var ( + ErrAuthTokenMissing = errors.New("auth token is missing") + ErrBadAuthString = errors.New("bad authorization string") +) + +// ExtractTokenFromMetadata extracts the token from the grpc metadata. func ExtractTokenFromMetadata(md metadata.MD) (string, error) { meta, ok := md["authorization"] if !ok { - return "", fmt.Errorf("auth token is missing") + return "", ErrAuthTokenMissing } auth := meta[0] @@ -18,7 +25,7 @@ func ExtractTokenFromMetadata(md metadata.MD) (string, error) { const prefix = "Bearer " if !strings.HasPrefix(auth, prefix) { - return "", fmt.Errorf("bad authorization string") + return "", ErrBadAuthString } return auth[len(prefix):], nil diff --git a/auth/middleware.go b/auth/middleware.go index b6bf08f..cf4bf61 100644 --- a/auth/middleware.go +++ b/auth/middleware.go @@ -5,10 +5,11 @@ import ( "net/http" ) +// Header keys. const ( - HeaderUserID = "X-USER-ID" - HeaderAppID = "X-APP-ID" - HeaderUsername = "X-USERNAME" + HeaderUserID = "X-User-Id" + HeaderAppID = "X-App-Id" + HeaderUsername = "X-Username" ) type contextKey int @@ -21,6 +22,7 @@ const ( usernameCtxKey ) +// UserIDMiddlewareFunc is a middleware that extracts the user ID from the request. func UserIDMiddlewareFunc(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { userID := r.Header.Get(HeaderUserID) @@ -30,6 +32,7 @@ func UserIDMiddlewareFunc(next http.Handler) http.Handler { }) } +// AppIDMiddlewareFunc is a middleware that extracts the app ID from the request. func AppIDMiddlewareFunc(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { appID := r.Header.Get(HeaderAppID) @@ -39,6 +42,7 @@ func AppIDMiddlewareFunc(next http.Handler) http.Handler { }) } +// UsernameMiddlewareFunc is a middleware that extracts the username from the request. func UsernameMiddlewareFunc(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { username := r.Header.Get(HeaderUsername) @@ -48,6 +52,7 @@ func UsernameMiddlewareFunc(next http.Handler) http.Handler { }) } +// NewUserIDContext returns a new context with the user ID. func NewUserIDContext(ctx context.Context, userID string) context.Context { if userID == "" { return ctx @@ -56,6 +61,7 @@ func NewUserIDContext(ctx context.Context, userID string) context.Context { return context.WithValue(ctx, userIDCtxKey, userID) } +// NewAppIDContext returns a new context with the app ID. func NewAppIDContext(ctx context.Context, appID string) context.Context { if appID == "" { return ctx @@ -64,6 +70,7 @@ func NewAppIDContext(ctx context.Context, appID string) context.Context { return context.WithValue(ctx, appIDCtxKey, appID) } +// NewUsernameContext returns a new context with the username. func NewUsernameContext(ctx context.Context, username string) context.Context { if username == "" { return ctx @@ -72,19 +79,25 @@ func NewUsernameContext(ctx context.Context, username string) context.Context { return context.WithValue(ctx, usernameCtxKey, usernameCtxKey) } +// UserIDFromContext returns the user ID from the context. func UserIDFromContext(ctx context.Context) string { + // nolint: revive userID, _ := ctx.Value(userIDCtxKey).(string) return userID } +// AppIDFromContext returns the app ID from the context. func AppIDFromContext(ctx context.Context) string { + // nolint: revive appID, _ := ctx.Value(appIDCtxKey).(string) return appID } +// UsernameFromContext returns the username from the context. func UsernameFromContext(ctx context.Context) string { + // nolint: revive username, _ := ctx.Value(usernameCtxKey).(string) return username diff --git a/auth/middleware_test.go b/auth/middleware_test.go new file mode 100644 index 0000000..f48a8c6 --- /dev/null +++ b/auth/middleware_test.go @@ -0,0 +1,45 @@ +package auth_test + +import ( + "net/http" + "testing" + + "github.com/purposeinplay/go-commons/auth" + "github.com/stretchr/testify/require" +) + +func TestMiddlewareUserID(t *testing.T) { + tests := map[string]struct { + requestUserID string + }{ + "NoUserID": { + requestUserID: "", + }, + "UserID": { + requestUserID: "123", + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + var userID string + + auth.UserIDMiddlewareFunc( + http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { + userID = auth.UserIDFromContext(r.Context()) + }), + ).ServeHTTP( + nil, + &http.Request{ + Header: http.Header{ + auth.HeaderUserID: []string{test.requestUserID}, + }, + }, + ) + + t.Log("UserID:", userID) + + require.Equal(t, test.requestUserID, userID) + }) + } +} diff --git a/httpserver/go.mod b/httpserver/go.mod index 71704cf..090e742 100644 --- a/httpserver/go.mod +++ b/httpserver/go.mod @@ -1,11 +1,10 @@ module github.com/purposeinplay/go-commons/httpserver -go 1.17 +go 1.21 require ( - github.com/matryer/is v1.4.0 - go.uber.org/atomic v1.11.0 - go.uber.org/zap v1.25.0 + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.8.1 + gopkg.in/yaml.v3 v3.0.1 // indirect ) - -require go.uber.org/multierr v1.11.0 // indirect diff --git a/httpserver/go.sum b/httpserver/go.sum index 6962701..2ec90f7 100644 --- a/httpserver/go.sum +++ b/httpserver/go.sum @@ -1,69 +1,17 @@ -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= -github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= -go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= -go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= -go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= -go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= -go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c= -go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/httpserver/options.go b/httpserver/options.go index 1fafdc4..b67ff7c 100644 --- a/httpserver/options.go +++ b/httpserver/options.go @@ -3,12 +3,11 @@ package httpserver import ( "context" "fmt" + "log/slog" "net" "os" "os/signal" "time" - - "go.uber.org/zap" ) // An Option configures an App using the functional options paradigm @@ -31,7 +30,7 @@ func (o addressOption) apply(s *Server) { } func (o addressOption) String() string { - return fmt.Sprintf("server.Address: %s", string(o)) + return "server.Address: " + string(o) } // WithAddress will set the address field of the server. @@ -171,24 +170,21 @@ func (o shutdownSignalsOption) apply(server *Server) { server.log.Debug( "waiting for shutdown signals", - zap.Stringer("signals", o), + slog.String("signals", o.String()), ) sig := <-sigC server.log.Info( "received shut down signal", - zap.String( - "signal", - sig.String(), - ), + slog.String("signal", sig.String()), ) err := server.Shutdown(shutdownTimeout) if err != nil { server.log.Error( "failed to shutdown server in time", - zap.Error(err), + slog.String("error", err.Error()), ) } }() diff --git a/httpserver/options_example_test.go b/httpserver/options_example_test.go index 32eaaa7..16486f7 100644 --- a/httpserver/options_example_test.go +++ b/httpserver/options_example_test.go @@ -35,7 +35,7 @@ func ExampleWithBaseContext() { fmt.Println(opt) // Output: - // server.BaseContext: context.Background.WithValue(type httpserver_test.key, val example) + // server.BaseContext: context.Background.WithValue(httpserver_test.key, example) // server.CancelContextOnShutdown: true } diff --git a/httpserver/server.go b/httpserver/server.go index 1643da9..a635be5 100644 --- a/httpserver/server.go +++ b/httpserver/server.go @@ -3,16 +3,15 @@ package httpserver import ( "context" "errors" + "log/slog" "net" "net/http" "sync" "time" - - "go.uber.org/zap" ) const ( - defaultAddr = ":8080" + defaultAddr = ":80" ) // Info holds relevant information about the Server. @@ -29,7 +28,7 @@ type Server struct { // underlying http server httpServer *http.Server - log *zap.Logger + log *slog.Logger // chan to signal that the server was shutdown which means that either the // Server() or ListenAndServe() methods returned. @@ -46,7 +45,7 @@ type Server struct { // You can use Options to override the defaults. // Default list: // - Address: ":8080". -func New(log *zap.Logger, handler http.Handler, options ...Option) *Server { +func New(logger *slog.Logger, handler http.Handler, options ...Option) *Server { const ( handlerTimeout = 10 * time.Second readHeaderTimeout = 5 * time.Second @@ -71,7 +70,7 @@ func New(log *zap.Logger, handler http.Handler, options ...Option) *Server { WriteTimeout: writeTimeout, IdleTimeout: idleTimeout, }, - log: log, + log: logger, done: make(chan struct{}), } @@ -117,7 +116,7 @@ func (s *Server) Serve(ln net.Listener) error { // that logs basic information // and blocks execution until the Server.Shutdown() method is called. func (s *Server) ListenAndServe() error { - s.log.Info("starting server", zap.String("address", s.httpServer.Addr)) + s.log.Info("starting server", slog.String("address", s.httpServer.Addr)) err := s.httpServer.ListenAndServe() diff --git a/httpserver/server_test.go b/httpserver/server_test.go index 9d060bd..f9f7604 100644 --- a/httpserver/server_test.go +++ b/httpserver/server_test.go @@ -2,41 +2,41 @@ package httpserver_test import ( "context" - "errors" "fmt" + "log/slog" "net" "net/http" "os" "sync" + "sync/atomic" "syscall" "testing" "time" - "github.com/matryer/is" "github.com/purposeinplay/go-commons/httpserver" - "go.uber.org/atomic" - "go.uber.org/zap" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestServer_ShutdownWithoutCallingListenAndServe(t *testing.T) { - i := is.New(t) + req := require.New(t) - s := httpserver.New(zap.NewExample(), nil) + s := httpserver.New(slog.Default(), nil) err := s.Shutdown(0) - i.NoErr(err) + req.NoError(err) } func TestServer_DoubleShutdown(t *testing.T) { - i := is.New(t) + req := require.New(t) - s := httpserver.New(zap.NewExample(), nil) + s := httpserver.New(slog.Default(), nil) err := s.Shutdown(0) - i.NoErr(err) + req.NoError(err) err = s.Shutdown(0) - i.NoErr(err) + req.NoError(err) } func TestServer(t *testing.T) { @@ -91,7 +91,7 @@ func TestServer(t *testing.T) { // holds server options type serverOptions struct { - logger *zap.Logger + logger *slog.Logger handler http.Handler options []httpserver.Option } @@ -118,7 +118,7 @@ func TestServer(t *testing.T) { // server will shutdown after request finishes due to increased timeout "ShutdownWithoutClosingLongLivedConnectionContext": { serverOptions: serverOptions{ - logger: zap.NewExample(), + logger: slog.Default(), handler: defaultHandler(), }, @@ -132,7 +132,7 @@ func TestServer(t *testing.T) { // request finishes due to the timeout "ShutdownDeadlineExceeded": { serverOptions: serverOptions{ - logger: zap.NewExample(), + logger: slog.Default(), handler: defaultHandler(), }, @@ -145,7 +145,7 @@ func TestServer(t *testing.T) { // server shutdown wll also close the request context "ShutdownWithClosingBaseContext": { serverOptions: serverOptions{ - logger: zap.NewExample(), + logger: slog.Default(), handler: defaultHandler(), options: []httpserver.Option{httpserver.WithBaseContext( context.Background(), @@ -161,7 +161,7 @@ func TestServer(t *testing.T) { "ShutdownWithSignals": { serverOptions: serverOptions{ - logger: zap.NewExample(), + logger: slog.Default(), handler: defaultHandler(), options: []httpserver.Option{ httpserver.WithShutdownSignalsOption(syscall.SIGINT), @@ -175,7 +175,7 @@ func TestServer(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { - i := is.New(t) + req := require.New(t) // initialize the shutdown server chan everytime a test is run shutdownServer = make(chan struct{}) @@ -193,14 +193,14 @@ func TestServer(t *testing.T) { // create a new listener for the given addres ln, err := net.Listen("tcp", httpServer.Info().Addr) - i.NoErr(err) + req.NoError(err) go func() { defer wg.Done() // start accepting requests err := httpServer.Serve(ln) - i.NoErr(err) + assert.NoError(t, err) t.Logf("server complete") }() @@ -217,25 +217,26 @@ func TestServer(t *testing.T) { // send a request to the server resp, err := http.Get(address) - i.NoErr(err) + assert.NoError(t, err) switch handlerExitStatus.Load() { // due to http.TimeoutHandler 503 is returned when // request'httpServer context is cancelled. case exitContext: - i.Equal( + assert.Equal( + t, http.StatusServiceUnavailable, resp.StatusCode, ) case exitTimeAfter: - i.Equal(http.StatusOK, resp.StatusCode) + assert.Equal(t, http.StatusOK, resp.StatusCode) default: - i.Equal(http.StatusOK, resp.StatusCode) + assert.Equal(t, http.StatusOK, resp.StatusCode) } err = resp.Body.Close() - i.NoErr(err) + assert.NoError(t, err) t.Logf("request complete") }() @@ -249,13 +250,13 @@ func TestServer(t *testing.T) { // send the shutdown signals err := sendSignals(test.shutdownSignals...) - i.NoErr(err) + req.NoError(err) } else { t.Logf("calling server.Shutdown()") // shutdown the server err := httpServer.Shutdown(test.shutdownTimeout) - i.True(errors.Is(err, test.expectedShutdownError)) + req.ErrorIs(err, test.expectedShutdownError) } t.Logf("shutdown complete") @@ -264,7 +265,7 @@ func TestServer(t *testing.T) { wg.Wait() if test.serverOptions.handler != nil { - i.Equal( + req.Equal( test.expectedHandlerExitStatus, handlerExitStatus.Load(), ) diff --git a/kafkadocker/cluster.go b/kafkadocker/cluster.go index fd6c4ac..4983850 100644 --- a/kafkadocker/cluster.go +++ b/kafkadocker/cluster.go @@ -15,6 +15,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/network" "github.com/testcontainers/testcontainers-go/wait" "golang.org/x/sync/errgroup" ) @@ -24,11 +25,12 @@ type Cluster struct { Brokers int // For specifying the number of brokers to start. Topics []string // For specifying the topics to create. HealthProbe bool // For specifying whether to health-probe the brokers after creation. + Kraft bool // For specifying whether to use the Kafka Raft protocol. zookeeperContainer testcontainers.Container brokerContainers []brokerContainer started atomic.Bool - network testcontainers.Network + network *testcontainers.DockerNetwork } // BrokerAddresses returns the addresses of the brokers in the cluster. @@ -54,20 +56,240 @@ func (c *Cluster) Start(ctx context.Context) error { return ErrBrokerAlreadyStarted } - const networkName = "kafkadocker" + kafkaNetwork, err := network.New(ctx) + if err != nil { + return fmt.Errorf("create network: %w", err) + } + + c.network = kafkaNetwork + + if !c.Kraft { + if err := c.startZookeeperCluster(ctx, kafkaNetwork.Name); err != nil { + return fmt.Errorf("start zookeeper cluster: %w", err) + } + + return nil + } + + if err := c.startKraftCluster(ctx, kafkaNetwork.Name); err != nil { + return fmt.Errorf("start kraft cluster: %w", err) + } + + return nil +} + +// Stop removes all the containers and the network concerning the cluster. +// nolint: gocognit, gocyclo +func (c *Cluster) Stop(ctx context.Context) error { + if !c.started.Load() { + return ErrBrokerWasNotStarted + } + + eg, egCtx := errgroup.WithContext(ctx) + + if c.zookeeperContainer != nil { + eg.Go(func() error { + if err := c.zookeeperContainer.Terminate(egCtx); err != nil { + return fmt.Errorf("terminate zookeeper container: %w", err) + } + + return nil + }) + } + + for i := range c.brokerContainers { + eg.Go(func() error { + if err := c.brokerContainers[i].Terminate(egCtx); err != nil { + return fmt.Errorf("terminate broker container %d: %w", i, err) + } + + return nil + }) + } + + var errs error + + if err := eg.Wait(); err != nil { + errs = errors.Join(errs, fmt.Errorf("terminate containers: %w", err)) + } + + if c.network != nil { + if err := c.network.Remove(ctx); err != nil { + errs = errors.Join(errs, fmt.Errorf("remove network: %w", err)) + } + } + + c.started.Store(false) + + return errs +} + +func (c *Cluster) startKraftCluster(ctx context.Context, networkName string) error { + const starterScriptName = "/testcontainers_start.sh" + + brokerControllerContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Image: "confluentinc/cp-kafka", + Name: "kafkadocker", + Hostname: "kafkadocker", + ExposedPorts: []string{ + "9092/tcp", + }, + // nolint: revive // line too long + Env: map[string]string{ + "KAFKA_PROCESS_ROLES": "controller,broker", + "KAFKA_NODE_ID": "1", + "CLUSTER_ID": "h6EwvA-jRU6omVykKrSg1w", + "KAFKA_LISTENER_SECURITY_PROTOCOL_MAP": "CONTROLLER:PLAINTEXT,BROKER:SASL_PLAINTEXT", + "KAFKA_LISTENERS": "BROKER://kafkadocker:9092,CONTROLLER://kafkadocker:9093", + "KAFKA_CONTROLLER_LISTENER_NAMES": "CONTROLLER", + "KAFKA_CONTROLLER_QUORUM_VOTERS": "1@kafkadocker:9093", + "KAFKA_INTER_BROKER_LISTENER_NAME": "BROKER", + "KAFKA_SASL_ENABLED_MECHANISMS": "PLAIN", + "KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL": "PLAIN", + "KAFKA_OPTS": "-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf", + }, + Networks: []string{networkName}, + NetworkAliases: map[string][]string{ + networkName: {"kafkadocker"}, + }, + WaitingFor: wait.ForLog("Kafka Server started"), + HostConfigModifier: func(config *container.HostConfig) { + config.RestartPolicy = container.RestartPolicy{Name: "unless-stopped"} + }, + Cmd: []string{ + "sh", + "-c", + fmt.Sprintf( + `while [ ! -f %[1]s ]; do sleep 0.1; done; %[1]s`, + starterScriptName, + ), + }, + LifecycleHooks: []testcontainers.ContainerLifecycleHooks{ + { + PostStarts: []testcontainers.ContainerHook{ + func(ctx context.Context, container testcontainers.Container) error { + var ( + advertisedListenerAddress = "BROKER://localhost:" + startScript string + ) + + const ( + retryAttempts = 5 + retryDelay = time.Second / 10 + ) + + if err := retry.Do(func() error { + p, err := container.MappedPort(ctx, "9092/tcp") + if err != nil { + return fmt.Errorf("get hook mapped port: %w", err) + } + + advertisedListenerAddress += p.Port() + + return nil + }, retry.Attempts(retryAttempts), retry.Delay(retryDelay)); err != nil { + return fmt.Errorf("get advertised listener address: %w", err) + } + + startScriptReader, err := container.CopyFileFromContainer( + ctx, + "/etc/confluent/docker/run", + ) + if err != nil { + // nolint: revive // line too long + return fmt.Errorf( + "copy start script from container: %w", + err, + ) + } + + ss, err := io.ReadAll(startScriptReader) + if err != nil { + return fmt.Errorf("read start script: %w", err) + } + + if err := startScriptReader.Close(); err != nil { + return fmt.Errorf("close start script reader: %w", err) + } + + startScript = string(ss) - network, err := testcontainers.GenericNetwork(ctx, testcontainers.GenericNetworkRequest{ - NetworkRequest: testcontainers.NetworkRequest{ - Name: networkName, - CheckDuplicate: true, + lastFiIdx := strings.LastIndex(startScript, "fi\n") + + startScript = startScript[:lastFiIdx+3] + fmt.Sprintf( + "\nexport KAFKA_ADVERTISED_LISTENERS=%s;env\n", + advertisedListenerAddress, + ) + startScript[lastFiIdx+3:] + + const fileMode = 0o755 + + if err := container.CopyToContainer( + ctx, + []byte(startScript), + starterScriptName, + fileMode, + ); err != nil { + return fmt.Errorf("copy start script to container: %w", err) + } + + return nil + }, + }, + }, + }, }, - }) + Reuse: true, + Started: false, + } + + brokContContainer, err := testcontainers.GenericContainer(ctx, brokerControllerContainerReq) if err != nil { - return fmt.Errorf("create network: %w", err) + return fmt.Errorf("create broker controller container: %w", err) + } + + const fileMode755 = 0o755 + + if err := brokContContainer.CopyToContainer( + ctx, + []byte(`KafkaServer { + org.apache.kafka.common.security.plain.PlainLoginModule required + username="admin" + password="admin-secret" + user_admin="admin-secret" + user_user1="user1-secret" + user_user2="user2-secret"; +};`), + "/etc/kafka/kafka_server_jaas.conf", + fileMode755, + ); err != nil { + return fmt.Errorf("copy jaas config to container: %w", err) } - c.network = network + if err := brokContContainer.Start(ctx); err != nil { + return fmt.Errorf("start broker controller container: %w", err) + } + + c.brokerContainers = []brokerContainer{{Container: brokContContainer}} + for i, bc := range c.brokerContainers { + containerIP, err := bc.Host(ctx) + if err != nil { + return fmt.Errorf("get broker container %d ip: %w", i, err) + } + + port, err := bc.MappedPort(ctx, "9092/tcp") + if err != nil { + return fmt.Errorf("get broker container %d mapped port: %w", i, err) + } + + c.brokerContainers[i].hostAddress = fmt.Sprintf("%s:%s", containerIP, port.Port()) + } + + return nil +} + +func (c *Cluster) startZookeeperCluster(ctx context.Context, networkName string) error { zookeeperReq := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ Image: "confluentinc/cp-zookeeper", @@ -229,7 +451,7 @@ func (c *Cluster) Start(ctx context.Context) error { ) startScript = startScript[:lastFiIdx+3] + fmt.Sprintf( - "\necho wtf;export KAFKA_ADVERTISED_LISTENERS=%s;env\n", + "\nexport KAFKA_ADVERTISED_LISTENERS=%s;env\n", advListeners, ) + startScript[lastFiIdx+3:] @@ -295,8 +517,6 @@ func (c *Cluster) Start(ctx context.Context) error { eg, egCtx := errgroup.WithContext(ctx) for i := range c.brokerContainers { - i := i - eg.Go(func() error { return probeBroker(egCtx, c.brokerContainers[i]) }) @@ -310,54 +530,6 @@ func (c *Cluster) Start(ctx context.Context) error { return nil } -// Stop removes all the containers and the network concerning the cluster. -// nolint: gocognit, gocyclo -func (c *Cluster) Stop(ctx context.Context) error { - if !c.started.Load() { - return ErrBrokerWasNotStarted - } - - eg, egCtx := errgroup.WithContext(ctx) - - if c.zookeeperContainer != nil { - eg.Go(func() error { - if err := c.zookeeperContainer.Terminate(egCtx); err != nil { - return fmt.Errorf("terminate zookeeper container: %w", err) - } - - return nil - }) - } - - for i := range c.brokerContainers { - i := i - - eg.Go(func() error { - if err := c.brokerContainers[i].Terminate(egCtx); err != nil { - return fmt.Errorf("terminate broker container %d: %w", i, err) - } - - return nil - }) - } - - var errs error - - if err := eg.Wait(); err != nil { - errs = errors.Join(errs, fmt.Errorf("terminate containers: %w", err)) - } - - if c.network != nil { - if err := c.network.Remove(ctx); err != nil { - errs = errors.Join(errs, fmt.Errorf("remove network: %w", err)) - } - } - - c.started.Store(false) - - return errs -} - func probeBroker(ctx context.Context, c brokerContainer) error { return retry.Do(func() error { brk := sarama.NewBroker(c.hostAddress) diff --git a/kafkadocker/cluster_test.go b/kafkadocker/cluster_test.go index fcb245d..d2d48d3 100644 --- a/kafkadocker/cluster_test.go +++ b/kafkadocker/cluster_test.go @@ -10,72 +10,104 @@ import ( "github.com/stretchr/testify/require" ) -func TestBroker(t *testing.T) { - t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true") - - req := require.New(t) +func TestKafka(t *testing.T) { ctx := context.Background() - cluster := &kafkadocker.Cluster{ - Brokers: 2, - HealthProbe: true, + tests := map[string]struct { + cluster *kafkadocker.Cluster + }{ + "Zookeeper": { + cluster: &kafkadocker.Cluster{ + Brokers: 2, + HealthProbe: true, + Kraft: false, + }, + }, + "Kraft": { + cluster: &kafkadocker.Cluster{ + Brokers: 1, + HealthProbe: true, + Kraft: true, + }, + }, } - t.Cleanup(func() { - cluster.Stop(ctx) - }) + for name, test := range tests { + t.Run(name, func(t *testing.T) { + t.Parallel() - err := cluster.Start(ctx) - req.NoError(err) + req := require.New(t) - t.Logf("cluster started successfully") + cluster := test.cluster - brokerAddresses := cluster.BrokerAddresses() + t.Logf("starting cluster") - t.Logf("broker addresses: %s", brokerAddresses) + err := cluster.Start(ctx) + req.NoError(err) - cfg := sarama.NewConfig() + t.Logf("cluster started successfully") - cfg.Producer.Return.Successes = true + t.Cleanup(func() { + cluster.Stop(ctx) + }) - client, err := sarama.NewClient(brokerAddresses, cfg) - req.NoError(err) + brokerAddresses := cluster.BrokerAddresses() - t.Cleanup(func() { - err := client.Close() - req.NoError(err) - }) + t.Logf("broker addresses: %s", brokerAddresses) - producer, err := sarama.NewSyncProducerFromClient(client) - req.NoError(err) + cfg := sarama.NewConfig() - const topic = "test" + if test.cluster.Kraft { + cfg.Net.SASL.Enable = true + cfg.Net.SASL.Handshake = true + cfg.Net.SASL.Mechanism = sarama.SASLTypePlaintext + cfg.Net.SASL.User = "admin" + cfg.Net.SASL.Version = sarama.SASLHandshakeV1 + cfg.Net.SASL.Password = "admin-secret" + } - partition, offset, err := producer.SendMessage(&sarama.ProducerMessage{ - Topic: topic, - Value: sarama.StringEncoder(topic), - }) - req.NoError(err) + cfg.Producer.Return.Successes = true - t.Logf("message partition: %d, message offset: %d", partition, offset) + client, err := sarama.NewClient(brokerAddresses, cfg) + req.NoError(err) - consumer, err := sarama.NewConsumerFromClient(client) - req.NoError(err) + t.Cleanup(func() { + err := client.Close() + req.NoError(err) + }) - partConsumer, err := consumer.ConsumePartition(topic, partition, sarama.OffsetOldest) - req.NoError(err) + producer, err := sarama.NewSyncProducerFromClient(client) + req.NoError(err) - select { - case mes := <-partConsumer.Messages(): - t.Logf("message: %+v", mes) - req.Equal(topic, string(mes.Value)) + const topic = "test" - case <-time.After(20 * time.Second): - req.Fail("timeout") - } + partition, offset, err := producer.SendMessage(&sarama.ProducerMessage{ + Topic: topic, + Value: sarama.StringEncoder(topic), + }) + req.NoError(err) + + t.Logf("message partition: %d, message offset: %d", partition, offset) + + consumer, err := sarama.NewConsumerFromClient(client) + req.NoError(err) - topics, err := client.Topics() - req.NoError(err) + partConsumer, err := consumer.ConsumePartition(topic, partition, sarama.OffsetOldest) + req.NoError(err) - req.Equal([]string{topic}, topics) + select { + case mes := <-partConsumer.Messages(): + t.Logf("message: %+v", mes) + req.Equal(topic, string(mes.Value)) + + case <-time.After(20 * time.Second): + req.Fail("timeout") + } + + topics, err := client.Topics() + req.NoError(err) + + req.Equal([]string{topic}, topics) + }) + } } diff --git a/kafkadocker/docker-compose.yaml b/kafkadocker/docker-compose.yaml new file mode 100644 index 0000000..448fd5b --- /dev/null +++ b/kafkadocker/docker-compose.yaml @@ -0,0 +1,30 @@ +services: + kafka1: + image: confluentinc/cp-kafka:7.7.1 + hostname: kafka1 + container_name: kafka1 + ports: + - '9092:9092' # Broker port for client communication + environment: + # Kafka roles and identification + KAFKA_PROCESS_ROLES: 'controller,broker' + KAFKA_NODE_ID: 1 + CLUSTER_ID: h6EwvA-jRU6omVykKrSg1w + + # Listeners and protocols + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,BROKER:SASL_PLAINTEXT + KAFKA_LISTENERS: BROKER://kafka1:9092,CONTROLLER://kafka1:9093 + KAFKA_ADVERTISED_LISTENERS: BROKER://localhost:9092 + KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER + KAFKA_CONTROLLER_QUORUM_VOTERS: '1@kafka1:9093' + KAFKA_INTER_BROKER_LISTENER_NAME: BROKER + + # SASL configuration + KAFKA_SASL_ENABLED_MECHANISMS: PLAIN + KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL: PLAIN + + # Java security options for JAAS configuration + KAFKA_OPTS: "-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf" + volumes: + - ./kafka-data2:/var/lib/kafka/data + - ./kafka_server_jaas.conf:/etc/kafka/kafka_server_jaas.conf \ No newline at end of file diff --git a/kafkadocker/go.mod b/kafkadocker/go.mod index 773fad0..63c39aa 100644 --- a/kafkadocker/go.mod +++ b/kafkadocker/go.mod @@ -1,66 +1,84 @@ module github.com/purposeinplay/go-commons/kafkadocker -go 1.20 +go 1.22.0 + +toolchain go1.23.2 require ( - github.com/IBM/sarama v1.40.0 + github.com/IBM/sarama v1.43.3 github.com/avast/retry-go v3.0.0+incompatible - github.com/docker/docker v24.0.4+incompatible - github.com/docker/go-connections v0.4.0 - github.com/stretchr/testify v1.8.4 - github.com/testcontainers/testcontainers-go v0.21.0 - golang.org/x/sync v0.3.0 + github.com/docker/docker v27.3.1+incompatible + github.com/docker/go-connections v0.5.0 + github.com/stretchr/testify v1.9.0 + github.com/testcontainers/testcontainers-go v0.34.0 + golang.org/x/sync v0.8.0 ) require ( + dario.cat/mergo v1.0.1 // indirect + github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect - github.com/Microsoft/go-winio v0.6.1 // indirect - github.com/cenkalti/backoff/v4 v4.2.1 // indirect - github.com/containerd/containerd v1.7.2 // indirect - github.com/cpuguy83/dockercfg v0.3.1 // indirect + github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/containerd/log v0.1.0 // indirect + github.com/containerd/platforms v0.2.1 // indirect + github.com/cpuguy83/dockercfg v0.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/docker/distribution v2.8.2+incompatible // indirect + github.com/distribution/reference v0.6.0 // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/eapache/go-resiliency v1.3.0 // indirect - github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 // indirect + github.com/eapache/go-resiliency v1.7.0 // indirect + github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect github.com/eapache/queue v1.1.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect - github.com/imdario/mergo v0.3.16 // indirect github.com/jcmturner/aescts/v2 v2.0.0 // indirect github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect github.com/jcmturner/gofork v1.7.6 // indirect github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect - github.com/klauspost/compress v1.16.7 // indirect - github.com/kr/text v0.2.0 // indirect + github.com/klauspost/compress v1.17.11 // indirect + github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect github.com/magiconair/properties v1.8.7 // indirect - github.com/moby/patternmatcher v0.5.0 // indirect - github.com/moby/sys/sequential v0.5.0 // indirect + github.com/moby/docker-image-spec v1.3.1 // indirect + github.com/moby/patternmatcher v0.6.0 // indirect + github.com/moby/sys/sequential v0.6.0 // indirect + github.com/moby/sys/user v0.3.0 // indirect + github.com/moby/sys/userns v0.1.0 // indirect github.com/moby/term v0.5.0 // indirect github.com/morikuni/aec v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.1.0-rc4 // indirect - github.com/opencontainers/runc v1.1.8 // indirect - github.com/pierrec/lz4/v4 v4.1.18 // indirect + github.com/opencontainers/image-spec v1.1.0 // indirect + github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/shirou/gopsutil/v3 v3.24.5 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.12.0 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/tools v0.11.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753 // indirect - google.golang.org/grpc v1.56.2 // indirect - google.golang.org/protobuf v1.31.0 // indirect + github.com/tklauser/go-sysconf v0.3.14 // indirect + github.com/tklauser/numcpus v0.9.0 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect + go.opentelemetry.io/otel v1.31.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect + go.opentelemetry.io/otel/sdk v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.31.0 // indirect + golang.org/x/crypto v0.28.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect + google.golang.org/grpc v1.67.1 // indirect + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gotest.tools/v3 v3.5.0 // indirect ) diff --git a/kafkadocker/go.sum b/kafkadocker/go.sum index d49aaf5..85556aa 100644 --- a/kafkadocker/go.sum +++ b/kafkadocker/go.sum @@ -1,57 +1,66 @@ -github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 h1:EKPd1INOIyr5hWOWhvpmQpY6tKjeG0hT1s3AMC/9fic= +dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= +dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= -github.com/IBM/sarama v1.40.0 h1:QTVmX+gMKye52mT5x+Ve/Bod2D0Gy7ylE2Wslv+RHtc= -github.com/IBM/sarama v1.40.0/go.mod h1:6pBloAs1WanL/vsq5qFTyTGulJUntZHhMLOUYEIs9mg= -github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= -github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/Microsoft/hcsshim v0.10.0-rc.8 h1:YSZVvlIIDD1UxQpJp0h+dnpLUw+TrY0cx8obKsp3bek= -github.com/Shopify/toxiproxy/v2 v2.5.0 h1:i4LPT+qrSlKNtQf5QliVjdP08GyAH8+BUIc9gT0eahc= +github.com/IBM/sarama v1.43.3 h1:Yj6L2IaNvb2mRBop39N7mmJAHBVY3dTPncr3qGVkxPA= +github.com/IBM/sarama v1.43.3/go.mod h1:FVIRaLrhK3Cla/9FfRF5X9Zua2KpS3SYIXxhac1H+FQ= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0= github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= -github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= -github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= -github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E= -github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= -github.com/containerd/containerd v1.7.2 h1:UF2gdONnxO8I6byZXDi5sXWiWvlW3D/sci7dTQimEJo= -github.com/containerd/containerd v1.7.2/go.mod h1:afcz74+K10M/+cjGHIVQrCt3RAQhUSCAjJ9iMYhhkuI= -github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= -github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= +github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= +github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= +github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= +github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= -github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X51MTk3ycuNI= -github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= -github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v24.0.4+incompatible h1:s/LVDftw9hjblvqIeTiGYXBCD95nOEEl7qRsRrIOuQI= -github.com/docker/docker v24.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= -github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v27.3.1+incompatible h1:KttF0XoteNTicmUtBO0L2tP+J7FGRFTjaEF4k6WdhfI= +github.com/docker/docker v27.3.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/eapache/go-resiliency v1.3.0 h1:RRL0nge+cWGlxXbUzJ7yMcq6w2XBEr19dCN6HECGaT0= -github.com/eapache/go-resiliency v1.3.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= -github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 h1:8yY/I9ndfrgrXUbOGObLHKBR4Fl3nZXwM2c7OYTT8hM= -github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= +github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA= +github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -60,8 +69,6 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9 github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= -github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= @@ -70,150 +77,177 @@ github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVET github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o= github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= -github.com/jcmturner/gokrb5/v8 v8.4.3 h1:iTonLeSJOn7MVUtyMT+arAn5AKAPrkilzhGw8wE/Tq8= -github.com/jcmturner/gokrb5/v8 v8.4.3/go.mod h1:dqRwJGXznQrzw6cWmyo6kH+E7jksEQG/CyVWsJEsJO0= github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8= github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0= +github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= -github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= -github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= -github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= +github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU= +github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko= +github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo= +github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs= +github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g= +github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= -github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0= -github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= -github.com/opencontainers/runc v1.1.7 h1:y2EZDS8sNng4Ksf0GUYNhKbTShZJPJg1FiXJNH/uoCk= -github.com/opencontainers/runc v1.1.7/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50= -github.com/opencontainers/runc v1.1.8 h1:zICRlc+C1XzivLc3nzE+cbJV4LIi8tib6YG0MqC6OqA= -github.com/opencontainers/runc v1.1.8/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50= -github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc= -github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= -github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ= -github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= +github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= +github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= -github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI= +github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= -github.com/testcontainers/testcontainers-go v0.21.0 h1:syePAxdeTzfkap+RrJaQZpJQ/s/fsUgn11xIvHrOE9U= -github.com/testcontainers/testcontainers-go v0.21.0/go.mod h1:c1ez3WVRHq7T/Aj+X3TIipFBwkBaNT5iNCY8+1b83Ng= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/testcontainers/testcontainers-go v0.34.0 h1:5fbgF0vIN5u+nD3IWabQwRybuB4GY8G2HHgCkbMzMHo= +github.com/testcontainers/testcontainers-go v0.34.0/go.mod h1:6P/kMkQe8yqPHfPWNulFGdFHTD8HB2vLq/231xY2iPQ= +github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= +github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= +github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo= +github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS604NSRyI= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= +go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= +go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.0.0-20220725212005-46097bf591d3/go.mod h1:AaygXjzTFtRAg2ttMY5RMuhpJ3cNnI0XpyFJD1iQRSM= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= +golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= -golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753 h1:XUODHrpzJEUeWmVo/jfNTLj0YyVveOo28oE6vkFbkO4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI= -google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= -gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= diff --git a/kafkadocker/kafka_server_jaas.conf b/kafkadocker/kafka_server_jaas.conf new file mode 100644 index 0000000..b51a05c --- /dev/null +++ b/kafkadocker/kafka_server_jaas.conf @@ -0,0 +1,8 @@ +KafkaServer { + org.apache.kafka.common.security.plain.PlainLoginModule required + username="admin" + password="admin-secret" + user_admin="admin-secret" + user_user1="user1-secret" + user_user2="user2-secret"; +}; \ No newline at end of file diff --git a/otel/Makefile b/otel/Makefile index adb4f05..6d4ea52 100644 --- a/otel/Makefile +++ b/otel/Makefile @@ -5,7 +5,7 @@ test: lint: golangci-lint run --fix -c=../.golangci.yml start-collector: - docker-compose -f ./test/docker-compose.yaml up + docker compose -f ./test/docker-compose.yaml up validate-config: docker run --volume=./test/collector-config.yaml:/etc/otel/config.yaml otel/opentelemetry-collector-contrib validate --config=/etc/otel/config.yaml create-sample-traces: diff --git a/otel/test/collector-config.yaml b/otel/test/collector-config.yaml index 3b1b254..0767f74 100644 --- a/otel/test/collector-config.yaml +++ b/otel/test/collector-config.yaml @@ -10,10 +10,6 @@ connectors: exporters: debug: verbosity: detailed - datadog/exporter: - api: - key: 5dcf1369da55b2afea413a9c3dd30403 - site: "datadoghq.eu" processors: batch: @@ -30,7 +26,7 @@ service: traces: receivers: [ otlp ] processors: [ batch ] - exporters: [datadog/connector, datadog/exporter, debug] + exporters: [datadog/connector, debug] metrics: receivers: [datadog/connector, otlp] processors: [batch, resourcedetection] diff --git a/otel/test/integration_test.go b/otel/test/integration_test.go index af3b8b7..87017a1 100644 --- a/otel/test/integration_test.go +++ b/otel/test/integration_test.go @@ -34,6 +34,8 @@ import ( "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/stats" "google.golang.org/grpc/test/bufconn" + "github.com/99designs/gqlgen/graphql" + "github.com/ravilushqa/otelgqlgen" ) func TestTracer(t *testing.T) { @@ -317,6 +319,26 @@ func TestGRPCGraphQLIntegration(t *testing.T) { mux := http.NewServeMux() + s.AroundOperations(func( + ctx context.Context, + next graphql.OperationHandler, + ) graphql.ResponseHandler { + t.Logf("op: %+v", graphql.GetOperationContext(ctx).Operation.Name) + + oc := graphql.GetOperationContext(ctx) + if oc == nil { + t.Log("no operation context") + return next(ctx) + } + + return next(otelgqlgen.SetOperationName(ctx, oc.OperationName)) + }) + + s.Use(otelgqlgen.Middleware(otelgqlgen.WithCreateSpanFromFields( + func(*graphql.FieldContext) bool { + return false + }))) + mux.HandleFunc( "POST /query", s.ServeHTTP, diff --git a/pagination/psql_pagination.go b/pagination/psql_pagination.go index a84e5a4..81e993d 100644 --- a/pagination/psql_pagination.go +++ b/pagination/psql_pagination.go @@ -113,7 +113,10 @@ func (p PSQLPaginator[T]) ListItems( } // nolint: gocognit, gocyclo -func queryItems[T any](ses *gorm.DB, pagination Arguments) ([]T, error) { +func queryItems[T Tabler](ses *gorm.DB, pagination Arguments) ([]T, error) { + var model T + table := model.TableName() + var items []T pagSession := ses.Session(&gorm.Session{}) @@ -122,7 +125,10 @@ func queryItems[T any](ses *gorm.DB, pagination Arguments) ([]T, error) { pagSession = pagSession.Order("created_at DESC") if pagination.afterCursor != nil { - pagSession = pagSession.Where("created_at < ?", pagination.afterCursor.CreatedAt) + pagSession = pagSession.Where( + fmt.Sprintf("%s.created_at < ?", table), + pagination.afterCursor.CreatedAt, + ) } if err := pagSession.Find(&items).Error; err != nil { @@ -132,10 +138,15 @@ func queryItems[T any](ses *gorm.DB, pagination Arguments) ([]T, error) { // First/After if pagination.First != nil { - pagSession = pagSession.Order("created_at DESC").Limit(*pagination.First) + pagSession = pagSession.Order( + fmt.Sprintf("%s.created_at DESC", table), + ).Limit(*pagination.First) if pagination.afterCursor != nil { - pagSession = pagSession.Where("created_at < ?", pagination.afterCursor.CreatedAt) + pagSession = pagSession.Where( + fmt.Sprintf("%s.created_at < ?", table), + pagination.afterCursor.CreatedAt, + ) } if err := pagSession.Find(&items).Error; err != nil { @@ -145,10 +156,15 @@ func queryItems[T any](ses *gorm.DB, pagination Arguments) ([]T, error) { // Last/Before if pagination.Last != nil { - pagSession = pagSession.Order("created_at ASC").Limit(*pagination.Last) + pagSession = pagSession.Order( + fmt.Sprintf("%s.created_at ASC", table), + ).Limit(*pagination.Last) if pagination.beforeCursor != nil { - pagSession = pagSession.Where("created_at > ?", pagination.beforeCursor.CreatedAt) + pagSession = pagSession.Where( + fmt.Sprintf("%s.created_at > ?", table), + pagination.beforeCursor.CreatedAt, + ) } if err := pagSession.Find(&items).Error; err != nil { diff --git a/psqlutil/go.mod b/psqlutil/go.mod index be0f753..84777c2 100644 --- a/psqlutil/go.mod +++ b/psqlutil/go.mod @@ -1,24 +1,28 @@ module github.com/purposeinplay/go-commons/psqlutil -go 1.19 +go 1.21 + +toolchain go1.23.4 require ( github.com/avast/retry-go v3.0.0+incompatible - github.com/jackc/pgx/v5 v5.5.2 - go.uber.org/zap v1.26.0 - gorm.io/driver/postgres v1.5.4 - gorm.io/gorm v1.25.6 + github.com/jackc/pgx/v5 v5.7.2 + github.com/lib/pq v1.10.9 + github.com/purposeinplay/go-commons/errors v0.0.3 + go.uber.org/zap v1.27.0 + gorm.io/driver/postgres v1.5.11 + gorm.io/gorm v1.25.12 moul.io/zapgorm2 v1.3.0 ) require ( github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect - github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/crypto v0.32.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/text v0.21.0 // indirect ) diff --git a/psqlutil/go.sum b/psqlutil/go.sum index 7128c80..9c9aa08 100644 --- a/psqlutil/go.sum +++ b/psqlutil/go.sum @@ -6,12 +6,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.5.2 h1:iLlpgp4Cp/gC9Xuscl7lFL1PhhW+ZLtXZcrfCt4C3tA= -github.com/jackc/pgx/v5 v5.5.2/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= -github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI= +github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= @@ -20,28 +20,34 @@ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/purposeinplay/go-commons/errors v0.0.3 h1:EkjPBqtkFoF8dIZdtF1VfuLawQ0DwHKkwqV9vjhvLb8= +github.com/purposeinplay/go-commons/errors v0.0.3/go.mod h1:jlKOBcStAnDTG1Qx6VtAnHMx9tzc2fvOSPXjpceImGc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= +golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -50,8 +56,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -60,8 +66,8 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -75,10 +81,11 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo= -gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= +gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= gorm.io/gorm v1.23.6/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= -gorm.io/gorm v1.25.6 h1:V92+vVda1wEISSOMtodHVRcUIOPYa2tgQtyF+DfFx+A= -gorm.io/gorm v1.25.6/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= +gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= moul.io/zapgorm2 v1.3.0 h1:+CzUTMIcnafd0d/BvBce8T4uPn6DQnpIrz64cyixlkk= moul.io/zapgorm2 v1.3.0/go.mod h1:nPVy6U9goFKHR4s+zfSo1xVFaoU7Qgd5DoCdOfzoCqs= diff --git a/psqlutil/gorm_plugin.go b/psqlutil/gorm_plugin.go new file mode 100644 index 0000000..9c7b32a --- /dev/null +++ b/psqlutil/gorm_plugin.go @@ -0,0 +1,81 @@ +package psqlutil + +import ( + "database/sql" + + "github.com/lib/pq" + "github.com/purposeinplay/go-commons/errors" + "gorm.io/gorm" +) + +var _ gorm.ErrorTranslator + +// GORMErrorsPlugin is a plugin for GORM that handles postgres specific errors. +type GORMErrorsPlugin struct{} + +// Name returns the name of the plugin. +func (GORMErrorsPlugin) Name() string { + return "psqlerrors" +} + +// Initialize registers the plugin with the GORM db. +func (p GORMErrorsPlugin) Initialize(db *gorm.DB) (err error) { + cb := db.Callback() + + return errors.Join( + cb.Create().After("gorm:create").Register("errors:after:create", p.handleError), + cb.Query().After("gorm:query").Register("errors:after:select", p.handleError), + cb.Delete().After("gorm:delete").Register("errors:after:delete", p.handleError), + cb.Update().After("gorm:update").Register("errors:after:update", p.handleError), + cb.Row().After("gorm:row").Register("errors:after:row", p.handleError), + cb.Raw().After("gorm:raw").Register("errors:after:raw", p.handleError), + ) +} + +func (GORMErrorsPlugin) handleError(tx *gorm.DB) { + err := tx.Error + + if err == nil { + return + } + + const ( + errCodeUniqueViolation = pq.ErrorCode("23505") + errCodeInvalidInput = pq.ErrorCode("22P02") + ) + + switch { + case errors.Is(err, gorm.ErrRecordNotFound), errors.Is(err, sql.ErrNoRows): + tx.Error = &errors.Error{ + Type: errors.ErrorTypeNotFound, + Details: "record not found", + } + case isErrorCode(err, errCodeInvalidInput): + tx.Error = &errors.Error{ + Type: errors.ErrorTypeInvalid, + Details: "invalid input", + } + case isErrorCode(err, errCodeUniqueViolation): + tx.Error = &errors.Error{ + Type: errors.ErrorTypeInvalid, + Details: "object already exists", + } + default: + tx.Error = &errors.Error{ + Type: errors.ErrorTypeInternalError, + Details: tx.Error.Error(), + } + } +} + +// isErrorCode a specific postgres specific error as defined by +// https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html +func isErrorCode(err error, errCode pq.ErrorCode) bool { + var pqErr *pq.Error + + if errors.As(err, &pqErr) { + return pqErr.Code == errCode + } + + return false +} diff --git a/psqlutil/psql_open.go b/psqlutil/psql_open.go index e3d0f88..d1a72e3 100644 --- a/psqlutil/psql_open.go +++ b/psqlutil/psql_open.go @@ -53,6 +53,10 @@ func GormOpen( return nil, fmt.Errorf("open db: %w", err) } + if err := db.Use(GORMErrorsPlugin{}); err != nil { + return nil, fmt.Errorf("use gorm errors plugin: %w", err) + } + return db, nil } diff --git a/pubsub/go.mod b/pubsub/go.mod index 0d51297..3760109 100644 --- a/pubsub/go.mod +++ b/pubsub/go.mod @@ -1,14 +1,14 @@ module github.com/purposeinplay/go-commons/pubsub -go 1.21 +go 1.22 -toolchain go1.21.2 +toolchain go1.23.2 require ( - github.com/IBM/sarama v1.43.2 + github.com/IBM/sarama v1.43.3 github.com/Shopify/sarama v1.38.1 - github.com/ThreeDotsLabs/watermill v1.3.5 - github.com/ThreeDotsLabs/watermill-kafka/v2 v2.5.0 + github.com/ThreeDotsLabs/watermill v1.4.0 + github.com/ThreeDotsLabs/watermill-kafka/v3 v3.0.5 github.com/google/uuid v1.6.0 github.com/matryer/is v1.4.1 github.com/xdg-go/scram v1.1.2 @@ -18,7 +18,8 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/eapache/go-resiliency v1.6.0 // indirect + github.com/dnwe/otelsarama v0.0.0-20240308230250-9388d9d40bc0 // indirect + github.com/eapache/go-resiliency v1.7.0 // indirect github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect github.com/eapache/queue v1.1.0 // indirect github.com/go-logr/logr v1.4.2 // indirect @@ -32,7 +33,7 @@ require ( github.com/jcmturner/gofork v1.7.6 // indirect github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect - github.com/klauspost/compress v1.17.8 // indirect + github.com/klauspost/compress v1.17.11 // indirect github.com/lithammer/shortuuid/v3 v3.0.7 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/pierrec/lz4/v4 v4.1.21 // indirect @@ -40,12 +41,11 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect - go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama v0.43.0 // indirect - go.opentelemetry.io/otel v1.27.0 // indirect - go.opentelemetry.io/otel/metric v1.27.0 // indirect - go.opentelemetry.io/otel/trace v1.27.0 // indirect + go.opentelemetry.io/otel v1.31.0 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect + go.opentelemetry.io/otel/trace v1.31.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/crypto v0.28.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/text v0.19.0 // indirect ) diff --git a/pubsub/go.sum b/pubsub/go.sum index 9e63a77..ba5d7a2 100644 --- a/pubsub/go.sum +++ b/pubsub/go.sum @@ -1,18 +1,20 @@ -github.com/IBM/sarama v1.43.2 h1:HABeEqRUh32z8yzY2hGB/j8mHSzC/HA9zlEjqFNCzSw= -github.com/IBM/sarama v1.43.2/go.mod h1:Kyo4WkF24Z+1nz7xeVUFWIuKVV8RS3wM8mkvPKMdXFQ= +github.com/IBM/sarama v1.43.3 h1:Yj6L2IaNvb2mRBop39N7mmJAHBVY3dTPncr3qGVkxPA= +github.com/IBM/sarama v1.43.3/go.mod h1:FVIRaLrhK3Cla/9FfRF5X9Zua2KpS3SYIXxhac1H+FQ= github.com/Shopify/sarama v1.38.1 h1:lqqPUPQZ7zPqYlWpTh+LQ9bhYNu2xJL6k1SJN4WVe2A= github.com/Shopify/sarama v1.38.1/go.mod h1:iwv9a67Ha8VNa+TifujYoWGxWnu2kNVAQdSdZ4X2o5g= github.com/Shopify/toxiproxy/v2 v2.5.0 h1:i4LPT+qrSlKNtQf5QliVjdP08GyAH8+BUIc9gT0eahc= github.com/Shopify/toxiproxy/v2 v2.5.0/go.mod h1:yhM2epWtAmel9CB8r2+L+PCmhH6yH2pITaPAo7jxJl0= -github.com/ThreeDotsLabs/watermill v1.3.5 h1:50JEPEhMGZQMh08ct0tfO1PsgMOAOhV3zxK2WofkbXg= -github.com/ThreeDotsLabs/watermill v1.3.5/go.mod h1:O/u/Ptyrk5MPTxSeWM5vzTtZcZfxXfO9PK9eXTYiFZY= -github.com/ThreeDotsLabs/watermill-kafka/v2 v2.5.0 h1:/KYEjLlLx6nW3jn6AEcwAlWkPWP62zi/sUsEP4uKkZE= -github.com/ThreeDotsLabs/watermill-kafka/v2 v2.5.0/go.mod h1:w+9jhI7x5ZP67ceSUIIpkgLzjAakotfHX4sWyqsKVjs= +github.com/ThreeDotsLabs/watermill v1.4.0 h1:c8T4QHY/MuxSXYQ1Cxn93cCZB5lkGgqhYA6L2jh2ghA= +github.com/ThreeDotsLabs/watermill v1.4.0/go.mod h1:lBnrLbxOjeMRgcJbv+UiZr8Ylz8RkJ4m6i/VN/Nk+to= +github.com/ThreeDotsLabs/watermill-kafka/v3 v3.0.5 h1:ud+4txnRgtr3kZXfXZ5+C7kVQEvsLc5HSNUEa0g+X1Q= +github.com/ThreeDotsLabs/watermill-kafka/v3 v3.0.5/go.mod h1:t4o+4A6GB+XC8WL3DandhzPwd265zQuyWMQC/I+WIOU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/eapache/go-resiliency v1.6.0 h1:CqGDTLtpwuWKn6Nj3uNUdflaq+/kIPsg0gfNzHton30= -github.com/eapache/go-resiliency v1.6.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= +github.com/dnwe/otelsarama v0.0.0-20240308230250-9388d9d40bc0 h1:R2zQhFwSCyyd7L43igYjDrH0wkC/i+QBPELuY0HOu84= +github.com/dnwe/otelsarama v0.0.0-20240308230250-9388d9d40bc0/go.mod h1:2MqLKYJfjs3UriXXF9Fd0Qmh/lhxi/6tHXkqtXxyIHc= +github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA= +github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws= github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= @@ -53,8 +55,8 @@ github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh6 github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= -github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= -github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/lithammer/shortuuid/v3 v3.0.7 h1:trX0KTHy4Pbwo/6ia8fscyHoGA+mf1jWbPJVuvyJQQ8= github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ= @@ -85,14 +87,12 @@ github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3k github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama v0.43.0 h1:/RxdhdIi0HrKSzdWHLjureinjnGL5YQEYevaC/EAg1k= -go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama v0.43.0/go.mod h1:BKzh9a9EE+vHuq99EwD2cEa+T+Ts1fQ6W3ovO80mjkY= -go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= -go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= -go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= -go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= -go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= -go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -104,8 +104,8 @@ go.uber.org/zap/exp v0.2.0/go.mod h1:t0gqAIdh1MfKv9EwN/dLwfZnJxe9ITAZN78HEWPFWDQ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -113,12 +113,12 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -133,8 +133,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/pubsub/kafka/kafka_init.go b/pubsub/kafka/kafka_init.go index 0c2b0c1..ac11573 100644 --- a/pubsub/kafka/kafka_init.go +++ b/pubsub/kafka/kafka_init.go @@ -4,7 +4,7 @@ import ( "log" "os" - "github.com/Shopify/sarama" + "github.com/IBM/sarama" ) func init() { diff --git a/pubsub/kafka/kafka_publisher.go b/pubsub/kafka/kafka_publisher.go index 266bc5b..e513717 100644 --- a/pubsub/kafka/kafka_publisher.go +++ b/pubsub/kafka/kafka_publisher.go @@ -3,8 +3,8 @@ package kafka import ( "fmt" - "github.com/Shopify/sarama" - "github.com/ThreeDotsLabs/watermill-kafka/v2/pkg/kafka" + "github.com/IBM/sarama" + "github.com/ThreeDotsLabs/watermill-kafka/v3/pkg/kafka" "github.com/ThreeDotsLabs/watermill/message" "github.com/google/uuid" "github.com/purposeinplay/go-commons/pubsub" diff --git a/pubsub/kafka/kafka_sasl.go b/pubsub/kafka/kafka_sasl.go index b08ce97..ed22833 100644 --- a/pubsub/kafka/kafka_sasl.go +++ b/pubsub/kafka/kafka_sasl.go @@ -1,14 +1,25 @@ package kafka import ( - "crypto/tls" "fmt" - "github.com/Shopify/sarama" - "github.com/ThreeDotsLabs/watermill-kafka/v2/pkg/kafka" + "github.com/IBM/sarama" + "github.com/ThreeDotsLabs/watermill-kafka/v3/pkg/kafka" "github.com/xdg-go/scram" + "crypto/tls" ) +// NewSASLPlainSubscriberConfig creates a new kafka +// subscriber config with Plain SASL authentication. +func NewSASLPlainSubscriberConfig(username, password string) *sarama.Config { + return saslPlainConfig(kafka.DefaultSaramaSubscriberConfig(), username, password) +} + +// NewSASLPlainPublisherConfig creates a new kafka publisher config with Plain SASL authentication. +func NewSASLPlainPublisherConfig(username, password string) *sarama.Config { + return saslPlainConfig(kafka.DefaultSaramaSyncPublisherConfig(), username, password) +} + // NewSASLSubscriberConfig creates a new kafka subscriber config with SASL authentication. func NewSASLSubscriberConfig(username, password string) *sarama.Config { return saslConfig(kafka.DefaultSaramaSubscriberConfig(), username, password) @@ -19,6 +30,20 @@ func NewSASLPublisherConfig(username, password string) *sarama.Config { return saslConfig(kafka.DefaultSaramaSyncPublisherConfig(), username, password) } +// saslConfig configures the sarama config for SASL authentication. +func saslPlainConfig(cfg *sarama.Config, username, password string) *sarama.Config { + cfg.Version = sarama.V3_6_0_0 + + cfg.Net.SASL.Enable = true + cfg.Net.SASL.Handshake = true + cfg.Net.SASL.Mechanism = sarama.SASLTypePlaintext + cfg.Net.SASL.User = username + cfg.Net.SASL.Version = sarama.SASLHandshakeV1 + cfg.Net.SASL.Password = password + + return cfg +} + // saslConfig configures the sarama config for SASL authentication. func saslConfig(cfg *sarama.Config, username, password string) *sarama.Config { cfg.Net.TLS.Enable = true @@ -27,11 +52,12 @@ func saslConfig(cfg *sarama.Config, username, password string) *sarama.Config { MinVersion: tls.VersionTLS12, } - cfg.Version = sarama.V3_3_1_0 + cfg.Version = sarama.V3_6_0_0 cfg.Net.SASL.Enable = true cfg.Net.SASL.Handshake = true cfg.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512 + cfg.Net.SASL.Mechanism = sarama.SASLTypePlaintext cfg.Net.SASL.User = username cfg.Net.SASL.Version = sarama.SASLHandshakeV1 cfg.Net.SASL.Password = password diff --git a/pubsub/kafka/kafka_subscriber.go b/pubsub/kafka/kafka_subscriber.go index d75ee72..0a360e5 100644 --- a/pubsub/kafka/kafka_subscriber.go +++ b/pubsub/kafka/kafka_subscriber.go @@ -5,8 +5,8 @@ import ( "fmt" "log/slog" - "github.com/Shopify/sarama" - "github.com/ThreeDotsLabs/watermill-kafka/v2/pkg/kafka" + "github.com/IBM/sarama" + "github.com/ThreeDotsLabs/watermill-kafka/v3/pkg/kafka" "github.com/ThreeDotsLabs/watermill/message" "github.com/purposeinplay/go-commons/pubsub" "go.uber.org/zap" diff --git a/pubsub/kafka/kafka_test.go b/pubsub/kafka/kafka_test.go index d48e681..85d9895 100644 --- a/pubsub/kafka/kafka_test.go +++ b/pubsub/kafka/kafka_test.go @@ -23,7 +23,7 @@ func TestPubSub(t *testing.T) { username = os.Getenv("KAFKA_USERNAME") password = os.Getenv("KAFKA_PASSWORD") brokerURL = os.Getenv("KAFKA_BROKER_URL") - topic = username + ".test" + topic = os.Getenv("KAFKA_TEST_TOPIC") ) suber1, err := kafka.NewSubscriber( diff --git a/pubsub/kafkasarama/kafka_sasl.go b/pubsub/kafkasarama/kafka_sasl.go index a572be2..b327dcb 100644 --- a/pubsub/kafkasarama/kafka_sasl.go +++ b/pubsub/kafkasarama/kafka_sasl.go @@ -3,29 +3,44 @@ package kafkasarama import ( "crypto/tls" "fmt" - "time" - "github.com/IBM/sarama" "github.com/xdg-go/scram" + "github.com/ThreeDotsLabs/watermill-kafka/v3/pkg/kafka" ) +// NewSASLPlainSubscriberConfig creates a new kafka +// subscriber config with Plain SASL authentication. +func NewSASLPlainSubscriberConfig(username, password string) *sarama.Config { + return saslPlainConfig(kafka.DefaultSaramaSubscriberConfig(), username, password) +} + +// NewSASLPlainPublisherConfig creates a new kafka publisher config with Plain SASL authentication. +func NewSASLPlainPublisherConfig(username, password string) *sarama.Config { + return saslPlainConfig(kafka.DefaultSaramaSyncPublisherConfig(), username, password) +} + // NewSASLSubscriberConfig creates a new kafka subscriber config with SASL authentication. func NewSASLSubscriberConfig(username, password string) *sarama.Config { - cfg := sarama.NewConfig() - cfg.Consumer.Return.Errors = true - - return saslConfig(cfg, username, password) + return saslConfig(kafka.DefaultSaramaSubscriberConfig(), username, password) } // NewSASLPublisherConfig creates a new kafka publisher config with SASL authentication. func NewSASLPublisherConfig(username, password string) *sarama.Config { - cfg := sarama.NewConfig() + return saslConfig(kafka.DefaultSaramaSyncPublisherConfig(), username, password) +} - cfg.Producer.Retry.Max = 10 - cfg.Producer.Return.Successes = true - cfg.Metadata.Retry.Backoff = time.Second * 2 +// saslConfig configures the sarama config for SASL authentication. +func saslPlainConfig(cfg *sarama.Config, username, password string) *sarama.Config { + cfg.Version = sarama.V3_6_0_0 - return saslConfig(cfg, username, password) + cfg.Net.SASL.Enable = true + cfg.Net.SASL.Handshake = true + cfg.Net.SASL.Mechanism = sarama.SASLTypePlaintext + cfg.Net.SASL.User = username + cfg.Net.SASL.Version = sarama.SASLHandshakeV1 + cfg.Net.SASL.Password = password + + return cfg } // saslConfig configures the sarama config for SASL authentication. diff --git a/pubsub/kafkasarama/kafkasarama_subscriber.go b/pubsub/kafkasarama/kafkasarama_subscriber.go index 4dfa6c8..6fde5f8 100644 --- a/pubsub/kafkasarama/kafkasarama_subscriber.go +++ b/pubsub/kafkasarama/kafkasarama_subscriber.go @@ -51,10 +51,6 @@ func (s Subscriber) Subscribe(channels ...string) (pubsub.Subscription[string, [ return nil, pubsub.ErrExactlyOneChannelAllowed } - if _, err := sarama.NewConsumerGroup(s.brokers, s.consumerGroup, s.cfg); err != nil { - return nil, fmt.Errorf("new sarama consumer group: %w", err) - } - consumer, err := sarama.NewConsumer(s.brokers, s.cfg) if err != nil { return nil, fmt.Errorf("new sarama consumer: %w", err) diff --git a/pubsub/kafkasarama/kafkasarama_test.go b/pubsub/kafkasarama/kafkasarama_test.go index 2c9a385..479518b 100644 --- a/pubsub/kafkasarama/kafkasarama_test.go +++ b/pubsub/kafkasarama/kafkasarama_test.go @@ -27,12 +27,12 @@ func TestPubSub(t *testing.T) { username = os.Getenv("KAFKA_USERNAME") password = os.Getenv("KAFKA_PASSWORD") brokerURL = os.Getenv("KAFKA_BROKER_URL") - topic = username + ".test" + topic = os.Getenv("KAFKA_TEST_TOPIC") ) suber1, err := kafkasarama.NewSubscriber( slogHandler, - kafkasarama.NewSASLSubscriberConfig( + kafkasarama.NewSASLPlainSubscriberConfig( username, password, ), @@ -43,7 +43,7 @@ func TestPubSub(t *testing.T) { pub, err := kafkasarama.NewPublisher( slogHandler, - kafkasarama.NewSASLPublisherConfig( + kafkasarama.NewSASLPlainPublisherConfig( username, password, ), @@ -80,10 +80,29 @@ func TestPubSub(t *testing.T) { go func() { defer wg.Done() - receivedMes := <-sub1.C() - is.Equal(receivedMes, mes) + timeout := time.After(3 * time.Second) + + var count int + + loop: + for { + select { + case receivedMes := <-sub1.C(): + if count > 0 { + t.Errorf("more than one message received: %+v", mes) + return + } - t.Logf("sub1 received the message in %s", time.Since(now)) + t.Logf("sub1 received the message: %+v in %s", mes, time.Since(now)) + + is.Equal(receivedMes, mes) + + count++ + + case <-timeout: + break loop + } + } }() go func() {