Skip to content

Commit

Permalink
22 add dnsnames emailaddresses ipaddresses uris to x509 output (#23)
Browse files Browse the repository at this point in the history
* refactor: Improve flags description.

* feat: Add DNSNames, EmailAddresses, IPAddresses, URIs to x509 output.
  • Loading branch information
lukasz-lobocki authored Jul 27, 2024
1 parent 7fde1a7 commit df1c5d8
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 33 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ step-badger x509Certs PATH [flags]
```text
Flags:
-e, --emit {t|j|m|o} emit format: table|json|markdown|openssl (default t)
-t, --time {i|s} time shown: iso|short (default i)
-t, --time {i|s} time format: iso|short (default i)
-s, --sort {s|f} sort order: start|finish (default f)
-c, --crl crl shown
-p, --provisioner provisioner shown
-v, --valid valid shown (default true)
-r, --revoked revoked shown (default true)
-x, --expired expired shown
-d, --dnsnames DNSNames column shown
-m, --emailaddresses EmailAddresses column shown
-i, --ipaddresses IPAddresses column shown
-u, --uris URIs column shown
-c, --crl crl column shown
-p, --provisioner provisioner column shown
-v, --valid valid certificates shown (default true)
-r, --revoked revoked certificates shown (default true)
-x, --expired expired certificates shown
```

### Example
Expand All @@ -41,12 +45,12 @@ step-badger sshCerts PATH [flags]
```text
Flags:
-e, --emit {t|j|m} emit format: table|json|markdown (default t)
-t, --time {i|s} time shown: iso|short (default i)
-t, --time {i|s} time format: iso|short (default i)
-s, --sort {s|f} sort order: start|finish (default f)
-k, --kid Key ID shown
-v, --valid valid shown (default true)
-r, --revoked revoked shown (default true)
-x, --expired expired shown
-k, --kid Key ID column shown
-v, --valid valid certificates shown (default true)
-r, --revoked revoked certificates shown (default true)
-x, --expired expired certificates shown
```

### Example
Expand Down
60 changes: 60 additions & 0 deletions cmd/columns_x509certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,66 @@ func getX509Columns() []tX509Column {
contentEscapeMD: true,
},

tX509Column{
isShown: func(tc tConfig) bool { return tc.showDNSNames },
title: func() string { return "DNSNames" }, // Static title
titleColor: color.Bold,

contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
return strings.Join(x.X509Certificate.DNSNames, ", ")
},
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
contentAlignMD: ALIGN_LEFT,
contentEscapeMD: true,
},

tX509Column{
isShown: func(tc tConfig) bool { return tc.showEmailAddresses },
title: func() string { return "EmailAddresses" }, // Static title
titleColor: color.Bold,

contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
return strings.Join(x.X509Certificate.EmailAddresses, ", ")
},
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
contentAlignMD: ALIGN_LEFT,
contentEscapeMD: true,
},

tX509Column{
isShown: func(tc tConfig) bool { return tc.showIPAddresses },
title: func() string { return "IPAddresses" }, // Static title
titleColor: color.Bold,

contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
var thisIPAddresses []string
for _, thisIPAddress := range x.X509Certificate.IPAddresses {
thisIPAddresses = append(thisIPAddresses, thisIPAddress.String())
}
return strings.Join(thisIPAddresses, ", ")
},
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
contentAlignMD: ALIGN_LEFT,
contentEscapeMD: true,
},

tX509Column{
isShown: func(tc tConfig) bool { return tc.showURIs },
title: func() string { return "URIs" }, // Static title
titleColor: color.Bold,

contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
var thisUris []string
for _, thisUri := range x.X509Certificate.URIs {
thisUris = append(thisUris, thisUri.String())
}
return strings.Join(thisUris, ", ")
},
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
contentAlignMD: ALIGN_LEFT,
contentEscapeMD: true,
},

