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

Method getClientCertificate

config/http_config.go:1429–1463  ·  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

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