From 74d0203af05460f040a02352dcddc9e69f94975c Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Mon, 19 Oct 2015 21:17:37 +0800 Subject: [PATCH] Make default tls host work Signed-off-by: Lei Jitang --- opts/opts.go | 8 ++++---- opts/opts_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/opts/opts.go b/opts/opts.go index 78059739a8..3d8e4b4816 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -16,7 +16,7 @@ var ( alphaRegexp = regexp.MustCompile(`[a-zA-Z]`) domainRegexp = regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`) // DefaultHTTPHost Default HTTP Host used if only port is provided to -H flag e.g. docker daemon -H tcp://:8080 - DefaultHTTPHost = "127.0.0.1" + DefaultHTTPHost = "localhost" // DefaultHTTPPort Default HTTP Port used if only the protocol is provided to -H flag e.g. docker daemon -H tcp:// // TODO Windows. DefaultHTTPPort is only used on Windows if a -H parameter @@ -342,7 +342,7 @@ func ValidateLabel(val string) (string, error) { // ValidateHost validates that the specified string is a valid host and returns it. func ValidateHost(val string) (string, error) { - _, err := parsers.ParseDockerDaemonHost(DefaultTCPHost, DefaultUnixSocket, val) + _, err := parsers.ParseDockerDaemonHost(DefaultTCPHost, DefaultTLSHost, DefaultUnixSocket, "", val) if err != nil { return val, err } @@ -352,8 +352,8 @@ func ValidateHost(val string) (string, error) { } // ParseHost and set defaults for a Daemon host string -func ParseHost(val string) (string, error) { - host, err := parsers.ParseDockerDaemonHost(DefaultTCPHost, DefaultUnixSocket, val) +func ParseHost(defaultHost, val string) (string, error) { + host, err := parsers.ParseDockerDaemonHost(DefaultTCPHost, DefaultTLSHost, DefaultUnixSocket, defaultHost, val) if err != nil { return val, err } diff --git a/opts/opts_test.go b/opts/opts_test.go index 0e4e9562e7..baf5f53362 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -445,9 +445,9 @@ func TestParseHost(t *testing.T) { "fd://": "fd://", "fd://something": "fd://something", "tcp://host:": "tcp://host:2375", - "tcp://": "tcp://127.0.0.1:2375", - "tcp://:2375": "tcp://127.0.0.1:2375", // default ip address - "tcp://:2376": "tcp://127.0.0.1:2376", // default ip address + "tcp://": "tcp://localhost:2375", + "tcp://:2375": "tcp://localhost:2375", // default ip address + "tcp://:2376": "tcp://localhost:2376", // default ip address "tcp://0.0.0.0:8080": "tcp://0.0.0.0:8080", "tcp://192.168.0.0:12000": "tcp://192.168.0.0:12000", "tcp://192.168:8080": "tcp://192.168:8080", @@ -458,12 +458,12 @@ func TestParseHost(t *testing.T) { } for value, errorMessage := range invalid { - if _, err := ParseHost(value); err == nil || err.Error() != errorMessage { + if _, err := ParseHost(defaultHTTPHost, value); err == nil || err.Error() != errorMessage { t.Fatalf("Expected an error for %v with [%v], got [%v]", value, errorMessage, err) } } for value, expected := range valid { - if actual, err := ParseHost(value); err != nil || actual != expected { + if actual, err := ParseHost(defaultHTTPHost, value); err != nil || actual != expected { t.Fatalf("Expected for %v [%v], got [%v, %v]", value, expected, actual, err) } }