remove GetNodeByIDOrMacAddress

This commit is contained in:
afeiszli 2022-02-01 21:50:11 -05:00
parent 0c502baa14
commit c8154ffa5d
7 changed files with 38 additions and 12 deletions

View file

@ -72,7 +72,7 @@ func grpcAuthorize(ctx context.Context) error {
authToken := authHeader[0]
nodeID, mac, network, err := logic.VerifyToken(authToken)
nodeID, _, network, err := logic.VerifyToken(authToken)
if err != nil {
return err
}
@ -82,7 +82,7 @@ func grpcAuthorize(ctx context.Context) error {
if err != nil {
return status.Errorf(codes.Unauthenticated, "Unauthorized. Network does not exist: "+network)
}
node, err := logic.GetNodeByIDorMacAddress(nodeID, mac, network)
node, err := logic.GetNodeByID(nodeID)
if database.IsEmptyRecord(err) {
// == DELETE replace logic after 2 major version updates ==
if node, err = logic.GetDeletedNodeByID(node.ID); err == nil {

View file

@ -221,7 +221,7 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
var extclient models.ExtClient
extclient.Network = networkName
extclient.IngressGatewayID = nodeid
node, err := logic.GetNodeByIDorMacAddress(nodeid, nodeid, networkName)
node, err := logic.GetNodeByID(nodeid)
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return

View file

@ -111,7 +111,7 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.Object)
return nil, err
}
node, err := logic.GetNodeByIDorMacAddress(newnode.ID, newnode.MacAddress, newnode.Network)
node, err := logic.GetNodeByID(newnode.ID)
if err != nil {
return nil, err
}
@ -265,14 +265,14 @@ func getNewOrLegacyNode(data string) (models.Node, error) {
if err = json.Unmarshal([]byte(data), &reqNode); err != nil {
oldID := strings.Split(data, "###") // handle legacy client IDs
if len(oldID) == 2 {
if node, err = logic.GetNodeByIDorMacAddress(reqNode.ID, oldID[0], oldID[1]); err != nil {
if node, err = logic.GetNodeByID(reqNode.ID); err != nil {
return models.Node{}, err
}
} else {
return models.Node{}, err
}
} else {
node, err = logic.GetNodeByIDorMacAddress(reqNode.ID, reqNode.MacAddress, reqNode.Network)
node, err = logic.GetNodeByID(reqNode.ID)
if err != nil {
return models.Node{}, err
}

View file

@ -549,6 +549,7 @@ func GetNodeRelay(network string, relayedNodeAddr string) (models.Node, error) {
}
// GetNodeByIDorMacAddress - gets the node, if a mac address exists, but not id, then it should delete it and recreate in DB with new ID
/*
func GetNodeByIDorMacAddress(uuid string, macaddress string, network string) (models.Node, error) {
var node models.Node
var err error
@ -571,7 +572,7 @@ func GetNodeByIDorMacAddress(uuid string, macaddress string, network string) (mo
}
return node, err
}
*/
// GetNodeByID - get node by uuid, should have been set by create
func GetNodeByID(uuid string) (models.Node, error) {
var record, err = database.FetchRecord(database.NODES_TABLE_NAME, uuid)

View file

@ -165,8 +165,12 @@ func Push(cfg config.ClientConfig) error {
} else {
err = functions.Push(cfg.Network)
}
ncutils.PrintLog("completed pushing network configs to remote server", 1)
ncutils.PrintLog("success", 1)
if err == nil {
ncutils.PrintLog("completed pushing network configs to remote server", 1)
ncutils.PrintLog("success", 1)
} else {
ncutils.PrintLog("error occurred pushing configs", 1)
}
return err
}
@ -193,7 +197,12 @@ func Pull(cfg config.ClientConfig) error {
_, err = functions.Pull(cfg.Network, true)
}
ncutils.PrintLog("reset network and peer configs", 1)
ncutils.PrintLog("success", 1)
if err == nil {
ncutils.PrintLog("reset network and peer configs", 1)
ncutils.PrintLog("success", 1)
} else {
ncutils.PrintLog("error occurred pulling configs from server", 1)
}
return err
}

View file

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"log"
"os"
"runtime"
"strings"
@ -155,7 +156,6 @@ func Pull(network string, manual bool) (*models.Node, error) {
if err != nil {
return nil, err
}
node := cfg.Node
//servercfg := cfg.Server
@ -171,6 +171,9 @@ func Pull(network string, manual bool) (*models.Node, error) {
var ctx context.Context
if cfg.Node.IsServer != "yes" {
log.Println("DELETE ME: server addr - " + cfg.Server.GRPCAddress)
log.Println("DELETE ME: server ssl - " + cfg.Server.GRPCSSL)
conn, err := grpc.Dial(cfg.Server.GRPCAddress,
ncutils.GRPCRequestOpts(cfg.Server.GRPCSSL))
if err != nil {
@ -185,7 +188,9 @@ func Pull(network string, manual bool) (*models.Node, error) {
ncutils.PrintLog("Failed to authenticate: "+err.Error(), 1)
return nil, err
}
log.Println("DELETE ME: node - " + node.Name)
log.Println("DELETE ME: node - " + node.Network)
log.Println("DELETE ME: node - " + node.Address)
data, err := json.Marshal(&node)
if err != nil {
ncutils.PrintLog("Failed to parse node config: "+err.Error(), 1)
@ -197,10 +202,15 @@ func Pull(network string, manual bool) (*models.Node, error) {
Type: nodepb.NODE_TYPE,
}
log.Println("DELETE ME: checkpoint 3")
readres, err := wcclient.ReadNode(ctx, req, grpc.Header(&header))
if err != nil {
return nil, err
}
log.Println("DELETE ME: checkpoint 3.5")
if err = json.Unmarshal([]byte(readres.Data), &resNode); err != nil {
return nil, err
}
@ -225,6 +235,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
if err != nil {
return &resNode, err
}
if resNode.IsServer != "yes" {
if wcclient == nil || ctx == nil {
return &cfg.Node, errors.New("issue initializing gRPC client")

View file

@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"os/signal"
"runtime"
@ -449,7 +450,9 @@ func UpdateKeys(cfg *config.ClientConfig, client mqtt.Client) error {
// Checkin -- go routine that checks for public or local ip changes, publishes changes
// if there are no updates, simply "pings" the server as a checkin
func Checkin(ctx context.Context, cfg *config.ClientConfig, network string) {
log.Println("DELETE ME: starting checkin")
for {
log.Println("DELETE ME: running checkin")
select {
case <-ctx.Done():
ncutils.Log("Checkin cancelled")
@ -489,6 +492,7 @@ func Checkin(ctx context.Context, cfg *config.ClientConfig, network string) {
PublishNodeUpdate(cfg)
}
}
log.Println("DELETE ME: run hell0")
Hello(cfg, network)
// ncutils.Log("Checkin complete")
}
@ -514,6 +518,7 @@ func Hello(cfg *config.ClientConfig, network string) {
if err := publish(cfg, fmt.Sprintf("ping/%s", cfg.Node.ID), []byte("hello world!")); err != nil {
ncutils.Log(fmt.Sprintf("error publishing ping, %v", err))
}
log.Println("DELETE ME: ran hello")
}
func publish(cfg *config.ClientConfig, dest string, msg []byte) error {