Merge pull request #100 from gravitl/bugfix_v0.2_misc

Bugfix v0.2 misc
This commit is contained in:
Alex
2021-04-19 10:07:07 -04:00
committed by GitHub
6 changed files with 247 additions and 105 deletions

View File

@@ -3,6 +3,7 @@ package controller
import (
"context"
"fmt"
"strconv"
nodepb "github.com/gravitl/netmaker/grpc"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/functions"
@@ -20,6 +21,7 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
// convert string id (from proto) to mongoDB ObjectId
macaddress := req.GetMacaddress()
networkName := req.GetNetwork()
network, _ := functions.GetParentNetwork(networkName)
node, err := GetNode(macaddress, networkName)
@@ -50,6 +52,9 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
Publickey: node.PublicKey,
Listenport: node.ListenPort,
Keepalive: node.PersistentKeepalive,
Islocal: *network.IsLocal,
Localrange: network.LocalRange,
},
}
return response, nil
@@ -87,9 +92,18 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
//Check to see if key is valid
//TODO: Triple inefficient!!! This is the third call to the DB we make for networks
validKey := functions.IsKeyValid(node.Network, node.AccessKey)
network, err := functions.GetParentNetwork(node.Network)
if err != nil {
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("Could not find network: %v", err))
} else {
fmt.Println("Creating node in network " + network.NetID)
fmt.Println("Network is local? " + strconv.FormatBool(*network.IsLocal))
fmt.Println("Range if local: " + network.LocalRange)
}
if !validKey {
network, _ := functions.GetParentNetwork(node.Network)
//Check to see if network will allow manual sign up
//may want to switch this up with the valid key check and avoid a DB call that way.
if *network.AllowManualSignUp {
@@ -126,6 +140,8 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
Publickey: node.PublicKey,
Listenport: node.ListenPort,
Keepalive: node.PersistentKeepalive,
Islocal: *network.IsLocal,
Localrange: network.LocalRange,
},
}
err = SetNetworkNodesLastModified(node.Network)
@@ -208,6 +224,8 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
// Convert the Id string to a MongoDB ObjectId
macaddress := nodechange.MacAddress
networkName := nodechange.Network
network, _ := functions.GetParentNetwork(networkName)
err := ValidateNode("update", networkName, nodechange)
if err != nil {
@@ -247,6 +265,8 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
Publickey: newnode.PublicKey,
Listenport: newnode.ListenPort,
Keepalive: newnode.PersistentKeepalive,
Islocal: *network.IsLocal,
Localrange: network.LocalRange,
},
}, nil