Skip to content

Commit 81edb39

Browse files
committed
Merge pull request #999 from docker/tcp-to-https-parsehost
If TCP host is provided while TLS is enabled, convert to https
2 parents 41acd70 + 3168149 commit 81edb39

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

docker/utils/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,12 @@ def parse_host(addr, platform=None, tls=False):
400400

401401
if addr == 'tcp://':
402402
raise errors.DockerException(
403-
"Invalid bind address format: {0}".format(addr))
403+
"Invalid bind address format: {0}".format(addr)
404+
)
404405
elif addr.startswith('unix://'):
405406
addr = addr[7:]
406407
elif addr.startswith('tcp://'):
407-
proto = "http"
408+
proto = 'http{0}'.format('s' if tls else '')
408409
addr = addr[6:]
409410
elif addr.startswith('https://'):
410411
proto = "https"

tests/unit/utils_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,12 @@ def test_parse_host_empty_value(self):
412412
def test_parse_host_tls(self):
413413
host_value = 'myhost.docker.net:3348'
414414
expected_result = 'https://myhost.docker.net:3348'
415-
self.assertEqual(parse_host(host_value, None, True), expected_result)
415+
assert parse_host(host_value, tls=True) == expected_result
416+
417+
def test_parse_host_tls_tcp_proto(self):
418+
host_value = 'tcp://myhost.docker.net:3348'
419+
expected_result = 'https://myhost.docker.net:3348'
420+
assert parse_host(host_value, tls=True) == expected_result
416421

417422

418423
class ParseRepositoryTagTest(base.BaseTestCase):

0 commit comments

Comments
 (0)