changing validation

This commit is contained in:
afeiszli
2022-02-05 15:16:11 -05:00
parent 7bf864a387
commit dd79186a81
3 changed files with 8 additions and 6 deletions

View File

@@ -563,10 +563,10 @@ func updateNode(w http.ResponseWriter, r *http.Request) {
} }
if servercfg.IsDNSMode() { if servercfg.IsDNSMode() {
err = logic.SetDNS() logic.SetDNS()
} }
logger.Log(1, r.Header.Get("user"), "updated node", node.MacAddress, "on network", node.Network) logger.Log(1, r.Header.Get("user"), "updated node", node.ID, "on network", node.Network)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(newNode) json.NewEncoder(w).Encode(newNode)

View File

@@ -159,7 +159,7 @@ func UpdateNode(currentNode *models.Node, newNode *models.Node) error {
return database.Insert(newNode.ID, string(data), database.NODES_TABLE_NAME) return database.Insert(newNode.ID, string(data), database.NODES_TABLE_NAME)
} }
} }
return fmt.Errorf("failed to update node " + newNode.MacAddress + ", cannot change macaddress.") return fmt.Errorf("failed to update node " + currentNode.ID + ", cannot change ID.")
} }
// IsNodeIDUnique - checks if node id is unique // IsNodeIDUnique - checks if node id is unique
@@ -175,8 +175,10 @@ func ValidateNode(node *models.Node, isUpdate bool) error {
if isUpdate { if isUpdate {
return true return true
} }
unique, _ := isMacAddressUnique(node.MacAddress, node.Network) var unique = true
if !(node.MacAddress == "") {
unique, _ = isMacAddressUnique(node.MacAddress, node.Network)
}
isFieldUnique, _ := IsNodeIDUnique(node) isFieldUnique, _ := IsNodeIDUnique(node)
return isFieldUnique && unique return isFieldUnique && unique
}) })

View File

@@ -21,7 +21,7 @@ import (
// SetJWT func will used to create the JWT while signing in and signing out // SetJWT func will used to create the JWT while signing in and signing out
func SetJWT(client nodepb.NodeServiceClient, network string) (context.Context, error) { func SetJWT(client nodepb.NodeServiceClient, network string) (context.Context, error) {
home := ncutils.GetNetclientPathSpecific() home := ncutils.GetNetclientPathSpecific()
tokentext, err := ncutils.GetFileWithRetry(home+"nettoken-"+network, 1) tokentext, err := os.ReadFile(home + "nettoken-" + network)
if err != nil { if err != nil {
err = AutoLogin(client, network) err = AutoLogin(client, network)
if err != nil { if err != nil {