MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / ParseServerSecret

Function ParseServerSecret

pkg/certs/certs.go:409–430  ·  view source on GitHub ↗

ParseServerSecret parse a secret for a server to a key pair

(secret *corev1.Secret)

Source from the content-addressed store, hash-verified

407
408// ParseServerSecret parse a secret for a server to a key pair
409func ParseServerSecret(secret *corev1.Secret) (*KeyPair, error) {
410 privateKey, ok := secret.Data[TLSPrivateKeyKey]
411 if !ok {
412 return nil, fmt.Errorf("missing %v secret data", TLSPrivateKeyKey)
413 }
414
415 publicKey, ok := secret.Data[TLSCertKey]
416 if !ok {
417 return nil, fmt.Errorf("missing %s secret data", TLSCertKey)
418 }
419
420 // Verify the key matches the certificate
421 _, err := tls.X509KeyPair(publicKey, privateKey)
422 if err != nil {
423 return nil, err
424 }
425
426 return &KeyPair{
427 Private: privateKey,
428 Certificate: publicKey,
429 }, nil
430}
431
432// createCAWithValidity create a CA with a certain validity, with a parent certificate and signed by a certain
433// private key. If the latest two parameters are nil, the CA will be a root one (self-signed)

Callers 4

BuildConfigurationFilesFunction · 0.92
validateLeafCertificateFunction · 0.92
RenewLeafCertificateFunction · 0.85
k8s_test.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected