From 86e869bae2bc43f331357956da3998b3cf5974be Mon Sep 17 00:00:00 2001
From: Malte Bauch <malte.bauch@stud.h-da.de>
Date: Thu, 19 Oct 2023 10:07:29 +0000
Subject: [PATCH] Resolve "The key for more complex paths in the map containing
 information of update events should be improved"

See merge request danet/gosdn!576
---
 controller/nucleus/networkElementWatcher.go | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/controller/nucleus/networkElementWatcher.go b/controller/nucleus/networkElementWatcher.go
index 672574d90..2da100471 100644
--- a/controller/nucleus/networkElementWatcher.go
+++ b/controller/nucleus/networkElementWatcher.go
@@ -4,7 +4,6 @@ import (
 	"context"
 	"fmt"
 	"strconv"
-	"strings"
 
 	"code.fbi.h-da.de/danet/gosdn/controller/customerrs"
 	"code.fbi.h-da.de/danet/gosdn/controller/event"
@@ -15,6 +14,7 @@ import (
 	"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
 	"github.com/google/uuid"
 	gpb "github.com/openconfig/gnmi/proto/gnmi"
+	"github.com/openconfig/ygot/ygot"
 	log "github.com/sirupsen/logrus"
 )
 
@@ -184,13 +184,9 @@ func (n *NetworkElementWatcher) handleSubscribeResponseUpdate(resp *gpb.Subscrib
 	pathsAndValues := make(map[string]string, len(resp.Update.Update))
 
 	for _, update := range resp.Update.Update {
-		pathString := ""
-
-		// go through elem to build full path
-		for _, elem := range update.Path.Elem {
-			// remove unwanted parts of path string example: "name:\"system\"" -> "system"
-			filteredElem := elem.String()[strings.Index(elem.String(), ":\"")+2 : len(elem.String())-1]
-			pathString += filteredElem + "/"
+		pathString, err := ygot.PathToString(update.Path)
+		if err != nil {
+			log.Errorf("Error trying to create a string from path: %v", err)
 		}
 
 		pathsAndValues[pathString] = update.Val.GetStringVal()
-- 
GitLab