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