mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-24 16:12:59 +08:00
updating netclient
This commit is contained in:
parent
4a6ebfc108
commit
9fb01f9620
10 changed files with 43 additions and 18 deletions
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"log"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/functions"
|
||||
nodepb "github.com/gravitl/netmaker/grpc"
|
||||
|
@ -81,8 +81,12 @@ func grpcAuthorize(ctx context.Context) error {
|
|||
|
||||
}
|
||||
emptynode := models.Node{}
|
||||
log.Println("node:",mac)
|
||||
log.Println("network:",network)
|
||||
node, err := functions.GetNodeByMacAddress(network, mac)
|
||||
if err != nil || node.MacAddress == emptynode.MacAddress {
|
||||
log.Println(err)
|
||||
log.Println(node.MacAddress,emptynode.MacAddress)
|
||||
return status.Errorf(codes.Unauthenticated, "Node does not exist.")
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ func GetPeersList(networkName string) ([]models.PeersResponse, error) {
|
|||
|
||||
var peers []models.PeersResponse
|
||||
collection, err := database.FetchRecords(database.NODES_TABLE_NAME)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
udppeers, errN := serverctl.GetPeers(networkName)
|
||||
if errN != nil {
|
||||
log.Println(errN)
|
||||
|
@ -175,6 +178,11 @@ func CreateNode(node models.Node, networkName string) (models.Node, error) {
|
|||
//returnErrorResponse(w, r, errorResponse)
|
||||
return node, err
|
||||
}
|
||||
err = node.Validate(false)
|
||||
if err != nil {
|
||||
return node, err
|
||||
}
|
||||
|
||||
key, err := functions.GetRecordKey(node.MacAddress, node.Network)
|
||||
if err != nil {
|
||||
return node, err
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/serverctl"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
|
@ -391,6 +391,14 @@ func createNetwork(w http.ResponseWriter, r *http.Request) {
|
|||
returnErrorResponse(w, r, formatError(err, "badrequest"))
|
||||
return
|
||||
}
|
||||
success, err := serverctl.AddNetwork(network.NetID)
|
||||
if err != nil || !success {
|
||||
if err == nil {
|
||||
err = errors.New("Failed to add server to network " + network.DisplayName)
|
||||
}
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
functions.PrintUserLog(r.Header.Get("user"), "created network "+network.NetID, 1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
//json.NewEncoder(w).Encode(result)
|
||||
|
|
|
@ -89,13 +89,6 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
|
|||
UDPHolePunch: data.GetUdpholepunch(),
|
||||
}
|
||||
|
||||
err := node.Validate(false)
|
||||
|
||||
if err != nil {
|
||||
// return internal gRPC error to be handled later
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//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)
|
||||
|
@ -227,6 +220,7 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
|
|||
PublicKey: data.GetPublickey(),
|
||||
ListenPort: data.GetListenport(),
|
||||
UDPHolePunch: data.GetUdpholepunch(),
|
||||
SaveConfig: data.GetSaveconfig(),
|
||||
}
|
||||
|
||||
// Convert the Id string to a MongoDB ObjectId
|
||||
|
|
|
@ -486,12 +486,6 @@ func createNode(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
err = node.Validate(false)
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "badrequest"))
|
||||
return
|
||||
}
|
||||
|
||||
node, err = CreateNode(node, networkName)
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"log"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
)
|
||||
|
@ -112,6 +112,8 @@ func (node *Node) SetDefaults() {
|
|||
if node.SaveConfig == "" {
|
||||
if parentNetwork.DefaultSaveConfig != "" {
|
||||
node.SaveConfig = parentNetwork.DefaultSaveConfig
|
||||
} else {
|
||||
node.SaveConfig = "yes"
|
||||
}
|
||||
}
|
||||
if node.Interface == "" {
|
||||
|
@ -132,6 +134,9 @@ func (node *Node) SetDefaults() {
|
|||
}
|
||||
if node.UDPHolePunch == "" {
|
||||
node.UDPHolePunch = parentNetwork.DefaultUDPHolePunch
|
||||
if node.UDPHolePunch == "" {
|
||||
node.UDPHolePunch = "yes"
|
||||
}
|
||||
}
|
||||
node.CheckInInterval = parentNetwork.DefaultCheckInInterval
|
||||
|
||||
|
@ -177,6 +182,7 @@ func IsIpv4Net(host string) bool {
|
|||
}
|
||||
|
||||
func (node *Node) Validate(isUpdate bool) error {
|
||||
log.Println("Node SaveConfig:",node.SaveConfig)
|
||||
v := validator.New()
|
||||
_ = v.RegisterValidation("macaddress_unique", func(fl validator.FieldLevel) bool {
|
||||
if isUpdate {
|
||||
|
|
|
@ -72,6 +72,7 @@ type NodeConfig struct {
|
|||
StaticPubKey string `yaml:"staticpubkey"`
|
||||
IPForwarding string `yaml:"ipforwarding"`
|
||||
UDPHolePunch string `yaml:"udpholepunch"`
|
||||
SaveConfig string `yaml:"saveconfig"`
|
||||
}
|
||||
|
||||
//reading in the env file
|
||||
|
@ -357,6 +358,9 @@ func ModConfig(node *nodepb.Node) error {
|
|||
if node.Udpholepunch != "" {
|
||||
nodecfg.UDPHolePunch = node.Udpholepunch
|
||||
}
|
||||
if node.Saveconfig != "" {
|
||||
nodecfg.SaveConfig = node.Saveconfig
|
||||
}
|
||||
if node.Isingressgateway {
|
||||
nodecfg.IsIngressGateway = "yes"
|
||||
} else {
|
||||
|
|
|
@ -169,6 +169,8 @@ func JoinNetwork(cfg config.ClientConfig) error {
|
|||
Publickey: cfg.Node.PublicKey,
|
||||
Name: cfg.Node.Name,
|
||||
Endpoint: cfg.Node.Endpoint,
|
||||
Saveconfig: cfg.Node.SaveConfig,
|
||||
Udpholepunch: cfg.Node.UDPHolePunch,
|
||||
}
|
||||
err = config.ModConfig(postnode)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/credentials"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"context"
|
||||
|
@ -45,6 +46,8 @@ func GetNode(network string) nodepb.Node {
|
|||
node.Macaddress = nodecfg.MacAddress
|
||||
node.Endpoint = nodecfg.Endpoint
|
||||
node.Password = nodecfg.Password
|
||||
node.Saveconfig = nodecfg.SaveConfig
|
||||
node.Udpholepunch = nodecfg.UDPHolePunch
|
||||
if nodecfg.DNS == "on" {
|
||||
node.Dnsoff = false
|
||||
} else {
|
||||
|
@ -60,6 +63,8 @@ func GetNode(network string) nodepb.Node {
|
|||
} else {
|
||||
node.Isingressgateway = false
|
||||
}
|
||||
fmt.Println("GetNode:")
|
||||
spew.Dump(node)
|
||||
return node
|
||||
}
|
||||
|
||||
|
|
|
@ -15,4 +15,4 @@ EOF
|
|||
|
||||
POST_JSON=$(generate_post_json)
|
||||
|
||||
curl --max-time 5.0 -d "$POST_JSON" -H 'Content-Type: application/json' -H "authorization: Bearer secretkey" localhost:8082/api/networks
|
||||
curl --max-time 5.0 -d "$POST_JSON" -H 'Content-Type: application/json' -H "authorization: Bearer secretkey" localhost:8081/api/networks
|
||||
|
|
Loading…
Reference in a new issue