From 1f59f18abd87bf5b1d4db8422660be03091d77b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Fri, 18 Oct 2024 13:50:35 -0300 Subject: [PATCH] certificates: sort by router and cname --- tsuru/client/certificate.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tsuru/client/certificate.go b/tsuru/client/certificate.go index 653bd6c4..9b70755b 100644 --- a/tsuru/client/certificate.go +++ b/tsuru/client/certificate.go @@ -16,6 +16,7 @@ import ( "net/http" "net/url" "os" + "sort" "strings" "time" @@ -228,14 +229,17 @@ 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), @@ -243,6 +247,18 @@ func (c *CertificateList) Run(context *cmd.Context) error { }) } } + + 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