Skip to content

Commit 2839e24

Browse files
Merge pull request #157 from sailpoint-oss/devrel-1759
update sail conn list command to show tags and versions and sort the …
2 parents 2635d12 + dfd77b4 commit 2839e24

File tree

5 files changed

+88
-10
lines changed

5 files changed

+88
-10
lines changed

cmd/connector/conn_list.go

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9+
"sort"
10+
"strings"
911

1012
"github.com/olekukonko/tablewriter"
1113
"github.com/sailpoint-oss/sailpoint-cli/internal/client"
14+
"github.com/sailpoint-oss/sailpoint-cli/internal/util"
1215
"github.com/spf13/cobra"
1316
)
1417

@@ -40,19 +43,75 @@ func newConnListCmd(client client.Client) *cobra.Command {
4043
return err
4144
}
4245

43-
var conns []connector
46+
var conns []connectorList
4447
err = json.Unmarshal(raw, &conns)
4548
if err != nil {
4649
return err
4750
}
4851

52+
// Sort connectors by Alias
53+
sort.Slice(conns, func(i, j int) bool {
54+
return conns[i].Alias < conns[j].Alias
55+
})
56+
4957
table := tablewriter.NewWriter(cmd.OutOrStdout())
50-
table.SetHeader(connectorColumns)
51-
for _, v := range conns {
52-
table.Append(v.columns())
58+
table.SetHeader(connectorListColumns)
59+
60+
// Process each connector and populate the table
61+
for _, conn := range conns {
62+
connectorRef := conn.ID
63+
if connectorRef == "" {
64+
continue
65+
}
66+
67+
// Build the tags endpoint using the connectorRef
68+
tagsEndpoint := util.ResourceUrl(endpoint, connectorRef, "tags")
69+
tagsResp, err := client.Get(cmd.Context(), tagsEndpoint)
70+
if err != nil {
71+
return err
72+
}
73+
defer tagsResp.Body.Close()
74+
75+
if tagsResp.StatusCode != http.StatusOK {
76+
body, _ := io.ReadAll(tagsResp.Body)
77+
return fmt.Errorf("non-200 response: %s\nbody: %s", tagsResp.Status, body)
78+
}
79+
80+
// Process the response for the tags request
81+
tagsRaw, err := io.ReadAll(tagsResp.Body)
82+
if err != nil {
83+
return err
84+
}
85+
86+
var tags []tag
87+
err = json.Unmarshal(tagsRaw, &tags)
88+
if err != nil {
89+
return err
90+
}
91+
92+
// Prepare data for the table
93+
var tagNames []string
94+
var versions []string
95+
for _, t := range tags {
96+
tagNames = append(tagNames, t.TagName)
97+
versions = append(versions, fmt.Sprintf("%d", t.ActiveVersion))
98+
}
99+
// Format the tags and versions as comma-separated lists
100+
tagsString := strings.Join(tagNames, ", ")
101+
versionsString := strings.Join(versions, ", ")
102+
103+
// Add the row to the table
104+
row := []string{
105+
conn.ID,
106+
conn.Alias,
107+
tagsString,
108+
versionsString,
109+
}
110+
table.Append(row)
53111
}
54-
table.Render()
55112

113+
// Render the table
114+
table.Render()
56115
return nil
57116
},
58117
}

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"`

cmd/connector/static/connector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"prettier": "^2.3.2",
2525
"shx": "^0.3.3",
2626
"ts-jest": "^27.0.5",
27-
"typescript": "4.9.3",
27+
"typescript": "^4.9.5",
2828
"cross-env": "7.0.3"
2929
},
3030
"jest": {

cmd/connector/static/connector/src/index.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ describe('connector unit tests', () => {
1616
it('should execute stdTestConnectionHandler', async () => {
1717
await (await connector())._exec(
1818
StandardCommand.StdTestConnection,
19-
{},
19+
{reloadConfig() {
20+
return Promise.resolve()
21+
},},
2022
undefined,
2123
new PassThrough({ objectMode: true }).on('data', (chunk) => expect(chunk).toStrictEqual(new RawResponse ({}, ResponseType.Output)))
2224
)

cmd/connector/static/customizer/src/index.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ describe('connector customizer unit tests', () => {
1515
}
1616
let updatedInput = await customizer._exec(
1717
customizer.handlerKey(CustomizerType.Before, StandardCommand.StdAccountRead),
18-
{},
18+
{reloadConfig() {
19+
return Promise.resolve()
20+
},},
1921
input
2022
)
2123

@@ -26,7 +28,9 @@ describe('connector customizer unit tests', () => {
2628
let customizer = await connectorCustomizer()
2729
let output = await customizer._exec(
2830
customizer.handlerKey(CustomizerType.After, StandardCommand.StdAccountRead),
29-
{},
31+
{reloadConfig() {
32+
return Promise.resolve()
33+
},},
3034
{
3135
identity: '',
3236
attributes: {
@@ -40,4 +44,4 @@ describe('connector customizer unit tests', () => {
4044

4145
expect(output.attributes.location).toStrictEqual('Austin')
4246
})
43-
})
47+
})

0 commit comments

Comments
 (0)