Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions docker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,18 @@ def is_server_error(self):


class Client(requests.Session):
def __init__(self, base_url=None, version=DEFAULT_DOCKER_API_VERSION,
timeout=DEFAULT_TIMEOUT_SECONDS):
def __init__(self,
base_url=None,
version=DEFAULT_DOCKER_API_VERSION,
timeout=DEFAULT_TIMEOUT_SECONDS,
tls=False,
tls_cert=None,
tls_key=None):
super(Client, self).__init__()
if tls and not (tls_cert and tls_key):
raise RuntimeError('tls_key and tls_cert are required.')
if tls and not base_url.startswith('https'):
raise RuntimeError('TLS: base_url has to start with https://')
if base_url is None:
base_url = "http+unix://var/run/docker.sock"
if 'unix:///' in base_url:
Expand All @@ -87,7 +96,12 @@ def __init__(self, base_url=None, version=DEFAULT_DOCKER_API_VERSION,
self._timeout = timeout
self._auth_configs = auth.load_config()

self.mount('http+unix://', unixconn.UnixAdapter(base_url, timeout))
if tls:
self.cert = (tls_cert, tls_key)
self.verify = False # We assume the server.crt will we self signed
self.mount('https://', requests.adapters.HTTPAdapter())
else:
self.mount('http+unix://', unixconn.UnixAdapter(base_url, timeout))

def _set_request_timeout(self, kwargs):
"""Prepare the kwargs for an HTTP request by inserting the timeout
Expand Down