From 3168149cbf20b51ac59ea2552a4e9dd7425ed784 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 17 Mar 2016 16:18:37 -0700 Subject: [PATCH] If tcp host is provided while TLS is enabled, convert to https Signed-off-by: Joffrey F --- docker/utils/utils.py | 5 +++-- tests/unit/utils_test.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index c5914cf6..70fcb1f0 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -400,11 +400,12 @@ def parse_host(addr, platform=None, tls=False): if addr == 'tcp://': raise errors.DockerException( - "Invalid bind address format: {0}".format(addr)) + "Invalid bind address format: {0}".format(addr) + ) elif addr.startswith('unix://'): addr = addr[7:] elif addr.startswith('tcp://'): - proto = "http" + proto = 'http{0}'.format('s' if tls else '') addr = addr[6:] elif addr.startswith('https://'): proto = "https" diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 65b7cf8a..c744604d 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -412,7 +412,12 @@ class ParseHostTest(base.BaseTestCase): def test_parse_host_tls(self): host_value = 'myhost.docker.net:3348' expected_result = 'https://myhost.docker.net:3348' - self.assertEqual(parse_host(host_value, None, True), expected_result) + assert parse_host(host_value, tls=True) == expected_result + + def test_parse_host_tls_tcp_proto(self): + host_value = 'tcp://myhost.docker.net:3348' + expected_result = 'https://myhost.docker.net:3348' + assert parse_host(host_value, tls=True) == expected_result class ParseRepositoryTagTest(base.BaseTestCase):