2019-08-22 05:12:46 +00:00
|
|
|
package tls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
|
2019-12-12 01:27:03 +00:00
|
|
|
"go.etcd.io/etcd/pkg/transport"
|
2019-08-22 05:12:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
CAFile string
|
|
|
|
CertFile string
|
|
|
|
KeyFile string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Config) ClientConfig() (*tls.Config, error) {
|
|
|
|
if c.CertFile == "" && c.KeyFile == "" && c.CAFile == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
info := &transport.TLSInfo{
|
2019-12-12 01:27:03 +00:00
|
|
|
CertFile: c.CertFile,
|
|
|
|
KeyFile: c.KeyFile,
|
|
|
|
TrustedCAFile: c.CAFile,
|
2019-08-22 05:12:46 +00:00
|
|
|
}
|
|
|
|
tlsConfig, err := info.ClientConfig()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return tlsConfig, nil
|
|
|
|
}
|