add missing auth interceptors
This commit is contained in:
@@ -25,6 +25,7 @@ type Config struct {
|
||||
SubmissionServiceAddr string
|
||||
TaskServiceAddr string
|
||||
CacheEnabled bool
|
||||
AuthSvcAddr string
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
@@ -45,6 +46,7 @@ func Load() (*Config, error) {
|
||||
SubmissionServiceAddr: getEnv("SUBMISSION_GRPC_ADDR", "localhost:50055"),
|
||||
TaskServiceAddr: getEnv("TASK_GRPC_ADDR", "localhost:50056"),
|
||||
CacheEnabled: mustGetBool("CACHE_ENABLED", false),
|
||||
AuthSvcAddr: getEnv("AUTH_GRPC_ADDR", "localhost:50057"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,15 @@ import (
|
||||
grpcHandlers "datarush/internal/results/handler/grpc"
|
||||
"datarush/internal/results/repository/postgres"
|
||||
"datarush/internal/results/service"
|
||||
authpb "datarush/pkg/api/auth"
|
||||
pb "datarush/pkg/api/results"
|
||||
"datarush/pkg/interceptor"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
||||
@@ -32,6 +35,7 @@ type Server struct {
|
||||
config *config.Config
|
||||
db *sqlx.DB
|
||||
redis *redis.Client
|
||||
authConn *grpc.ClientConn
|
||||
}
|
||||
|
||||
func New(cfg *config.Config) *Server {
|
||||
@@ -47,6 +51,12 @@ func (s *Server) Start() error {
|
||||
}
|
||||
s.db = db
|
||||
|
||||
authConn, err := grpc.Dial(s.config.AuthSvcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to auth service: %w", err)
|
||||
}
|
||||
s.authConn = authConn
|
||||
|
||||
redisClient := redis.NewClient(&redis.Options{
|
||||
Addr: s.config.RedisAddr,
|
||||
})
|
||||
@@ -68,7 +78,13 @@ func (s *Server) startGRPCServer() error {
|
||||
return fmt.Errorf("failed to listen on grpc port: %w", err)
|
||||
}
|
||||
|
||||
s.grpcServer = grpc.NewServer()
|
||||
authClient := authpb.NewAuthServiceClient(s.authConn)
|
||||
authInterceptor := interceptor.NewAuthInterceptor(authClient)
|
||||
|
||||
s.grpcServer = grpc.NewServer(
|
||||
grpc.UnaryInterceptor(authInterceptor.Unary()),
|
||||
)
|
||||
|
||||
s.registerGRPCServices()
|
||||
|
||||
log.Printf("starting gRPC server on port %d", s.config.GRPCPort)
|
||||
|
||||
@@ -79,7 +79,6 @@ func (s *Server) registerGRPCServices() error {
|
||||
s.grpcServer = grpc.NewServer(
|
||||
grpc.UnaryInterceptor(authInterceptor.Unary()),
|
||||
)
|
||||
|
||||
taskRepo := taskPostgresRepo.NewTaskRepository(s.db)
|
||||
|
||||
taskService := service.NewTaskService(taskRepo)
|
||||
|
||||
Reference in New Issue
Block a user