mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Set client version instead of negotiating it
Signed-off-by: Christopher Crone <christopher.crone@docker.com>
This commit is contained in:
parent
42d812df0a
commit
85431566a8
1 changed files with 25 additions and 5 deletions
|
@ -18,7 +18,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
dclient "github.com/docker/docker/client"
|
dclient "github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
|
@ -328,10 +327,31 @@ func DaemonHost() string {
|
||||||
// NewEnvClientWithVersion returns a docker client with a specified version.
|
// NewEnvClientWithVersion returns a docker client with a specified version.
|
||||||
// See: github.com/docker/docker/client `NewEnvClient()`
|
// See: github.com/docker/docker/client `NewEnvClient()`
|
||||||
func NewEnvClientWithVersion(version string) (*dclient.Client, error) {
|
func NewEnvClientWithVersion(version string) (*dclient.Client, error) {
|
||||||
cli, err := dclient.NewEnvClient()
|
if version == "" {
|
||||||
if err != nil {
|
return nil, errors.New("version not specified")
|
||||||
return nil, err
|
}
|
||||||
|
|
||||||
|
var httpClient *http.Client
|
||||||
|
if os.Getenv("DOCKER_CERT_PATH") != "" {
|
||||||
|
tlsConfig, err := getTLSConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
httpClient = &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: tlsConfig,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
host := os.Getenv("DOCKER_HOST")
|
||||||
|
if host == "" {
|
||||||
|
host = dclient.DefaultDockerHost
|
||||||
|
}
|
||||||
|
|
||||||
|
cli, err := dclient.NewClient(host, version, httpClient, nil)
|
||||||
|
if err != nil {
|
||||||
|
return cli, err
|
||||||
}
|
}
|
||||||
cli.NegotiateAPIVersionPing(types.Ping{APIVersion: version})
|
|
||||||
return cli, nil
|
return cli, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue