Skip to content

Commit df1c5d8

Browse files
22 add dnsnames emailaddresses ipaddresses uris to x509 output (#23)
* refactor: Improve flags description. * feat: Add DNSNames, EmailAddresses, IPAddresses, URIs to x509 output.
1 parent 7fde1a7 commit df1c5d8

File tree

5 files changed

+107
-33
lines changed

5 files changed

+107
-33
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ step-badger x509Certs PATH [flags]
1717
```text
1818
Flags:
1919
-e, --emit {t|j|m|o} emit format: table|json|markdown|openssl (default t)
20-
-t, --time {i|s} time shown: iso|short (default i)
20+
-t, --time {i|s} time format: iso|short (default i)
2121
-s, --sort {s|f} sort order: start|finish (default f)
22-
-c, --crl crl shown
23-
-p, --provisioner provisioner shown
24-
-v, --valid valid shown (default true)
25-
-r, --revoked revoked shown (default true)
26-
-x, --expired expired shown
22+
-d, --dnsnames DNSNames column shown
23+
-m, --emailaddresses EmailAddresses column shown
24+
-i, --ipaddresses IPAddresses column shown
25+
-u, --uris URIs column shown
26+
-c, --crl crl column shown
27+
-p, --provisioner provisioner column shown
28+
-v, --valid valid certificates shown (default true)
29+
-r, --revoked revoked certificates shown (default true)
30+
-x, --expired expired certificates shown
2731
```
2832

2933
### Example
@@ -41,12 +45,12 @@ step-badger sshCerts PATH [flags]
4145
```text
4246
Flags:
4347
-e, --emit {t|j|m} emit format: table|json|markdown (default t)
44-
-t, --time {i|s} time shown: iso|short (default i)
48+
-t, --time {i|s} time format: iso|short (default i)
4549
-s, --sort {s|f} sort order: start|finish (default f)
46-
-k, --kid Key ID shown
47-
-v, --valid valid shown (default true)
48-
-r, --revoked revoked shown (default true)
49-
-x, --expired expired shown
50+
-k, --kid Key ID column shown
51+
-v, --valid valid certificates shown (default true)
52+
-r, --revoked revoked certificates shown (default true)
53+
-x, --expired expired certificates shown
5054
```
5155

5256
### Example

cmd/columns_x509certs.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,66 @@ func getX509Columns() []tX509Column {
5050
contentEscapeMD: true,
5151
},
5252

53+
tX509Column{
54+
isShown: func(tc tConfig) bool { return tc.showDNSNames },
55+
title: func() string { return "DNSNames" }, // Static title
56+
titleColor: color.Bold,
57+
58+
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
59+
return strings.Join(x.X509Certificate.DNSNames, ", ")
60+
},
61+
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
62+
contentAlignMD: ALIGN_LEFT,
63+
contentEscapeMD: true,
64+
},
65+
66+
tX509Column{
67+
isShown: func(tc tConfig) bool { return tc.showEmailAddresses },
68+
title: func() string { return "EmailAddresses" }, // Static title
69+
titleColor: color.Bold,
70+
71+
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
72+
return strings.Join(x.X509Certificate.EmailAddresses, ", ")
73+
},
74+
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
75+
contentAlignMD: ALIGN_LEFT,
76+
contentEscapeMD: true,
77+
},
78+
79+
tX509Column{
80+
isShown: func(tc tConfig) bool { return tc.showIPAddresses },
81+
title: func() string { return "IPAddresses" }, // Static title
82+
titleColor: color.Bold,
83+
84+
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
85+
var thisIPAddresses []string
86+
for _, thisIPAddress := range x.X509Certificate.IPAddresses {
87+
thisIPAddresses = append(thisIPAddresses, thisIPAddress.String())
88+
}
89+
return strings.Join(thisIPAddresses, ", ")
90+
},
91+
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
92+
contentAlignMD: ALIGN_LEFT,
93+
contentEscapeMD: true,
94+
},
95+
96+
tX509Column{
97+
isShown: func(tc tConfig) bool { return tc.showURIs },
98+
title: func() string { return "URIs" }, // Static title
99+
titleColor: color.Bold,
100+
101+
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
102+
var thisUris []string
103+
for _, thisUri := range x.X509Certificate.URIs {
104+
thisUris = append(thisUris, thisUri.String())
105+
}
106+
return strings.Join(thisUris, ", ")
107+
},
108+
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color
109+
contentAlignMD: ALIGN_LEFT,
110+
contentEscapeMD: true,
111+
},
112+
53113
tX509Column{
54114
isShown: func(tc tConfig) bool { return tc.showCrl },
55115
title: func() string { return "CRLDistributionPoints" }, // Static title

cmd/command_sshcerts.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ func init() {
3838
sshCertsCmd.Flags().SortFlags = false
3939

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

4949
/*

cmd/command_x509certs.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ func init() {
3838
x509certsCmd.Flags().SortFlags = false
3939

4040
x509certsCmd.Flags().VarP(config.emitX509Format, "emit", "e", "emit format: table|json|markdown|openssl") // Choice
41-
x509certsCmd.Flags().VarP(config.timeFormat, "time", "t", "time shown: iso|short") // Choice
41+
x509certsCmd.Flags().VarP(config.timeFormat, "time", "t", "time format: iso|short") // Choice
4242
x509certsCmd.Flags().VarP(config.sortOrder, "sort", "s", "sort order: start|finish") // Choice
43-
x509certsCmd.Flags().BoolVarP(&config.showCrl, "crl", "c", false, "crl shown")
44-
x509certsCmd.Flags().BoolVarP(&config.showProvisioner, "provisioner", "p", false, "provisioner shown")
45-
x509certsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid shown")
46-
x509certsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked shown")
47-
x509certsCmd.Flags().BoolVarP(&config.showExpired, "expired", "x", false, "expired shown")
43+
44+
x509certsCmd.Flags().BoolVarP(&config.showDNSNames, "dnsnames", "d", false, "DNSNames column shown")
45+
x509certsCmd.Flags().BoolVarP(&config.showEmailAddresses, "emailaddresses", "m", false, "EmailAddresses column shown")
46+
x509certsCmd.Flags().BoolVarP(&config.showIPAddresses, "ipaddresses", "i", false, "IPAddresses column shown")
47+
x509certsCmd.Flags().BoolVarP(&config.showURIs, "uris", "u", false, "URIs column shown")
48+
x509certsCmd.Flags().BoolVarP(&config.showCrl, "crl", "c", false, "crl column shown")
49+
x509certsCmd.Flags().BoolVarP(&config.showProvisioner, "provisioner", "p", false, "provisioner column shown")
50+
51+
x509certsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid certificates shown")
52+
x509certsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked certificates shown")
53+
x509certsCmd.Flags().BoolVarP(&config.showExpired, "expired", "x", false, "expired certificates shown")
4854
}
4955

5056
/*

cmd/defs_root.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@ func initChoices() {
4141
Configuration structure
4242
*/
4343
type tConfig struct {
44-
emitSshFormat *tChoice
45-
emitX509Format *tChoice
46-
showCrl bool
47-
showKeyId bool
48-
sortOrder *tChoice
49-
showValid bool
50-
showExpired bool
51-
showRevoked bool
52-
showProvisioner bool
53-
timeFormat *tChoice
44+
emitSshFormat *tChoice
45+
emitX509Format *tChoice
46+
showCrl bool
47+
showKeyId bool
48+
sortOrder *tChoice
49+
showValid bool
50+
showExpired bool
51+
showRevoked bool
52+
showProvisioner bool
53+
timeFormat *tChoice
54+
showDNSNames bool
55+
showEmailAddresses bool
56+
showIPAddresses bool
57+
showURIs bool
5458
}
5559

5660
/*
@@ -106,7 +110,7 @@ func getThisAlignChar() map[int]string {
106110
}
107111

108112
/*
109-
escapeMarkdown returns same string but safeguarderd against markdown interpretation
113+
escapeMarkdown returns same string but safeguarded against markdown interpretation
110114
111115
'text' text to be safeguarded
112116
*/

0 commit comments

Comments
 (0)