mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
parent
8e203b7bd5
commit
78132c9b5b
@ -15,6 +15,7 @@
|
||||
package clientv3
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"net"
|
||||
"net/url"
|
||||
@ -25,7 +26,6 @@ import (
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc/credentials"
|
||||
"github.com/coreos/etcd/pkg/transport"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -64,7 +64,7 @@ type Config struct {
|
||||
DialTimeout time.Duration
|
||||
|
||||
// TLS holds the client secure credentials, if any.
|
||||
TLS *transport.TLSInfo
|
||||
TLS *tls.Config
|
||||
}
|
||||
|
||||
// New creates a new etcdv3 client from a given configuration.
|
||||
@ -157,11 +157,7 @@ func newClient(cfg *Config) (*Client, error) {
|
||||
}
|
||||
var creds *credentials.TransportAuthenticator
|
||||
if cfg.TLS != nil {
|
||||
tlscfg, err := cfg.TLS.ClientConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := credentials.NewTLS(tlscfg)
|
||||
c := credentials.NewTLS(cfg.TLS)
|
||||
creds = &c
|
||||
}
|
||||
// use a temporary skeleton client to bootstrap first connection
|
||||
|
@ -94,9 +94,15 @@ func mustClient(endpoints []string, cert, key, cacert string) *clientv3.Client {
|
||||
|
||||
cfg := clientv3.Config{
|
||||
Endpoints: endpoints,
|
||||
TLS: cfgtls,
|
||||
DialTimeout: 20 * time.Second,
|
||||
}
|
||||
if cfgtls != nil {
|
||||
clientTLS, err := cfgtls.ClientConfig()
|
||||
if err != nil {
|
||||
ExitWithError(ExitBadArgs, err)
|
||||
}
|
||||
cfg.TLS = clientTLS
|
||||
}
|
||||
|
||||
client, err := clientv3.New(cfg)
|
||||
if err != nil {
|
||||
|
@ -491,10 +491,18 @@ func NewClientV3(m *member) (*clientv3.Client, error) {
|
||||
if m.grpcAddr == "" {
|
||||
return nil, fmt.Errorf("member not configured for grpc")
|
||||
}
|
||||
|
||||
cfg := clientv3.Config{
|
||||
Endpoints: []string{m.grpcAddr},
|
||||
DialTimeout: 5 * time.Second,
|
||||
TLS: m.ClientTLSInfo,
|
||||
}
|
||||
|
||||
if m.ClientTLSInfo != nil {
|
||||
tls, err := m.ClientTLSInfo.ClientConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.TLS = tls
|
||||
}
|
||||
return clientv3.New(cfg)
|
||||
}
|
||||
|
@ -31,16 +31,17 @@ var (
|
||||
func mustCreateConn() *clientv3.Client {
|
||||
endpoint := endpoints[dialTotal%len(endpoints)]
|
||||
dialTotal++
|
||||
cfgtls := &tls
|
||||
if cfgtls.Empty() {
|
||||
cfgtls = nil
|
||||
cfg := clientv3.Config{Endpoints: []string{endpoint}}
|
||||
if !tls.Empty() {
|
||||
cfgtls, err := tls.ClientConfig()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "bad tls config: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
cfg.TLS = cfgtls
|
||||
}
|
||||
client, err := clientv3.New(
|
||||
clientv3.Config{
|
||||
Endpoints: []string{endpoint},
|
||||
TLS: cfgtls,
|
||||
},
|
||||
)
|
||||
|
||||
client, err := clientv3.New(cfg)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "dial error: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user