Browse Source

added auth stuff

worker-9 4 years ago
parent
commit
324337eac1
2 changed files with 5 additions and 13 deletions
  1. 5 12
      controllers/authGrpc.go
  2. 0 1
      netclient/functions/checkin.go

+ 5 - 12
controllers/authGrpc.go

@@ -69,7 +69,6 @@ func grpcAuthorize(ctx context.Context) error {
 	authToken := authHeader[0]
 
 	mac, network, err := functions.VerifyToken(authToken)
-
 	if err != nil {
 		return err
 	}
@@ -82,28 +81,22 @@ func grpcAuthorize(ctx context.Context) error {
 	emptynode := models.Node{}
 	node, err := functions.GetNodeByMacAddress(network, mac)
 	if database.IsEmptyRecord(err) {
-		if node, err = functions.GetDeletedNodeByMacAddress(network, mac); err != nil {
-			if !database.IsEmptyRecord(err) {
-				if functions.RemoveDeletedNode(node.ID) {
-					return status.Errorf(codes.Unauthenticated, models.NODE_DELETE)
-				}
+		if node, err = functions.GetDeletedNodeByMacAddress(network, mac); err == nil {
+			if functions.RemoveDeletedNode(node.ID) {
+				return status.Errorf(codes.Unauthenticated, models.NODE_DELETE)
 			}
 			return status.Errorf(codes.Unauthenticated, "Node does not exist.")
 		}
+		return status.Errorf(codes.Unauthenticated, "Empty record")
 	}
 	if err != nil || node.MacAddress == emptynode.MacAddress {
 		return status.Errorf(codes.Unauthenticated, "Node does not exist.")
 	}
 
-	//check that the request is for a valid network
-	//if (networkCheck && !networkexists) || err != nil {
 	if !networkexists {
-
 		return status.Errorf(codes.Unauthenticated, "Network does not exist.")
-
-	} else {
-		return nil
 	}
+	return nil
 }
 
 //Node authenticates using its password and retrieves a JWT for authorization.

+ 0 - 1
netclient/functions/checkin.go

@@ -106,7 +106,6 @@ func checkNodeActions(node *models.Node, networkName string, servercfg config.Se
 		err := RemoveLocalInstance(cfg, networkName)
 		if err != nil {
 			log.Println("Error:", err)
-			return ""
 		}
 		return models.NODE_DELETE
 	}