mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
major overhaul initiated
This commit is contained in:
@@ -73,6 +73,57 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *NodeServiceServer) GetConn(ctx context.Context, data *nodepb.Client) (*nodepb.Client, error) {
|
||||
// Get the protobuf node type from the protobuf request type
|
||||
// Essentially doing req.Node to access the struct with a nil check
|
||||
// Now we have to convert this into a NodeItem type to convert into BSON
|
||||
clientreq := models.ServerClient{
|
||||
// ID: primitive.NilObjectID,
|
||||
Address: data.GetAddress(),
|
||||
Address6: data.GetAddress6(),
|
||||
AccessKey: data.GetAccesskey(),
|
||||
PublicKey: data.GetPublickey(),
|
||||
PrivateKey: data.GetPrivatekey(),
|
||||
ServerPort: data.GetServerport(),
|
||||
ServerKey: data.GetServerkey(),
|
||||
ServerEndpoint: data.GetServerendpoint(),
|
||||
}
|
||||
|
||||
//Check to see if key is valid
|
||||
//TODO: Triple inefficient!!! This is the third call to the DB we make for networks
|
||||
if servercfg.IsRegisterKeyRequired() {
|
||||
validKey := functions.IsKeyValidGlobal(clientreq.AccessKey)
|
||||
if !validKey {
|
||||
return nil, status.Errorf(
|
||||
codes.Internal,
|
||||
fmt.Sprintf("Invalid key, and server does not allow no-key signups"),
|
||||
)
|
||||
}
|
||||
}
|
||||
client, err := RegisterClient(clientreq)
|
||||
|
||||
if err != nil {
|
||||
// return internal gRPC error to be handled later
|
||||
return nil, status.Errorf(
|
||||
codes.Internal,
|
||||
fmt.Sprintf("Internal error: %v", err),
|
||||
)
|
||||
}
|
||||
// return the node in a CreateNodeRes type
|
||||
response := &nodepb.Client{
|
||||
Privatekey: client.PrivateKey,
|
||||
Publickey: client.PublicKey,
|
||||
Accesskey: client.AccessKey,
|
||||
Address: client.Address,
|
||||
Address6: client.Address6,
|
||||
Serverendpoint: client.ServerEndpoint,
|
||||
Serverport: client.ServerPort,
|
||||
Serverkey: client.ServerKey,
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNodeReq) (*nodepb.CreateNodeRes, error) {
|
||||
// Get the protobuf node type from the protobuf request type
|
||||
// Essentially doing req.Node to access the struct with a nil check
|
||||
|
Reference in New Issue
Block a user