From 78132c9b5bf971c5d6c8a225ea8a3f96827cfad7 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 7 Mar 2016 15:00:14 -0800 Subject: [PATCH] clientv3: use tls.Config in clientv3.Config Fixes #4648 --- clientv3/client.go | 10 +++------- etcdctlv3/command/global.go | 8 +++++++- integration/cluster.go | 10 +++++++++- tools/benchmark/cmd/util.go | 19 ++++++++++--------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/clientv3/client.go b/clientv3/client.go index 99ea7269a..c266f36f2 100644 --- a/clientv3/client.go +++ b/clientv3/client.go @@ -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 diff --git a/etcdctlv3/command/global.go b/etcdctlv3/command/global.go index 38d261dd4..a0ea35a34 100644 --- a/etcdctlv3/command/global.go +++ b/etcdctlv3/command/global.go @@ -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 { diff --git a/integration/cluster.go b/integration/cluster.go index 7ec023d23..bdae94153 100644 --- a/integration/cluster.go +++ b/integration/cluster.go @@ -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) } diff --git a/tools/benchmark/cmd/util.go b/tools/benchmark/cmd/util.go index f76ec4331..094ec4c8f 100644 --- a/tools/benchmark/cmd/util.go +++ b/tools/benchmark/cmd/util.go @@ -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)