Skip to content

Commit

Permalink
certificates: sort by router and cname
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Oct 18, 2024
1 parent 30283f5 commit 1f59f18
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tsuru/client/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"net/http"
"net/url"
"os"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -228,21 +229,36 @@ func (c *CertificateList) Run(context *cmd.Context) error {
tbl := tablecli.NewTable()
tbl.LineSeparator = true
tbl.Headers = tablecli.Row{"Router", "CName", "Public Key Info", "Certificate Validity"}

rows := []tablecli.Row{}

for router, routerCerts := range appCerts.RouterCertificates {
for cname, cnameCert := range routerCerts.CNameCertificates {
cert, err := parseCert([]byte(cnameCert.Certificate))
if err != nil {
tbl.AddRow(tablecli.Row{router, cname, err.Error(), "-"})
rows = append(rows, tablecli.Row{router, cname, err.Error(), "-"})
continue
}
tbl.AddRow(tablecli.Row{
rows = append(rows, tablecli.Row{
router,
formatCName(cname, cnameCert.Issuer),
formatPublicKeyInfo(*cert),
formatCertificateValidity(*cert),
})
}
}

sort.Slice(rows, func(i, j int) bool {
if rows[i][0] == rows[j][0] {
return rows[i][1] < rows[j][1]
}
return rows[i][0] < rows[j][0]
})

for _, row := range rows {
tbl.AddRow(row)
}

tbl.Sort()
fmt.Fprint(context.Stdout, tbl.String())
return nil
Expand Down

0 comments on commit 1f59f18

Please sign in to comment.