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

Method Validate

config/http_config.go:1380–1398  ·  view source on GitHub ↗

Validate validates the TLSConfig to check that only one of the inlined or file-based fields for the TLS CA, client certificate, and client key are used.

()

Source from the content-addressed store, hash-verified

1378// file-based fields for the TLS CA, client certificate, and client key are
1379// used.
1380func (c *TLSConfig) Validate() error {
1381 if nonZeroCount(len(c.CA) > 0, len(c.CAFile) > 0, len(c.CARef) > 0) > 1 {
1382 return errors.New("at most one of ca, ca_file & ca_ref must be configured")
1383 }
1384 if nonZeroCount(len(c.Cert) > 0, len(c.CertFile) > 0, len(c.CertRef) > 0) > 1 {
1385 return errors.New("at most one of cert, cert_file & cert_ref must be configured")
1386 }
1387 if nonZeroCount(len(c.Key) > 0, len(c.KeyFile) > 0, len(c.KeyRef) > 0) > 1 {
1388 return errors.New("at most one of key and key_file must be configured")
1389 }
1390
1391 if c.usingClientCert() && !c.usingClientKey() {
1392 return errors.New("exactly one of key or key_file must be configured when a client certificate is configured")
1393 } else if c.usingClientKey() && !c.usingClientCert() {
1394 return errors.New("exactly one of cert or cert_file must be configured when a client key is configured")
1395 }
1396
1397 return nil
1398}
1399
1400func (c *TLSConfig) usingClientCert() bool {
1401 return len(c.Cert) > 0 || len(c.CertFile) > 0 || len(c.CertRef) > 0

Callers 5

UnmarshalYAMLMethod · 0.95
UnmarshalYAMLMethod · 0.45
UnmarshalJSONMethod · 0.45
ValidateMethod · 0.45
NewTLSConfigWithContextFunction · 0.45

Calls 3

usingClientCertMethod · 0.95
usingClientKeyMethod · 0.95
nonZeroCountFunction · 0.85

Tested by

no test coverage detected