From 6fd31915b9a02d5c8cb37c60785993780e561bdc Mon Sep 17 00:00:00 2001 From: timka Date: Wed, 17 Dec 2025 17:58:58 +0300 Subject: [PATCH] add interceptors to task and competition services --- go.sum | 5 ----- internal/task/server/server.go | 4 +++- internal/user/server/server.go | 11 ++++++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/go.sum b/go.sum index b25dc5c..c55eade 100644 --- a/go.sum +++ b/go.sum @@ -138,13 +138,8 @@ 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= -<<<<<<< HEAD -github.com/redis/go-redis/v9 v9.16.0 h1:OotgqgLSRCmzfqChbQyG1PHC3tLNR89DG4jdOERSEP4= -github.com/redis/go-redis/v9 v9.16.0/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370= -======= github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI= github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370= ->>>>>>> origin/feature/task github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/task/server/server.go b/internal/task/server/server.go index b2f94bf..bcce31a 100644 --- a/internal/task/server/server.go +++ b/internal/task/server/server.go @@ -69,7 +69,9 @@ func (s *Server) registerGRPCServices() error { authClient := authpb.NewAuthServiceClient(s.authConn) authInterceptor := interceptor.NewAuthInterceptor(authClient) - s.grpcServer = grpc.NewServer() + s.grpcServer = grpc.NewServer( + grpc.UnaryInterceptor(authInterceptor.Unary()), + ) taskRepo := taskPostgresRepo.NewTaskRepository(s.db) diff --git a/internal/user/server/server.go b/internal/user/server/server.go index c945f7b..1eeb22c 100644 --- a/internal/user/server/server.go +++ b/internal/user/server/server.go @@ -8,10 +8,11 @@ import ( "datarush/internal/user/config" grpcHandlers "datarush/internal/user/handler/grpc" - "datarush/internal/user/middleware" userPostgresRepo "datarush/internal/user/repository/postgres" "datarush/internal/user/service" + authpb "datarush/pkg/api/auth" pb "datarush/pkg/api/user" + "datarush/pkg/interceptor" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" @@ -29,6 +30,7 @@ type Server struct { grpcServer *grpc.Server config *config.Config db *sqlx.DB + authConn *grpc.ClientConn } func New(cfg *config.Config) *Server { @@ -64,8 +66,11 @@ func (s *Server) Start() error { } func (s *Server) registerGRPCServices() error { + authClient := authpb.NewAuthServiceClient(s.authConn) + authInterceptor := interceptor.NewAuthInterceptor(authClient) + s.grpcServer = grpc.NewServer( - grpc.UnaryInterceptor(middleware.AuthInterceptor(s.config.JWTSecret)), + grpc.UnaryInterceptor(authInterceptor.Unary()), ) userRepo := userPostgresRepo.NewUserRepository(s.db) @@ -96,4 +101,4 @@ func (s *Server) Stop() { } log.Println("user server stopped") -} \ No newline at end of file +}