浏览代码

clientv3: use tls.Config in clientv3.Config

Fixes #4648
Anthony Romano 9 年之前
父节点
当前提交
78132c9b5b
共有 4 个文件被更改,包括 29 次插入18 次删除
  1. 3 7
      clientv3/client.go
  2. 7 1
      etcdctlv3/command/global.go
  3. 9 1
      integration/cluster.go
  4. 10 9
      tools/benchmark/cmd/util.go

+ 3 - 7
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

+ 7 - 1
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 {

+ 9 - 1
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)
 }

+ 10 - 9
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)