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.
()
| 1378 | // file-based fields for the TLS CA, client certificate, and client key are |
| 1379 | // used. |
| 1380 | func (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 | |
| 1400 | func (c *TLSConfig) usingClientCert() bool { |
| 1401 | return len(c.Cert) > 0 || len(c.CertFile) > 0 || len(c.CertRef) > 0 |
no test coverage detected