MCPcopy Create free account
hub / github.com/prometheus/common / getClientCertificate

Method getClientCertificate

config/http_config.go:1427–1461  ·  view source on GitHub ↗

getClientCertificate reads the pair of client cert and key and returns a tls.Certificate.

(ctx context.Context, secretManager SecretManager)

Source from the content-addressed store, hash-verified

1425
1426// getClientCertificate reads the pair of client cert and key and returns a tls.Certificate.
1427func (c *TLSConfig) getClientCertificate(ctx context.Context, secretManager SecretManager) (*tls.Certificate, error) {
1428 var (
1429 certData, keyData string
1430 err error
1431 )
1432
1433 certSecret, err := toSecret(secretManager, Secret(c.Cert), c.CertFile, c.CertRef)
1434 if err != nil {
1435 return nil, fmt.Errorf("unable to use client cert: %w", err)
1436 }
1437 if certSecret != nil {
1438 certData, err = certSecret.Fetch(ctx)
1439 if err != nil {
1440 return nil, fmt.Errorf("unable to read specified client cert: %w", err)
1441 }
1442 }
1443
1444 keySecret, err := toSecret(secretManager, c.Key, c.KeyFile, c.KeyRef)
1445 if err != nil {
1446 return nil, fmt.Errorf("unable to use client key: %w", err)
1447 }
1448 if keySecret != nil {
1449 keyData, err = keySecret.Fetch(ctx)
1450 if err != nil {
1451 return nil, fmt.Errorf("unable to read specified client key: %w", err)
1452 }
1453 }
1454
1455 cert, err := tls.X509KeyPair([]byte(certData), []byte(keyData))
1456 if err != nil {
1457 return nil, fmt.Errorf("unable to use specified client cert (%s) & key (%s): %w", certSecret.Description(), keySecret.Description(), err)
1458 }
1459
1460 return &cert, nil
1461}
1462
1463// updateRootCA parses the given byte slice as a series of PEM encoded certificates and updates tls.Config.RootCAs.
1464func updateRootCA(cfg *tls.Config, b []byte) bool {

Callers 1

NewTLSConfigWithContextFunction · 0.80

Calls 4

toSecretFunction · 0.85
SecretTypeAlias · 0.85
FetchMethod · 0.65
DescriptionMethod · 0.65

Tested by

no test coverage detected