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

Method Validate

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

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