mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 01:07:41 +08:00
rando logs
This commit is contained in:
@@ -3,7 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"github.com/gravitl/netmaker/functions"
|
"github.com/gravitl/netmaker/functions"
|
||||||
nodepb "github.com/gravitl/netmaker/grpc"
|
nodepb "github.com/gravitl/netmaker/grpc"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
@@ -170,6 +170,7 @@ func (s *NodeServiceServer) CheckIn(ctx context.Context, req *nodepb.CheckInReq)
|
|||||||
PersistentKeepalive: data.GetKeepalive(),
|
PersistentKeepalive: data.GetKeepalive(),
|
||||||
PublicKey: data.GetPublickey(),
|
PublicKey: data.GetPublickey(),
|
||||||
UDPHolePunch: data.GetUdpholepunch(),
|
UDPHolePunch: data.GetUdpholepunch(),
|
||||||
|
SaveConfig: data.GetSaveconfig(),
|
||||||
}
|
}
|
||||||
|
|
||||||
checkinresponse, err := NodeCheckIn(node, node.Network)
|
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) {
|
func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNodeReq) (*nodepb.UpdateNodeRes, error) {
|
||||||
// Get the node data from the request
|
// Get the node data from the request
|
||||||
data := req.GetNode()
|
data := req.GetNode()
|
||||||
|
log.Println("DATA:",data)
|
||||||
// Now we have to convert this into a NodeItem type to convert into BSON
|
// Now we have to convert this into a NodeItem type to convert into BSON
|
||||||
newnode := models.Node{
|
newnode := models.Node{
|
||||||
// ID: primitive.NilObjectID,
|
// ID: primitive.NilObjectID,
|
||||||
@@ -228,11 +230,7 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
|
|||||||
networkName := newnode.Network
|
networkName := newnode.Network
|
||||||
network, _ := functions.GetParentNetwork(networkName)
|
network, _ := functions.GetParentNetwork(networkName)
|
||||||
|
|
||||||
err := newnode.Validate(true)
|
log.Println("NODE SAVECONFIG:",newnode.SaveConfig)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
node, err := functions.GetNodeByMacAddress(networkName, macaddress)
|
node, err := functions.GetNodeByMacAddress(networkName, macaddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(
|
return nil, status.Errorf(
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"github.com/rqlite/gorqlite"
|
"github.com/rqlite/gorqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,12 +47,21 @@ func createTable(tableName string) error {
|
|||||||
return nil
|
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 {
|
func Insert(key string, value string, tableName string) error {
|
||||||
_, err := Database.WriteOne("INSERT OR REPLACE INTO " + tableName + " (key, value) VALUES ('" + key + "', '" + value + "')")
|
if key != "" && value != "" && isJSONString(value) {
|
||||||
if err != nil {
|
_, err := Database.WriteOne("INSERT OR REPLACE INTO " + tableName + " (key, value) VALUES ('" + key + "', '" + value + "')")
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return errors.New("invalid insert " + key + " : " + value)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteRecord(tableName string, key string) error {
|
func DeleteRecord(tableName string, key string) error {
|
||||||
|
@@ -473,6 +473,7 @@ func GetNodeByMacAddress(network string, macaddress string) (models.Node, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
record, err := database.FetchRecord(database.NODES_TABLE_NAME, key)
|
record, err := database.FetchRecord(database.NODES_TABLE_NAME, key)
|
||||||
|
log.Println("RECORD:",record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Node{}, err
|
return models.Node{}, err
|
||||||
}
|
}
|
||||||
|
@@ -149,6 +149,7 @@ func (node *Node) SetDefaults() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (currentNode *Node) Update(newNode *Node) error {
|
func (currentNode *Node) Update(newNode *Node) error {
|
||||||
|
log.Println("Node SaveConfig:",newNode.SaveConfig)
|
||||||
if err := newNode.Validate(true); err != nil {
|
if err := newNode.Validate(true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user