mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
parent
9ea1705563
commit
9dc0782f45
@ -15,7 +15,9 @@
|
|||||||
package clientv3
|
package clientv3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -157,16 +159,25 @@ func (c *Client) Dial(endpoint string) (*grpc.ClientConn, error) {
|
|||||||
grpc.WithBlock(),
|
grpc.WithBlock(),
|
||||||
grpc.WithTimeout(c.cfg.DialTimeout),
|
grpc.WithTimeout(c.cfg.DialTimeout),
|
||||||
}
|
}
|
||||||
if c.creds != nil {
|
|
||||||
opts = append(opts, grpc.WithTransportCredentials(*c.creds))
|
|
||||||
} else {
|
|
||||||
opts = append(opts, grpc.WithInsecure())
|
|
||||||
}
|
|
||||||
|
|
||||||
proto := "tcp"
|
proto := "tcp"
|
||||||
if url, uerr := url.Parse(endpoint); uerr == nil && url.Scheme == "unix" {
|
creds := c.creds
|
||||||
proto = "unix"
|
if url, uerr := url.Parse(endpoint); uerr == nil && strings.Contains(endpoint, "://") {
|
||||||
// strip unix:// prefix so certs work
|
switch url.Scheme {
|
||||||
|
case "unix":
|
||||||
|
proto = "unix"
|
||||||
|
case "http":
|
||||||
|
creds = nil
|
||||||
|
case "https":
|
||||||
|
if creds == nil {
|
||||||
|
tlsconfig := &tls.Config{InsecureSkipVerify: true}
|
||||||
|
emptyCreds := credentials.NewTLS(tlsconfig)
|
||||||
|
creds = &emptyCreds
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unknown scheme %q for %q", url.Scheme, endpoint)
|
||||||
|
}
|
||||||
|
// strip scheme:// prefix since grpc dials by host
|
||||||
endpoint = url.Host
|
endpoint = url.Host
|
||||||
}
|
}
|
||||||
f := func(a string, t time.Duration) (net.Conn, error) {
|
f := func(a string, t time.Duration) (net.Conn, error) {
|
||||||
@ -179,6 +190,12 @@ func (c *Client) Dial(endpoint string) (*grpc.ClientConn, error) {
|
|||||||
}
|
}
|
||||||
opts = append(opts, grpc.WithDialer(f))
|
opts = append(opts, grpc.WithDialer(f))
|
||||||
|
|
||||||
|
if creds != nil {
|
||||||
|
opts = append(opts, grpc.WithTransportCredentials(*creds))
|
||||||
|
} else {
|
||||||
|
opts = append(opts, grpc.WithInsecure())
|
||||||
|
}
|
||||||
|
|
||||||
if c.Username != "" && c.Password != "" {
|
if c.Username != "" && c.Password != "" {
|
||||||
auth, err := newAuthenticator(endpoint, opts)
|
auth, err := newAuthenticator(endpoint, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user