refactor embbedded cert/key combo
@@ -829,32 +829,23 @@ func (c *Config) TLSClientCerts() ([]tls.Certificate, error) {
var cb, kb []byte
if clientConfig.TLSCerts.Client.CertPem != "" {
cb = []byte(clientConfig.TLSCerts.Client.CertPem)
- if clientConfig.TLSCerts.Client.KeyPem != "" {
- kb = []byte(clientConfig.TLSCerts.Client.KeyPem)
- } else if clientConfig.TLSCerts.Client.Keyfile != "" {
- kb, err = loadByteKeyOrCertFromFile(&clientConfig, true)
+ } else if clientConfig.TLSCerts.Client.Certfile != "" {
+ cb, err = loadByteKeyOrCertFromFile(&clientConfig, false)
if err != nil {
- return nil, err
+ return nil, errors.Wrapf(err, "Failed to load cert from file path '%s'", clientConfig.TLSCerts.Client.Certfile)
}
- } else {
- return nil, errors.Errorf("Missing key for cert/key pair TLS client credentials. Ensure either the key file path or the key content is embedded in the client config.")
}
- } else if clientConfig.TLSCerts.Client.Certfile != "" {
- cb, err = loadByteKeyOrCertFromFile(&clientConfig, false)
+
if clientConfig.TLSCerts.Client.KeyPem != "" {
kb = []byte(clientConfig.TLSCerts.Client.KeyPem)
- if err != nil {
- return nil, err
- }
} else if clientConfig.TLSCerts.Client.Keyfile != "" {
kb, err = loadByteKeyOrCertFromFile(&clientConfig, true)
if err != nil {
- return nil, err
+ return nil, errors.Wrapf(err, "Failed to load key from file path '%s'", clientConfig.TLSCerts.Client.Keyfile)
}
- } else {
- return nil, errors.Errorf("Missing key for cert/key pair TLS client credentials. Ensure either the key file path or the key content is embedded in the client config.")
}
- } else {
+
+ if len(cb) == 0 && len(kb) == 0 {
// if no cert found in the config, return empty cert chain
return []tls.Certificate{clientCerts}, nil
}
