@@ -6,9 +6,11 @@ import (
6
6
"fmt"
7
7
"io"
8
8
"net/http"
9
+ "sort"
9
10
10
11
"github.com/olekukonko/tablewriter"
11
12
"github.com/sailpoint-oss/sailpoint-cli/internal/client"
13
+ "github.com/sailpoint-oss/sailpoint-cli/internal/util"
12
14
"github.com/spf13/cobra"
13
15
)
14
16
@@ -40,19 +42,74 @@ func newConnListCmd(client client.Client) *cobra.Command {
40
42
return err
41
43
}
42
44
43
- var conns []connector
45
+ var conns []connectorList
44
46
err = json .Unmarshal (raw , & conns )
45
47
if err != nil {
46
48
return err
47
49
}
48
50
51
+ // Sort connectors by Alias
52
+ sort .Slice (conns , func (i , j int ) bool {
53
+ return conns [i ].Alias < conns [j ].Alias
54
+ })
55
+
49
56
table := tablewriter .NewWriter (cmd .OutOrStdout ())
50
- table .SetHeader (connectorColumns )
51
- for _ , v := range conns {
52
- table .Append (v .columns ())
57
+ table .SetHeader (connectorListColumns )
58
+
59
+ // Process each connector and populate the table
60
+ for _ , conn := range conns {
61
+ connectorRef := conn .ID
62
+ if connectorRef == "" {
63
+ continue
64
+ }
65
+
66
+ // Build the tags endpoint using the connectorRef
67
+ tagsEndpoint := util .ResourceUrl (endpoint , connectorRef , "tags" )
68
+ tagsResp , err := client .Get (cmd .Context (), tagsEndpoint )
69
+ if err != nil {
70
+ return err
71
+ }
72
+ defer tagsResp .Body .Close ()
73
+
74
+ if tagsResp .StatusCode != http .StatusOK {
75
+ body , _ := io .ReadAll (tagsResp .Body )
76
+ return fmt .Errorf ("non-200 response: %s\n body: %s" , tagsResp .Status , body )
77
+ }
78
+
79
+ // Process the response for the tags request
80
+ tagsRaw , err := io .ReadAll (tagsResp .Body )
81
+ if err != nil {
82
+ return err
83
+ }
84
+
85
+ var tags []tag
86
+ err = json .Unmarshal (tagsRaw , & tags )
87
+ if err != nil {
88
+ return err
89
+ }
90
+
91
+ // Prepare data for the table
92
+ var tagNames []string
93
+ var versions []string
94
+ for _ , t := range tags {
95
+ tagNames = append (tagNames , t .TagName )
96
+ versions = append (versions , fmt .Sprintf ("%d" , t .ActiveVersion ))
97
+ }
98
+ tagsString := fmt .Sprintf ("%s" , tagNames )
99
+ versionsString := fmt .Sprintf ("%s" , versions )
100
+
101
+ // Add the row to the table
102
+ row := []string {
103
+ conn .ID ,
104
+ conn .Alias ,
105
+ tagsString ,
106
+ versionsString ,
107
+ }
108
+ table .Append (row )
53
109
}
54
- table .Render ()
55
110
111
+ // Render the table
112
+ table .Render ()
56
113
return nil
57
114
},
58
115
}
0 commit comments