Skip to content

Commit

Permalink
Add node addresses to cert list command
Browse files Browse the repository at this point in the history
  • Loading branch information
marc committed May 24, 2017
1 parent b55542e commit 310b08e
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions pkg/cli/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cli
import (
"fmt"
"os"
"strings"
"time"

"github.com/cockroachdb/cockroach/pkg/security"
Expand Down Expand Up @@ -170,10 +171,10 @@ func runListCerts(cmd *cobra.Command, args []string) error {

fmt.Fprintf(os.Stdout, "Certificate directory: %s\n", baseCfg.SSLCertsDir)

certTableHeaders := []string{"Usage", "Certificate File", "Key File", "Notes", "Expires", "Error"}
certTableHeaders := []string{"Usage", "Certificate File", "Key File", "Expires", "Notes", "Error"}
var rows [][]string

addRow := func(ci *security.CertInfo, name string) {
addRow := func(ci *security.CertInfo, notes string) {
var errString string
if ci.Error != nil {
errString = ci.Error.Error()
Expand All @@ -182,22 +183,39 @@ func runListCerts(cmd *cobra.Command, args []string) error {
ci.FileUsage.String(),
ci.Filename,
ci.KeyFilename,
name,
ci.ExpirationTime.Format("2006/01/02"),
notes,
errString,
})
}

if ca := cm.CACert(); ca != nil {
addRow(ca, "")
if cert := cm.CACert(); cert != nil {
addRow(cert, "")
}

if node := cm.NodeCert(); node != nil {
addRow(node, "")
if cert := cm.NodeCert(); cert != nil {
var addresses []string
if cert.Error == nil && len(cert.ParsedCertificates) > 0 {
addresses = cert.ParsedCertificates[0].DNSNames
for _, ip := range cert.ParsedCertificates[0].IPAddresses {
addresses = append(addresses, ip.String())
}
} else {
addresses = append(addresses, "<unknown>")
}

addRow(cert, fmt.Sprintf("addresses: %s", strings.Join(addresses, ",")))
}

for name, cert := range cm.ClientCerts() {
addRow(cert, fmt.Sprintf("user=%s", name))
for _, cert := range cm.ClientCerts() {
var user string
if cert.Error == nil && len(cert.ParsedCertificates) > 0 {
user = cert.ParsedCertificates[0].Subject.CommonName
} else {
user = "unknown"
}

addRow(cert, fmt.Sprintf("user: %s", user))
}

return printQueryOutput(os.Stdout, certTableHeaders, newRowSliceIter(rows), "", cliCtx.tableDisplayFormat)
Expand Down

0 comments on commit 310b08e

Please sign in to comment.