Skip to content

Commit

Permalink
feat(cli,api) nodes on both namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
helderbetiol committed Jun 14, 2024
1 parent 5bc34be commit 23b798b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
9 changes: 5 additions & 4 deletions API/controllers/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,6 @@ func HandleGenericObjects(w http.ResponseWriter, r *http.Request) {
// Save entity to help delete and respond
for _, obj := range entData {
obj["entity"] = entStr
if entStr == "device" && req["attributes.virtual_config.clusterId"] != nil {
// add namespace prefix to nodes
obj["id"] = "Physical." + obj["id"].(string)
}
}

if nLimit, e := strconv.Atoi(filters.Limit); e == nil && nLimit > 0 && req["id"] != nil {
Expand Down Expand Up @@ -668,6 +664,7 @@ func HandleComplexFilters(w http.ResponseWriter, r *http.Request) {
u.ErrLog(ErrDecodingBodyMsg, "HANDLE COMPLEX FILTERS", "", r)
return
}
println(complexFilterExp)

// Get objects
filters := getFiltersFromQueryParams(r)
Expand All @@ -686,6 +683,10 @@ func HandleComplexFilters(w http.ResponseWriter, r *http.Request) {
// Save entity to help delete and respond
for _, obj := range entData {
obj["entity"] = entStr
if entStr == "device" && strings.Contains(complexFilterExp, "virtual_config.type=node") {
// add namespace prefix to device nodes
obj["id"] = "Physical." + obj["id"].(string)
}
}

matchingObjects = append(matchingObjects, entData...)
Expand Down
23 changes: 9 additions & 14 deletions CLI/controllers/commandController.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ func (controller Controller) ObjectUrlGeneric(pathStr string, depth int, filters

isNodeLayerInVirtualPath := false
if path.Layer != nil {
path.Layer.ApplyFilters(filters)
if path.Prefix == models.VirtualObjsPath && path.Layer.Name() == "#nodes" {
isNodeLayerInVirtualPath = true
} else {
path.Layer.ApplyFilters(filters)
filters["filter"] = strings.Replace(filters["filter"], "category=virtual_obj",
"virtual_config.clusterId="+path.ObjectID[:len(path.ObjectID)-2], 1)
}
}

Expand Down Expand Up @@ -152,10 +153,7 @@ func (controller Controller) ObjectUrlGeneric(pathStr string, depth int, filters
params.Add("namespace", "organisational")
params.Add("id", path.ObjectID)
case models.VirtualObjsPath:
if isNodeLayerInVirtualPath {
params.Add("category", "device")
params.Set("virtual_config.clusterId", path.ObjectID[:len(path.ObjectID)-2])
} else {
if !isNodeLayerInVirtualPath {
params.Add("category", "virtual_obj")
if path.ObjectID != "Logical."+models.VirtualObjsNode+".*" {
params.Add("id", path.ObjectID)
Expand All @@ -169,14 +167,11 @@ func (controller Controller) ObjectUrlGeneric(pathStr string, depth int, filters
}

endpoint := "/api/objects"

if !isNodeLayerInVirtualPath {
for key, value := range filters {
if key != "filter" {
params.Set(key, value)
} else {
endpoint = "/api/objects/search"
}
for key, value := range filters {
if key != "filter" {
params.Set(key, value)
} else {
endpoint = "/api/objects/search"
}
}

Expand Down

0 comments on commit 23b798b

Please sign in to comment.