netbird/management/server.go
andpar83 7b52049333
Improve addition of new peers in Management service. (#56)
* Store refactoring
* Improve addition of new peers in Management service.
2021-07-18 20:51:09 +02:00

41 lines
1.0 KiB
Go

package management
import (
"context"
"github.com/wiretrustee/wiretrustee/management/proto"
"google.golang.org/grpc/status"
)
// Server an instance of a Management server
type Server struct {
Store *FileStore
}
// NewServer creates a new Management server
func NewServer(dataDir string) (*Server, error) {
store, err := NewStore(dataDir)
if err != nil {
return nil, err
}
return &Server{
Store: store,
}, nil
}
// RegisterPeer adds a peer to the Store. Returns 404 in case the provided setup key doesn't exist
func (s *Server) RegisterPeer(ctx context.Context, req *proto.RegisterPeerRequest) (*proto.RegisterPeerResponse, error) {
err := s.Store.AddPeer(req.SetupKey, req.Key)
if err != nil {
return &proto.RegisterPeerResponse{}, status.Errorf(404, "provided setup key doesn't exists")
}
return &proto.RegisterPeerResponse{}, nil
}
// IsHealthy indicates whether the service is healthy
func (s *Server) IsHealthy(ctx context.Context, req *proto.Empty) (*proto.Empty, error) {
return &proto.Empty{}, nil
}