Skip to content

Commit 8fc2147

Browse files
update sail conn list command to show tags and versions and sort the table by Alias name
1 parent 2635d12 commit 8fc2147

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

cmd/connector/conn_list.go

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9+
"sort"
910

1011
"github.com/olekukonko/tablewriter"
1112
"github.com/sailpoint-oss/sailpoint-cli/internal/client"
13+
"github.com/sailpoint-oss/sailpoint-cli/internal/util"
1214
"github.com/spf13/cobra"
1315
)
1416

@@ -40,19 +42,74 @@ func newConnListCmd(client client.Client) *cobra.Command {
4042
return err
4143
}
4244

43-
var conns []connector
45+
var conns []connectorList
4446
err = json.Unmarshal(raw, &conns)
4547
if err != nil {
4648
return err
4749
}
4850

51+
// Sort connectors by Alias
52+
sort.Slice(conns, func(i, j int) bool {
53+
return conns[i].Alias < conns[j].Alias
54+
})
55+
4956
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\nbody: %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)
53109
}
54-
table.Render()
55110

111+
// Render the table
112+
table.Render()
56113
return nil
57114
},
58115
}

cmd/connector/models.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ func (c connector) columns() []string {
1717

1818
var connectorColumns = []string{"ID", "Alias"}
1919

20+
type connectorList struct {
21+
ID string `json:"id"`
22+
Alias string `json:"alias"`
23+
TagName string `json:"tagName"`
24+
ActiveVersion uint32 `json:"activeVersion"`
25+
}
26+
27+
func (c connectorList) columns() []string {
28+
return []string{c.ID, c.Alias, c.TagName, fmt.Sprint(c.ActiveVersion)}
29+
}
30+
31+
var connectorListColumns = []string{"ID", "Alias", "Tags", "Version"}
32+
2033
type connectorVersion struct {
2134
ConnectorID string `json:"connectorId"`
2235
Version int `json:"version"`

0 commit comments

Comments
 (0)