mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-20 01:06:45 +00:00
connect proxy grpc server to database
This commit is contained in:
@@ -150,7 +150,7 @@ func (s *BaseServer) GRPCServer() *grpc.Server {
|
|||||||
}
|
}
|
||||||
mgmtProto.RegisterManagementServiceServer(gRPCAPIHandler, srv)
|
mgmtProto.RegisterManagementServiceServer(gRPCAPIHandler, srv)
|
||||||
|
|
||||||
proxyService := nbgrpc.NewProxyServiceServer()
|
proxyService := nbgrpc.NewProxyServiceServer(s.Store())
|
||||||
mgmtProto.RegisterProxyServiceServer(gRPCAPIHandler, proxyService)
|
mgmtProto.RegisterProxyServiceServer(gRPCAPIHandler, proxyService)
|
||||||
log.Info("ProxyService registered on gRPC server")
|
log.Info("ProxyService registered on gRPC server")
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ import (
|
|||||||
"google.golang.org/grpc/status"
|
"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
|
// ProxyServiceServer implements the ProxyService gRPC server
|
||||||
type ProxyServiceServer struct {
|
type ProxyServiceServer struct {
|
||||||
proto.UnimplementedProxyServiceServer
|
proto.UnimplementedProxyServiceServer
|
||||||
@@ -23,6 +27,9 @@ type ProxyServiceServer struct {
|
|||||||
|
|
||||||
// Channel for broadcasting service updates to all proxies
|
// Channel for broadcasting service updates to all proxies
|
||||||
updatesChan chan *proto.ProxyMapping
|
updatesChan chan *proto.ProxyMapping
|
||||||
|
|
||||||
|
// Store of services
|
||||||
|
serviceStore serviceStore
|
||||||
}
|
}
|
||||||
|
|
||||||
// proxyConnection represents a connected proxy
|
// proxyConnection represents a connected proxy
|
||||||
@@ -36,9 +43,10 @@ type proxyConnection struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewProxyServiceServer creates a new proxy service server
|
// NewProxyServiceServer creates a new proxy service server
|
||||||
func NewProxyServiceServer() *ProxyServiceServer {
|
func NewProxyServiceServer(store serviceStore) *ProxyServiceServer {
|
||||||
return &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
|
// sendSnapshot sends the initial snapshot of all services to proxy
|
||||||
func (s *ProxyServiceServer) sendSnapshot(ctx context.Context, conn *proxyConnection) error {
|
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 {
|
if err != nil {
|
||||||
// TODO: something
|
// TODO: something
|
||||||
return fmt.Errorf("get account services from store: %w", err)
|
return fmt.Errorf("get account services from store: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user