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

Method Validate

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

929// file-based fields for the TLS CA, client certificate, and client key are
930// used.
931func (c *TLSConfig) Validate() error {
932 if len(c.CA) > 0 && len(c.CAFile) > 0 {
933 return fmt.Errorf("at most one of ca and ca_file must be configured")
934 }
935 if len(c.Cert) > 0 && len(c.CertFile) > 0 {
936 return fmt.Errorf("at most one of cert and cert_file must be configured")
937 }
938 if len(c.Key) > 0 && len(c.KeyFile) > 0 {
939 return fmt.Errorf("at most one of key and key_file must be configured")
940 }
941
942 if c.usingClientCert() && !c.usingClientKey() {
943 return fmt.Errorf("exactly one of key or key_file must be configured when a client certificate is configured")
944 } else if c.usingClientKey() && !c.usingClientCert() {
945 return fmt.Errorf("exactly one of cert or cert_file must be configured when a client key is configured")
946 }
947
948 return nil
949}
950
951func (c *TLSConfig) usingClientCert() bool {
952 return len(c.Cert) > 0 || len(c.CertFile) > 0

Callers 7

UnmarshalYAMLMethod · 0.95
TestNewClientFromConfigFunction · 0.45
TestValidateHTTPConfigFunction · 0.45
UnmarshalYAMLMethod · 0.45
UnmarshalJSONMethod · 0.45
ValidateMethod · 0.45
NewTLSConfigFunction · 0.45

Calls 2

usingClientCertMethod · 0.95
usingClientKeyMethod · 0.95

Tested by 2

TestNewClientFromConfigFunction · 0.36
TestValidateHTTPConfigFunction · 0.36