add auth
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
orderPostgresRepo "datarush/internal/lms/repository/postgres"
|
||||
"datarush/internal/lms/service"
|
||||
|
||||
authPb "datarush/pkg/api/auth"
|
||||
pb "datarush/pkg/api/order"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
@@ -72,6 +73,12 @@ func runHTTPHandler(s *Server, grpcServerEndpoint *string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Register auth service
|
||||
if err := registerAuthService(ctx, gwmux, s.config.AuthGRPCAddr, opts); err != nil {
|
||||
log.Printf("failed to register auth service: %v", err)
|
||||
// Don't fail completely if auth service is not available
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/healthz", httpHandlers.NewHealthHandler(s.db, s.redisDB))
|
||||
mux.Handle("/", gwmux)
|
||||
@@ -87,6 +94,19 @@ func runHTTPHandler(s *Server, grpcServerEndpoint *string) error {
|
||||
return srv.ListenAndServe()
|
||||
}
|
||||
|
||||
func registerAuthService(ctx context.Context, gwmux *runtime.ServeMux, authAddr string, opts []grpc.DialOption) error {
|
||||
if err := authPb.RegisterAuthServiceHandlerFromEndpoint(ctx, gwmux, authAddr, opts); err != nil {
|
||||
return fmt.Errorf("register auth service handler: %w", err)
|
||||
}
|
||||
log.Printf("registered auth service from %s", authAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerAuthHandlerFromEndpoint(ctx context.Context, gwmux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error {
|
||||
// We'll import the proto and register it here
|
||||
// For now, this is a placeholder that will be called from gateway integration
|
||||
return nil
|
||||
|
||||
func getDatabase(cfg config.Config) (*sqlx.DB, error) {
|
||||
db, err := sqlx.Connect("postgres", cfg.BuildPostgresConnStr())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user