Browse Source

rando logs

afeiszli 4 years ago
parent
commit
f1cac641dc
4 changed files with 21 additions and 10 deletions
  1. 4 6
      controllers/nodeGrpcController.go
  2. 15 4
      database/database.go
  3. 1 0
      functions/helpers.go
  4. 1 0
      models/node.go

+ 4 - 6
controllers/nodeGrpcController.go

@@ -3,7 +3,7 @@ package controller
 import (
 	"context"
 	"fmt"
-
+	"log"
 	"github.com/gravitl/netmaker/functions"
 	nodepb "github.com/gravitl/netmaker/grpc"
 	"github.com/gravitl/netmaker/models"
@@ -170,6 +170,7 @@ func (s *NodeServiceServer) CheckIn(ctx context.Context, req *nodepb.CheckInReq)
 		PersistentKeepalive: data.GetKeepalive(),
 		PublicKey:           data.GetPublickey(),
 		UDPHolePunch:        data.GetUdpholepunch(),
+		SaveConfig:        data.GetSaveconfig(),
 	}
 
 	checkinresponse, err := NodeCheckIn(node, node.Network)
@@ -201,6 +202,7 @@ func (s *NodeServiceServer) CheckIn(ctx context.Context, req *nodepb.CheckInReq)
 func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNodeReq) (*nodepb.UpdateNodeRes, error) {
 	// Get the node data from the request
 	data := req.GetNode()
+	log.Println("DATA:",data)
 	// Now we have to convert this into a NodeItem type to convert into BSON
 	newnode := models.Node{
 		// ID:       primitive.NilObjectID,
@@ -228,11 +230,7 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
 	networkName := newnode.Network
 	network, _ := functions.GetParentNetwork(networkName)
 
-	err := newnode.Validate(true)
-	if err != nil {
-		return nil, err
-	}
-
+	log.Println("NODE SAVECONFIG:",newnode.SaveConfig)
 	node, err := functions.GetNodeByMacAddress(networkName, macaddress)
 	if err != nil {
 		return nil, status.Errorf(

+ 15 - 4
database/database.go

@@ -1,6 +1,8 @@
 package database
 
 import (
+	"encoding/json"
+	"errors"
 	"github.com/rqlite/gorqlite"
 )
 
@@ -45,12 +47,21 @@ func createTable(tableName string) error {
 	return nil
 }
 
+func isJSONString(value string) bool {
+	var jsonInt interface{}
+	return json.Unmarshal([]byte(value), &jsonInt) == nil
+}
+
 func Insert(key string, value string, tableName string) error {
-	_, err := Database.WriteOne("INSERT OR REPLACE INTO " + tableName + " (key, value) VALUES ('" + key + "', '" + value + "')")
-	if err != nil {
-		return err
+	if key != "" && value != "" && isJSONString(value) {
+		_, err := Database.WriteOne("INSERT OR REPLACE INTO " + tableName + " (key, value) VALUES ('" + key + "', '" + value + "')")
+		if err != nil {
+			return err
+		}
+		return nil
+	} else {
+		return errors.New("invalid insert " + key + " : " + value)
 	}
-	return nil
 }
 
 func DeleteRecord(tableName string, key string) error {

+ 1 - 0
functions/helpers.go

@@ -473,6 +473,7 @@ func GetNodeByMacAddress(network string, macaddress string) (models.Node, error)
 	}
 
 	record, err := database.FetchRecord(database.NODES_TABLE_NAME, key)
+	log.Println("RECORD:",record)
 	if err != nil {
 		return models.Node{}, err
 	}

+ 1 - 0
models/node.go

@@ -149,6 +149,7 @@ func (node *Node) SetDefaults() {
 }
 
 func (currentNode *Node) Update(newNode *Node) error {
+	log.Println("Node SaveConfig:",newNode.SaveConfig)
 	if err := newNode.Validate(true); err != nil {
 		return err
 	}