Skip to content

Commit

Permalink
chore: added review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Feb 13, 2024
1 parent a3e4ba6 commit b7f2433
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
1 change: 1 addition & 0 deletions query/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
"owner",
"topology_type",
"topology_id",
"parent_id",
"type", // Deprecated. Use resource_selector.types instead
}
)
Expand Down
13 changes: 3 additions & 10 deletions query/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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})
}
Expand Down
3 changes: 0 additions & 3 deletions types/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b7f2433

Please sign in to comment.