@@ -22,6 +22,7 @@ type TopologyOptions struct {
22
22
AgentID string
23
23
Flatten bool
24
24
Depth int
25
+ Team string
25
26
// TODO: Filter status and types in DB Query
26
27
Types []string
27
28
Status []string
@@ -62,6 +63,14 @@ func (opt TopologyOptions) componentRelationWhereClause() string {
62
63
return s
63
64
}
64
65
66
+ func (opt TopologyOptions ) teamWhereClause () string {
67
+ if opt .Team != "" {
68
+ return "AND @team = ANY(team_names)"
69
+ }
70
+
71
+ return ""
72
+ }
73
+
65
74
func generateQuery (opts TopologyOptions ) (string , map [string ]any ) {
66
75
selectSubQuery := `
67
76
SELECT id FROM components %s
@@ -74,7 +83,7 @@ func generateQuery(opts TopologyOptions) (string, map[string]any) {
74
83
query := fmt .Sprintf (`
75
84
WITH topology_result AS (
76
85
SELECT * FROM topology
77
- WHERE id IN (%s)
86
+ WHERE id IN (%s) %s
78
87
)
79
88
SELECT
80
89
json_build_object(
@@ -92,7 +101,7 @@ func generateQuery(opts TopologyOptions) (string, map[string]any) {
92
101
)
93
102
FROM
94
103
topology_result
95
- ` , subQuery )
104
+ ` , subQuery , opts . teamWhereClause () )
96
105
97
106
args := make (map [string ]any )
98
107
if opts .ID != "" {
@@ -108,6 +117,9 @@ func generateQuery(opts TopologyOptions) (string, map[string]any) {
108
117
if opts .Labels != nil {
109
118
args ["labels" ] = opts .Labels
110
119
}
120
+ if opts .Team != "" {
121
+ args ["team" ] = opts .Team
122
+ }
111
123
112
124
return query , args
113
125
}
@@ -131,6 +143,7 @@ func QueryTopology(ctx context.Context, dbpool *pgxpool.Pool, params TopologyOpt
131
143
ctx , cancel = context .WithTimeout (ctx , DefaultQueryTimeout )
132
144
defer cancel ()
133
145
}
146
+
134
147
rows , err := dbpool .Query (ctx , query , pgx .NamedArgs (args ))
135
148
if err != nil {
136
149
return nil , err
0 commit comments