mirror of https://github.com/docker/docker-py.git
Support unspecified protocol in base_url when using TLS
(assume HTTPS) Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
446e6d08dd
commit
bb94fe7a8c
|
@ -45,17 +45,17 @@ class Client(
|
||||||
timeout=constants.DEFAULT_TIMEOUT_SECONDS, tls=False):
|
timeout=constants.DEFAULT_TIMEOUT_SECONDS, tls=False):
|
||||||
super(Client, self).__init__()
|
super(Client, self).__init__()
|
||||||
|
|
||||||
if tls and (not base_url or not base_url.startswith('https://')):
|
if tls and not base_url:
|
||||||
raise errors.TLSParameterError(
|
raise errors.TLSParameterError(
|
||||||
'If using TLS, the base_url argument must begin with '
|
'If using TLS, the base_url argument must be provided.'
|
||||||
'"https://".')
|
)
|
||||||
|
|
||||||
self.base_url = base_url
|
self.base_url = base_url
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
self._auth_configs = auth.load_config()
|
self._auth_configs = auth.load_config()
|
||||||
|
|
||||||
base_url = utils.parse_host(base_url, sys.platform)
|
base_url = utils.parse_host(base_url, sys.platform, tls=bool(tls))
|
||||||
if base_url.startswith('http+unix://'):
|
if base_url.startswith('http+unix://'):
|
||||||
self._custom_adapter = unixconn.UnixAdapter(base_url, timeout)
|
self._custom_adapter = unixconn.UnixAdapter(base_url, timeout)
|
||||||
self.mount('http+docker://', self._custom_adapter)
|
self.mount('http+docker://', self._custom_adapter)
|
||||||
|
|
|
@ -345,7 +345,7 @@ def parse_repository_tag(repo_name):
|
||||||
# fd:// protocol unsupported (for obvious reasons)
|
# fd:// protocol unsupported (for obvious reasons)
|
||||||
# Added support for http and https
|
# Added support for http and https
|
||||||
# Protocol translation: tcp -> http, unix -> http+unix
|
# Protocol translation: tcp -> http, unix -> http+unix
|
||||||
def parse_host(addr, platform=None):
|
def parse_host(addr, platform=None, tls=False):
|
||||||
proto = "http+unix"
|
proto = "http+unix"
|
||||||
host = DEFAULT_HTTP_HOST
|
host = DEFAULT_HTTP_HOST
|
||||||
port = None
|
port = None
|
||||||
|
@ -381,7 +381,7 @@ def parse_host(addr, platform=None):
|
||||||
raise errors.DockerException(
|
raise errors.DockerException(
|
||||||
"Invalid bind address protocol: {0}".format(addr)
|
"Invalid bind address protocol: {0}".format(addr)
|
||||||
)
|
)
|
||||||
proto = "http"
|
proto = "https" if tls else "http"
|
||||||
|
|
||||||
if proto != "http+unix" and ":" in addr:
|
if proto != "http+unix" and ":" in addr:
|
||||||
host_parts = addr.split(':')
|
host_parts = addr.split(':')
|
||||||
|
|
|
@ -360,6 +360,11 @@ class ParseHostTest(base.BaseTestCase):
|
||||||
|
|
||||||
assert parse_host(val, 'win32') == tcp_port
|
assert parse_host(val, 'win32') == tcp_port
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
class ParseRepositoryTagTest(base.BaseTestCase):
|
class ParseRepositoryTagTest(base.BaseTestCase):
|
||||||
sha = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
sha = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||||||
|
|
Loading…
Reference in New Issue