mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Merge pull request #71002 from awly/certutil-cleanup
Remove unused funcs in certutil
This commit is contained in:
commit
d399e079f2
@ -260,34 +260,6 @@ func GenerateSelfSignedCertKeyWithFixtures(host string, alternateIPs []net.IP, a
|
|||||||
return certBuffer.Bytes(), keyBuffer.Bytes(), nil
|
return certBuffer.Bytes(), keyBuffer.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatBytesCert receives byte array certificate and formats in human-readable format
|
|
||||||
func FormatBytesCert(cert []byte) (string, error) {
|
|
||||||
block, _ := pem.Decode(cert)
|
|
||||||
c, err := x509.ParseCertificate(block.Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to parse certificate [%v]", err)
|
|
||||||
}
|
|
||||||
return FormatCert(c), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormatCert receives certificate and formats in human-readable format
|
|
||||||
func FormatCert(c *x509.Certificate) string {
|
|
||||||
var ips []string
|
|
||||||
for _, ip := range c.IPAddresses {
|
|
||||||
ips = append(ips, ip.String())
|
|
||||||
}
|
|
||||||
altNames := append(ips, c.DNSNames...)
|
|
||||||
res := fmt.Sprintf(
|
|
||||||
"Issuer: CN=%s | Subject: CN=%s | CA: %t\n",
|
|
||||||
c.Issuer.CommonName, c.Subject.CommonName, c.IsCA,
|
|
||||||
)
|
|
||||||
res += fmt.Sprintf("Not before: %s Not After: %s", c.NotBefore, c.NotAfter)
|
|
||||||
if len(altNames) > 0 {
|
|
||||||
res += fmt.Sprintf("\nAlternate Names: %v", altNames)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipsToStrings(ips []net.IP) []string {
|
func ipsToStrings(ips []net.IP) []string {
|
||||||
ss := make([]string, 0, len(ips))
|
ss := make([]string, 0, len(ips))
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
|
Loading…
Reference in New Issue
Block a user