Skip to content

Commit 525c72b

Browse files
Simplifing badger use. (#24)
* refactor: dbTable simplified BREAKING CHANGE: Different dbTable output format. * chore: Remove unneeded defs. * refactor: Extensive x509 code simplification. * chore * refactor: Extensive ssh simplification. * chore * chore * chore
1 parent 99808e5 commit 525c72b

16 files changed

+872
-566
lines changed

cmd/badger.go

Lines changed: 412 additions & 0 deletions
Large diffs are not rendered by default.

cmd/columns_sshcerts.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ getX509Columns defines look and content of table's emitted columns.
2323
*/
2424
func getSshColumns() []tSshColumn {
2525

26-
var thisColumns []tSshColumn
26+
var columns []tSshColumn
2727

28-
thisColumns = append(thisColumns,
28+
columns = append(columns,
2929

3030
tSshColumn{
3131
isShown: func(_ tConfig) bool { return true }, // Always shown.
@@ -46,10 +46,10 @@ func getSshColumns() []tSshColumn {
4646
titleColor: color.Bold,
4747

4848
contentSource: func(x tSshCertificateWithRevocation, _ tConfig) string {
49-
return getThisCertType()[int(x.SshCertificate.CertType)]
49+
return getCertType()[int(x.SshCertificate.CertType)]
5050
},
5151
contentColor: func(x tSshCertificateWithRevocation) color.Attribute {
52-
return getThisCertTypeColor()[int(x.SshCertificate.CertType)]
52+
return getCertTypeColor()[int(x.SshCertificate.CertType)]
5353
}, // Dynamic color
5454
contentAlignMD: ALIGN_LEFT,
5555
contentEscapeMD: true,
@@ -119,11 +119,11 @@ func getSshColumns() []tSshColumn {
119119
titleColor: color.Bold,
120120

121121
contentSource: func(x tSshCertificateWithRevocation, tc tConfig) string {
122-
if len(x.SshRevocation.ProvisionerID) > 0 {
122+
if len(x.SshCertificateRevocation.ProvisionerID) > 0 {
123123
if tc.timeFormat.Value == "s" {
124-
return x.SshRevocation.RevokedAt.UTC().Format(time.DateOnly)
124+
return x.SshCertificateRevocation.RevokedAt.UTC().Format(time.DateOnly)
125125
} else {
126-
return x.SshRevocation.RevokedAt.UTC().Format(time.RFC3339)
126+
return x.SshCertificateRevocation.RevokedAt.UTC().Format(time.RFC3339)
127127
}
128128
} else {
129129
return ""
@@ -143,30 +143,30 @@ func getSshColumns() []tSshColumn {
143143
return x.Validity
144144
},
145145
contentColor: func(x tSshCertificateWithRevocation) color.Attribute {
146-
return getThisValidityColor()[x.Validity]
146+
return getValidityColor()[x.Validity]
147147
}, // Dynamic color
148148
contentAlignMD: ALIGN_LEFT,
149149
contentEscapeMD: true,
150150
},
151151
)
152152

153-
return thisColumns
153+
return columns
154154
}
155155

156156
/*
157-
getThisCertType maps given CertType to string to be displayed.
157+
getCertType maps given CertType to string to be displayed.
158158
*/
159-
func getThisCertType() map[int]string {
159+
func getCertType() map[int]string {
160160
return map[int]string{
161161
1: `User`,
162162
2: `Host`,
163163
}
164164
}
165165

166166
/*
167-
getThisCertTypeColor maps given CertType to color to be used.
167+
getCertTypeColor maps given CertType to color to be used.
168168
*/
169-
func getThisCertTypeColor() map[int]color.Attribute {
169+
func getCertTypeColor() map[int]color.Attribute {
170170
return map[int]color.Attribute{
171171
1: color.FgCyan,
172172
2: color.FgMagenta,

cmd/columns_x509certs.go

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type tX509Column struct {
1111
isShown func(tConfig) bool
1212
title func() string
1313
titleColor color.Attribute
14-
contentSource func(tX509CertificateWithRevocation, tConfig) string
15-
contentColor func(tX509CertificateWithRevocation) color.Attribute
14+
contentSource func(tX509CertificateProvisionerRevocation, tConfig) string
15+
contentColor func(tX509CertificateProvisionerRevocation) color.Attribute
1616
contentAlignMD int
1717
contentEscapeMD bool
1818
}
@@ -22,19 +22,19 @@ getX509Columns defines look and content of table's emitted columns.
2222
*/
2323
func getX509Columns() []tX509Column {
2424

25-
var thisColumns []tX509Column
25+
var columns []tX509Column
2626

27-
thisColumns = append(thisColumns,
27+
columns = append(columns,
2828

2929
tX509Column{
3030
isShown: func(_ tConfig) bool { return true }, // Always shown.
3131
title: func() string { return "Serial number" }, // Static title.
3232
titleColor: color.Bold,
3333

34-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
34+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
3535
return x.X509Certificate.SerialNumber.String()
3636
},
37-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color.
37+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgWhite }, // Static color.
3838
contentAlignMD: ALIGN_RIGHT,
3939
contentEscapeMD: false,
4040
},
@@ -44,8 +44,10 @@ func getX509Columns() []tX509Column {
4444
title: func() string { return "Subject" }, // Static title.
4545
titleColor: color.Bold,
4646

47-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string { return x.X509Certificate.Subject.String() },
48-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgHiWhite }, // Static color.
47+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
48+
return x.X509Certificate.Subject.String()
49+
},
50+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgHiWhite }, // Static color.
4951
contentAlignMD: ALIGN_LEFT,
5052
contentEscapeMD: true,
5153
},
@@ -55,10 +57,10 @@ func getX509Columns() []tX509Column {
5557
title: func() string { return "DNSNames" }, // Static title.
5658
titleColor: color.Bold,
5759

58-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
60+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
5961
return strings.Join(x.X509Certificate.DNSNames, ", ")
6062
},
61-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color.
63+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgWhite }, // Static color.
6264
contentAlignMD: ALIGN_LEFT,
6365
contentEscapeMD: true,
6466
},
@@ -68,10 +70,10 @@ func getX509Columns() []tX509Column {
6870
title: func() string { return "EmailAddresses" }, // Static title.
6971
titleColor: color.Bold,
7072

71-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
73+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
7274
return strings.Join(x.X509Certificate.EmailAddresses, ", ")
7375
},
74-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color.
76+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgWhite }, // Static color.
7577
contentAlignMD: ALIGN_LEFT,
7678
contentEscapeMD: true,
7779
},
@@ -81,14 +83,14 @@ func getX509Columns() []tX509Column {
8183
title: func() string { return "IPAddresses" }, // Static title.
8284
titleColor: color.Bold,
8385

84-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
85-
var thisIPAddresses []string
86-
for _, thisIPAddress := range x.X509Certificate.IPAddresses {
87-
thisIPAddresses = append(thisIPAddresses, thisIPAddress.String())
86+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
87+
var ipAddresses []string
88+
for _, ipAddress := range x.X509Certificate.IPAddresses {
89+
ipAddresses = append(ipAddresses, ipAddress.String())
8890
}
89-
return strings.Join(thisIPAddresses, ", ")
91+
return strings.Join(ipAddresses, ", ")
9092
},
91-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color.
93+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgWhite }, // Static color.
9294
contentAlignMD: ALIGN_LEFT,
9395
contentEscapeMD: true,
9496
},
@@ -98,14 +100,14 @@ func getX509Columns() []tX509Column {
98100
title: func() string { return "URIs" }, // Static title.
99101
titleColor: color.Bold,
100102

101-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
102-
var thisUris []string
103-
for _, thisUri := range x.X509Certificate.URIs {
104-
thisUris = append(thisUris, thisUri.String())
103+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
104+
var uris []string
105+
for _, uri := range x.X509Certificate.URIs {
106+
uris = append(uris, uri.String())
105107
}
106-
return strings.Join(thisUris, ", ")
108+
return strings.Join(uris, ", ")
107109
},
108-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color.
110+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgWhite }, // Static color.
109111
contentAlignMD: ALIGN_LEFT,
110112
contentEscapeMD: true,
111113
},
@@ -115,10 +117,10 @@ func getX509Columns() []tX509Column {
115117
title: func() string { return "CRLDistributionPoints" }, // Static title.
116118
titleColor: color.Bold,
117119

118-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
120+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
119121
return strings.Join(x.X509Certificate.CRLDistributionPoints, ", ")
120122
},
121-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color.
123+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgWhite }, // Static color.
122124
contentAlignMD: ALIGN_LEFT,
123125
contentEscapeMD: true,
124126
},
@@ -128,10 +130,10 @@ func getX509Columns() []tX509Column {
128130
title: func() string { return "Provisioner" }, // Static title.
129131
titleColor: color.Bold,
130132

131-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
133+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
132134
return (x.X509Provisioner.Type + " " + x.X509Provisioner.Name[:min(len(x.X509Provisioner.Name), 6)])
133135
},
134-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgWhite }, // Static color.
136+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgWhite }, // Static color.
135137
contentAlignMD: ALIGN_LEFT,
136138
contentEscapeMD: true,
137139
},
@@ -141,14 +143,14 @@ func getX509Columns() []tX509Column {
141143
title: func() string { return "Start" }, // Static title.
142144
titleColor: color.Bold,
143145

144-
contentSource: func(x tX509CertificateWithRevocation, tc tConfig) string {
146+
contentSource: func(x tX509CertificateProvisionerRevocation, tc tConfig) string {
145147
if tc.timeFormat.Value == "s" {
146148
return x.X509Certificate.NotBefore.UTC().Format(time.DateOnly)
147149
} else {
148150
return x.X509Certificate.NotBefore.UTC().Format(time.RFC3339)
149151
}
150152
},
151-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgHiBlack }, // Static color.
153+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgHiBlack }, // Static color.
152154
contentAlignMD: ALIGN_LEFT,
153155
contentEscapeMD: true,
154156
},
@@ -158,14 +160,14 @@ func getX509Columns() []tX509Column {
158160
title: func() string { return "Finish" }, // Static title.
159161
titleColor: color.Bold,
160162

161-
contentSource: func(x tX509CertificateWithRevocation, tc tConfig) string {
163+
contentSource: func(x tX509CertificateProvisionerRevocation, tc tConfig) string {
162164
if tc.timeFormat.Value == "s" {
163165
return x.X509Certificate.NotAfter.UTC().Format(time.DateOnly)
164166
} else {
165167
return x.X509Certificate.NotAfter.UTC().Format(time.RFC3339)
166168
}
167169
},
168-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgHiBlack }, // Static color.
170+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgHiBlack }, // Static color.
169171
contentAlignMD: ALIGN_LEFT,
170172
contentEscapeMD: true,
171173
},
@@ -175,7 +177,7 @@ func getX509Columns() []tX509Column {
175177
title: func() string { return "Revoked at" }, // Static title.
176178
titleColor: color.Bold,
177179

178-
contentSource: func(x tX509CertificateWithRevocation, tc tConfig) string {
180+
contentSource: func(x tX509CertificateProvisionerRevocation, tc tConfig) string {
179181
if len(x.X509Revocation.ProvisionerID) > 0 {
180182
if tc.timeFormat.Value == "s" {
181183
return x.X509Revocation.RevokedAt.UTC().Format(time.DateOnly)
@@ -186,7 +188,7 @@ func getX509Columns() []tX509Column {
186188
return ""
187189
}
188190
},
189-
contentColor: func(_ tX509CertificateWithRevocation) color.Attribute { return color.FgHiBlack }, // Static color.
191+
contentColor: func(_ tX509CertificateProvisionerRevocation) color.Attribute { return color.FgHiBlack }, // Static color.
190192
contentAlignMD: ALIGN_LEFT,
191193
contentEscapeMD: true,
192194
},
@@ -196,16 +198,16 @@ func getX509Columns() []tX509Column {
196198
title: func() string { return "Validity" }, // Static title.
197199
titleColor: color.Bold,
198200

199-
contentSource: func(x tX509CertificateWithRevocation, _ tConfig) string {
201+
contentSource: func(x tX509CertificateProvisionerRevocation, _ tConfig) string {
200202
return x.Validity
201203
},
202-
contentColor: func(x tX509CertificateWithRevocation) color.Attribute {
203-
return getThisValidityColor()[x.Validity]
204+
contentColor: func(x tX509CertificateProvisionerRevocation) color.Attribute {
205+
return getValidityColor()[x.Validity]
204206
}, // Dynamic color
205207
contentAlignMD: ALIGN_LEFT,
206208
contentEscapeMD: true,
207209
},
208210
)
209211

210-
return thisColumns
212+
return columns
211213
}

0 commit comments

Comments
 (0)