mirror of https://github.com/docker/docker-py.git
Update parse_host and tests
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
d922713923
commit
0176fa171f
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import struct
|
import struct
|
||||||
import sys
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
@ -63,7 +62,9 @@ class Client(
|
||||||
|
|
||||||
self._auth_configs = auth.load_config()
|
self._auth_configs = auth.load_config()
|
||||||
|
|
||||||
base_url = utils.parse_host(base_url, sys.platform, tls=bool(tls))
|
base_url = utils.parse_host(
|
||||||
|
base_url, constants.IS_WINDOWS_PLATFORM, tls=bool(tls)
|
||||||
|
)
|
||||||
if base_url.startswith('http+unix://'):
|
if base_url.startswith('http+unix://'):
|
||||||
self._custom_adapter = UnixAdapter(base_url, timeout)
|
self._custom_adapter = UnixAdapter(base_url, timeout)
|
||||||
self.mount('http+docker://', self._custom_adapter)
|
self.mount('http+docker://', self._custom_adapter)
|
||||||
|
|
|
@ -383,13 +383,13 @@ 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, tls=False):
|
def parse_host(addr, is_win32=False, tls=False):
|
||||||
proto = "http+unix"
|
proto = "http+unix"
|
||||||
host = DEFAULT_HTTP_HOST
|
host = DEFAULT_HTTP_HOST
|
||||||
port = None
|
port = None
|
||||||
path = ''
|
path = ''
|
||||||
|
|
||||||
if not addr and platform == 'win32':
|
if not addr and is_win32:
|
||||||
addr = '{0}:{1}'.format(DEFAULT_HTTP_HOST, 2375)
|
addr = '{0}:{1}'.format(DEFAULT_HTTP_HOST, 2375)
|
||||||
|
|
||||||
if not addr or addr.strip() == 'unix://':
|
if not addr or addr.strip() == 'unix://':
|
||||||
|
|
|
@ -388,6 +388,7 @@ class ParseHostTest(base.BaseTestCase):
|
||||||
'somehost.net:80/service/swarm': (
|
'somehost.net:80/service/swarm': (
|
||||||
'http://somehost.net:80/service/swarm'
|
'http://somehost.net:80/service/swarm'
|
||||||
),
|
),
|
||||||
|
'npipe:////./pipe/docker_engine': 'npipe:////./pipe/docker_engine',
|
||||||
}
|
}
|
||||||
|
|
||||||
for host in invalid_hosts:
|
for host in invalid_hosts:
|
||||||
|
@ -402,10 +403,8 @@ class ParseHostTest(base.BaseTestCase):
|
||||||
tcp_port = 'http://127.0.0.1:2375'
|
tcp_port = 'http://127.0.0.1:2375'
|
||||||
|
|
||||||
for val in [None, '']:
|
for val in [None, '']:
|
||||||
for platform in ['darwin', 'linux2', None]:
|
assert parse_host(val, is_win32=False) == unix_socket
|
||||||
assert parse_host(val, platform) == unix_socket
|
assert parse_host(val, is_win32=True) == tcp_port
|
||||||
|
|
||||||
assert parse_host(val, 'win32') == tcp_port
|
|
||||||
|
|
||||||
def test_parse_host_tls(self):
|
def test_parse_host_tls(self):
|
||||||
host_value = 'myhost.docker.net:3348'
|
host_value = 'myhost.docker.net:3348'
|
||||||
|
|
Loading…
Reference in New Issue