setup tasks auth middleware and compose
This commit is contained in:
@@ -20,6 +20,7 @@ type Config struct {
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
AuthSvcAddr string
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
@@ -35,6 +36,7 @@ func Load() (*Config, error) {
|
||||
DBUser: getEnv("POSTGRES_USERNAME", "postgres"),
|
||||
DBPassword: getEnv("POSTGRES_PASSWORD", "postgres"),
|
||||
DBName: getEnv("POSTGRES_DATABASE", "postgres"),
|
||||
AuthSvcAddr: getEnv("AUTH_SVC_ADDR", "localhost:50051"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -71,4 +73,4 @@ func (c Config) BuildPostgresConnStr() string {
|
||||
func (c Config) BuildPostgresDSN() string {
|
||||
return fmt.Sprintf("postgresql://%s:%s@%s/%s?sslmode=disable",
|
||||
c.DBUser, c.DBPassword, net.JoinHostPort(c.DBHost, strconv.Itoa(c.DBPort)), c.DBName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import (
|
||||
grpcHandlers "datarush/internal/task/handler/grpc"
|
||||
taskPostgresRepo "datarush/internal/task/repository/postgres"
|
||||
"datarush/internal/task/service"
|
||||
authpb "datarush/pkg/api/auth"
|
||||
pb "datarush/pkg/api/task"
|
||||
"datarush/pkg/interceptor"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
@@ -28,6 +30,7 @@ type Server struct {
|
||||
grpcServer *grpc.Server
|
||||
config *config.Config
|
||||
db *sqlx.DB
|
||||
authConn *grpc.ClientConn
|
||||
}
|
||||
|
||||
func New(cfg *config.Config) *Server {
|
||||
@@ -63,6 +66,9 @@ func (s *Server) Start() error {
|
||||
}
|
||||
|
||||
func (s *Server) registerGRPCServices() error {
|
||||
authClient := authpb.NewAuthServiceClient(s.authConn)
|
||||
authInterceptor := interceptor.NewAuthInterceptor(authClient)
|
||||
|
||||
s.grpcServer = grpc.NewServer()
|
||||
|
||||
taskRepo := taskPostgresRepo.NewTaskRepository(s.db)
|
||||
@@ -93,4 +99,4 @@ func (s *Server) Stop() {
|
||||
}
|
||||
|
||||
log.Println("task server stopped")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user