mirror of https://github.com/docker/cli.git
Merge pull request #1443 from acmcodercom/defaulttcpschema
fixes #1441 set default schema to tcp for docker host
This commit is contained in:
commit
a2a7a7cc00
|
@ -274,21 +274,17 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, isTrusted bool, containe
|
||||||
|
|
||||||
// NewAPIClientFromFlags creates a new APIClient from command line flags
|
// NewAPIClientFromFlags creates a new APIClient from command line flags
|
||||||
func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) {
|
func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) {
|
||||||
unparsedHost, err := getUnparsedServerHost(opts.Hosts)
|
host, err := getServerHost(opts.Hosts, opts.TLSOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &client.Client{}, err
|
return &client.Client{}, err
|
||||||
}
|
}
|
||||||
var clientOpts []func(*client.Client) error
|
var clientOpts []func(*client.Client) error
|
||||||
helper, err := connhelper.GetConnectionHelper(unparsedHost)
|
helper, err := connhelper.GetConnectionHelper(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &client.Client{}, err
|
return &client.Client{}, err
|
||||||
}
|
}
|
||||||
if helper == nil {
|
if helper == nil {
|
||||||
clientOpts = append(clientOpts, withHTTPClient(opts.TLSOptions))
|
clientOpts = append(clientOpts, withHTTPClient(opts.TLSOptions))
|
||||||
host, err := dopts.ParseHost(opts.TLSOptions != nil, unparsedHost)
|
|
||||||
if err != nil {
|
|
||||||
return &client.Client{}, err
|
|
||||||
}
|
|
||||||
clientOpts = append(clientOpts, client.WithHost(host))
|
clientOpts = append(clientOpts, client.WithHost(host))
|
||||||
} else {
|
} else {
|
||||||
clientOpts = append(clientOpts, func(c *client.Client) error {
|
clientOpts = append(clientOpts, func(c *client.Client) error {
|
||||||
|
@ -321,7 +317,7 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
|
||||||
return client.NewClientWithOpts(clientOpts...)
|
return client.NewClientWithOpts(clientOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUnparsedServerHost(hosts []string) (string, error) {
|
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error) {
|
||||||
var host string
|
var host string
|
||||||
switch len(hosts) {
|
switch len(hosts) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -331,7 +327,8 @@ func getUnparsedServerHost(hosts []string) (string, error) {
|
||||||
default:
|
default:
|
||||||
return "", errors.New("Please specify only one -H")
|
return "", errors.New("Please specify only one -H")
|
||||||
}
|
}
|
||||||
return host, nil
|
|
||||||
|
return dopts.ParseHost(tlsOptions != nil, host)
|
||||||
}
|
}
|
||||||
|
|
||||||
func withHTTPClient(tlsOpts *tlsconfig.Options) func(*client.Client) error {
|
func withHTTPClient(tlsOpts *tlsconfig.Options) func(*client.Client) error {
|
||||||
|
|
|
@ -43,6 +43,26 @@ func TestNewAPIClientFromFlags(t *testing.T) {
|
||||||
assert.Check(t, is.Equal(api.DefaultVersion, apiclient.ClientVersion()))
|
assert.Check(t, is.Equal(api.DefaultVersion, apiclient.ClientVersion()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewAPIClientFromFlagsForDefaultSchema(t *testing.T) {
|
||||||
|
host := ":2375"
|
||||||
|
opts := &flags.CommonOptions{Hosts: []string{host}}
|
||||||
|
configFile := &configfile.ConfigFile{
|
||||||
|
HTTPHeaders: map[string]string{
|
||||||
|
"My-Header": "Custom-Value",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
apiclient, err := NewAPIClientFromFlags(opts, configFile)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Check(t, is.Equal("tcp://localhost"+host, apiclient.DaemonHost()))
|
||||||
|
|
||||||
|
expectedHeaders := map[string]string{
|
||||||
|
"My-Header": "Custom-Value",
|
||||||
|
"User-Agent": UserAgent(),
|
||||||
|
}
|
||||||
|
assert.Check(t, is.DeepEqual(expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders()))
|
||||||
|
assert.Check(t, is.Equal(api.DefaultVersion, apiclient.ClientVersion()))
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
|
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
|
||||||
customVersion := "v3.3.3"
|
customVersion := "v3.3.3"
|
||||||
defer env.Patch(t, "DOCKER_API_VERSION", customVersion)()
|
defer env.Patch(t, "DOCKER_API_VERSION", customVersion)()
|
||||||
|
|
|
@ -77,6 +77,8 @@ func parseDockerDaemonHost(addr string) (string, error) {
|
||||||
return parseSimpleProtoAddr("npipe", addrParts[1], DefaultNamedPipe)
|
return parseSimpleProtoAddr("npipe", addrParts[1], DefaultNamedPipe)
|
||||||
case "fd":
|
case "fd":
|
||||||
return addr, nil
|
return addr, nil
|
||||||
|
case "ssh":
|
||||||
|
return addr, nil
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("Invalid bind address format: %s", addr)
|
return "", fmt.Errorf("Invalid bind address format: %s", addr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue