From 87e4a33ae239487723249e7297dd8e523e6ee659 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Tue, 13 Feb 2024 15:33:42 +0530 Subject: [PATCH] chore: added review comments --- query/components.go | 1 + query/resource_selector.go | 13 +++---------- types/resource_selector.go | 3 --- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/query/components.go b/query/components.go index 0b6f024b..f6ba823f 100644 --- a/query/components.go +++ b/query/components.go @@ -12,6 +12,7 @@ var ( "owner", "topology_type", "topology_id", + "parent_id", "type", // Deprecated. Use resource_selector.types instead } ) diff --git a/query/resource_selector.go b/query/resource_selector.go index 7d8f25bf..a9650a53 100644 --- a/query/resource_selector.go +++ b/query/resource_selector.go @@ -12,6 +12,7 @@ import ( "github.com/flanksource/duty/types" "github.com/google/uuid" "github.com/patrickmn/go-cache" + "github.com/samber/lo" ) // queryResourceSelector runs the given resourceSelector and returns the resource ids @@ -64,14 +65,6 @@ func queryResourceSelector(ctx context.Context, resourceSelector types.ResourceS query = query.Where("agent_id = ?", agent.ID) } - if resourceSelector.ParentID != "" { - if resourceSelector.ParentID == "nil" { - query = query.Where("parent_id IS NULL") - } else { - query = query.Where("parent_id = ?", resourceSelector.ParentID) - } - } - if len(resourceSelector.LabelSelector) > 0 { labels := collections.SelectorToMap(resourceSelector.LabelSelector) var onlyKeys []string @@ -90,11 +83,11 @@ func queryResourceSelector(ctx context.Context, resourceSelector types.ResourceS if len(resourceSelector.FieldSelector) > 0 { fields := collections.SelectorToMap(resourceSelector.FieldSelector) - columnWhereClauses := map[string]string{} + columnWhereClauses := map[string]any{} var props models.Properties for k, v := range fields { if collections.Contains(allowedColumnsAsFields, k) { - columnWhereClauses[k] = v + columnWhereClauses[k] = lo.Ternary[any](v == "nil", nil, v) } else { props = append(props, &models.Property{Name: k, Text: v}) } diff --git a/types/resource_selector.go b/types/resource_selector.go index b84a8a4b..9071e61d 100644 --- a/types/resource_selector.go +++ b/types/resource_selector.go @@ -18,9 +18,6 @@ type ResourceSelector struct { // Additionally, the special "self" value can be used to select resources without an agent. Agent string `yaml:"agent,omitempty" json:"agent,omitempty"` - // Set this to "nil" to query it as NULL or give a uuid - ParentID string `yaml:"parent_id,omitempty" json:"parent_id,omitempty"` - // Cache directives // 'no-cache' (should not fetch from cache but can be cached) // 'no-store' (should not cache)