diff --git a/management/internals/server/boot.go b/management/internals/server/boot.go index 9f89512ff..64a161ed5 100644 --- a/management/internals/server/boot.go +++ b/management/internals/server/boot.go @@ -150,7 +150,7 @@ func (s *BaseServer) GRPCServer() *grpc.Server { } mgmtProto.RegisterManagementServiceServer(gRPCAPIHandler, srv) - proxyService := nbgrpc.NewProxyServiceServer() + proxyService := nbgrpc.NewProxyServiceServer(s.Store()) mgmtProto.RegisterProxyServiceServer(gRPCAPIHandler, proxyService) log.Info("ProxyService registered on gRPC server") diff --git a/management/internals/shared/grpc/proxy.go b/management/internals/shared/grpc/proxy.go index a22d1c48a..d982e3d6e 100644 --- a/management/internals/shared/grpc/proxy.go +++ b/management/internals/shared/grpc/proxy.go @@ -14,6 +14,10 @@ import ( "google.golang.org/grpc/status" ) +type serviceStore interface { + GetAccountServices(ctx context.Context, lockStrength store.LockingStrength, accountID string) ([]*services.Service, error) +} + // ProxyServiceServer implements the ProxyService gRPC server type ProxyServiceServer struct { proto.UnimplementedProxyServiceServer @@ -23,6 +27,9 @@ type ProxyServiceServer struct { // Channel for broadcasting service updates to all proxies updatesChan chan *proto.ProxyMapping + + // Store of services + serviceStore serviceStore } // proxyConnection represents a connected proxy @@ -36,9 +43,10 @@ type proxyConnection struct { } // NewProxyServiceServer creates a new proxy service server -func NewProxyServiceServer() *ProxyServiceServer { +func NewProxyServiceServer(store serviceStore) *ProxyServiceServer { return &ProxyServiceServer{ - updatesChan: make(chan *proto.ProxyMapping, 100), + updatesChan: make(chan *proto.ProxyMapping, 100), + serviceStore: store, } } @@ -93,35 +101,9 @@ func (s *ProxyServiceServer) GetMappingUpdate(req *proto.GetMappingUpdateRequest } } -type serviceStore interface { - GetAccountServices(ctx context.Context, lockStrength store.LockingStrength, accountID string) ([]*services.Service, error) -} - -// stubstore implements a serviceStore using stubbed out data rather than a real database connection. -type stubstore struct{} - -func (stubstore) GetAccountServices(_ context.Context, _ store.LockingStrength, _ string) ([]*services.Service, error) { - return []*services.Service{ - { - ID: "test", - Domain: "test.netbird.io", - Targets: []services.Target{ - { - Enabled: true, - Path: "/", - Host: "100.116.118.156:8181", - }, - }, - Enabled: true, - Exposed: true, - AuthBearerEnabled: true, - }, - }, nil -} - // sendSnapshot sends the initial snapshot of all services to proxy func (s *ProxyServiceServer) sendSnapshot(ctx context.Context, conn *proxyConnection) error { - svcs, err := stubstore{}.GetAccountServices(ctx, store.LockingStrengthNone, conn.proxyID) // TODO: check locking strength and accountID. Use an actual database connection here! + svcs, err := s.serviceStore.GetAccountServices(ctx, store.LockingStrengthNone, conn.proxyID) // TODO: check locking strength and accountID. if err != nil { // TODO: something return fmt.Errorf("get account services from store: %w", err)