@@ -22,6 +22,7 @@ type TopologyOptions struct {
2222 AgentID string
2323 Flatten bool
2424 Depth int
25+ Team string
2526 // TODO: Filter status and types in DB Query
2627 Types []string
2728 Status []string
@@ -62,6 +63,14 @@ func (opt TopologyOptions) componentRelationWhereClause() string {
6263 return s
6364}
6465
66+ func (opt TopologyOptions ) teamWhereClause () string {
67+ if opt .Team != "" {
68+ return "AND @team = ANY(team_names)"
69+ }
70+
71+ return ""
72+ }
73+
6574func generateQuery (opts TopologyOptions ) (string , map [string ]any ) {
6675 selectSubQuery := `
6776 SELECT id FROM components %s
@@ -74,7 +83,7 @@ func generateQuery(opts TopologyOptions) (string, map[string]any) {
7483 query := fmt .Sprintf (`
7584 WITH topology_result AS (
7685 SELECT * FROM topology
77- WHERE id IN (%s)
86+ WHERE id IN (%s) %s
7887 )
7988 SELECT
8089 json_build_object(
@@ -92,7 +101,7 @@ func generateQuery(opts TopologyOptions) (string, map[string]any) {
92101 )
93102 FROM
94103 topology_result
95- ` , subQuery )
104+ ` , subQuery , opts . teamWhereClause () )
96105
97106 args := make (map [string ]any )
98107 if opts .ID != "" {
@@ -108,6 +117,9 @@ func generateQuery(opts TopologyOptions) (string, map[string]any) {
108117 if opts .Labels != nil {
109118 args ["labels" ] = opts .Labels
110119 }
120+ if opts .Team != "" {
121+ args ["team" ] = opts .Team
122+ }
111123
112124 return query , args
113125}
@@ -131,6 +143,7 @@ func QueryTopology(ctx context.Context, dbpool *pgxpool.Pool, params TopologyOpt
131143 ctx , cancel = context .WithTimeout (ctx , DefaultQueryTimeout )
132144 defer cancel ()
133145 }
146+
134147 rows , err := dbpool .Query (ctx , query , pgx .NamedArgs (args ))
135148 if err != nil {
136149 return nil , err
0 commit comments