tX509Column{
isShown: func(tc tConfig) bool { return tc.showCrl },
title: func() string { return "CRLDistributionPoints" }, // Static title
Expand Down
10 changes: 5 additions & 5 deletions cmd/command_sshcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func init() {
sshCertsCmd.Flags().SortFlags = false

sshCertsCmd.Flags().VarP(config.emitSshFormat, "emit", "e", "emit format: table|json|markdown") // Choice
sshCertsCmd.Flags().VarP(config.timeFormat, "time", "t", "time shown: iso|short") // Choice
sshCertsCmd.Flags().VarP(config.timeFormat, "time", "t", "time format: iso|short") // Choice
sshCertsCmd.Flags().VarP(config.sortOrder, "sort", "s", "sort order: start|finish") // Choice
sshCertsCmd.Flags().BoolVarP(&config.showKeyId, "kid", "k", false, "Key ID shown")
sshCertsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid shown")
sshCertsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked shown")
sshCertsCmd.Flags().BoolVarP(&config.showExpired, "expired", "x", false, "expired shown")
sshCertsCmd.Flags().BoolVarP(&config.showKeyId, "kid", "k", false, "Key ID column shown")
sshCertsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid certificates shown")
sshCertsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked certificates shown")
sshCertsCmd.Flags().BoolVarP(&config.showExpired, "expired", "x", false, "expired certificates shown")
}

/*
Expand Down
18 changes: 12 additions & 6 deletions cmd/command_x509certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ func init() {
x509certsCmd.Flags().SortFlags = false

x509certsCmd.Flags().VarP(config.emitX509Format, "emit", "e", "emit format: table|json|markdown|openssl") // Choice
x509certsCmd.Flags().VarP(config.timeFormat, "time", "t", "time shown: iso|short") // Choice
x509certsCmd.Flags().VarP(config.timeFormat, "time", "t", "time format: iso|short") // Choice
x509certsCmd.Flags().VarP(config.sortOrder, "sort", "s", "sort order: start|finish") // Choice
x509certsCmd.Flags().BoolVarP(&config.showCrl, "crl", "c", false, "crl shown")
x509certsCmd.Flags().BoolVarP(&config.showProvisioner, "provisioner", "p", false, "provisioner shown")
x509certsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid shown")
x509certsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked shown")
x509certsCmd.Flags().BoolVarP(&config.showExpired, "expired", "x", false, "expired shown")

x509certsCmd.Flags().BoolVarP(&config.showDNSNames, "dnsnames", "d", false, "DNSNames column shown")
x509certsCmd.Flags().BoolVarP(&config.showEmailAddresses, "emailaddresses", "m", false, "EmailAddresses column shown")
x509certsCmd.Flags().BoolVarP(&config.showIPAddresses, "ipaddresses", "i", false, "IPAddresses column shown")
x509certsCmd.Flags().BoolVarP(&config.showURIs, "uris", "u", false, "URIs column shown")
x509certsCmd.Flags().BoolVarP(&config.showCrl, "crl", "c", false, "crl column shown")
x509certsCmd.Flags().BoolVarP(&config.showProvisioner, "provisioner", "p", false, "provisioner column shown")

x509certsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid certificates shown")
x509certsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked certificates shown")
x509certsCmd.Flags().BoolVarP(&config.showExpired, "expired", "x", false, "expired certificates shown")
}

/*
Expand Down
26 changes: 15 additions & 11 deletions cmd/defs_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ func initChoices() {
Configuration structure
*/
type tConfig struct {
emitSshFormat *tChoice
emitX509Format *tChoice
showCrl bool
showKeyId bool
sortOrder *tChoice
showValid bool
showExpired bool
showRevoked bool
showProvisioner bool
timeFormat *tChoice
emitSshFormat *tChoice
emitX509Format *tChoice
showCrl bool
showKeyId bool
sortOrder *tChoice
showValid bool
showExpired bool
showRevoked bool
showProvisioner bool
timeFormat *tChoice
showDNSNames bool
showEmailAddresses bool
showIPAddresses bool
showURIs bool
}

/*
Expand Down Expand Up @@ -106,7 +110,7 @@ func getThisAlignChar() map[int]string {
}

/*
escapeMarkdown returns same string but safeguarderd against markdown interpretation
escapeMarkdown returns same string but safeguarded against markdown interpretation
'text' text to be safeguarded
*/
Expand Down

0 comments on commit df1c5d8

Please sign in to comment.