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.
()
| 929 | // file-based fields for the TLS CA, client certificate, and client key are |
| 930 | // used. |
| 931 | func (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 | |
| 951 | func (c *TLSConfig) usingClientCert() bool { |
| 952 | return len(c.Cert) > 0 || len(c.CertFile) > 0 |