@@ -69,9 +69,18 @@ def is_server_error(self):
69
69
70
70
71
71
class Client (requests .Session ):
72
- def __init__ (self , base_url = None , version = DEFAULT_DOCKER_API_VERSION ,
73
- timeout = DEFAULT_TIMEOUT_SECONDS ):
72
+ def __init__ (self ,
73
+ base_url = None ,
74
+ version = DEFAULT_DOCKER_API_VERSION ,
75
+ timeout = DEFAULT_TIMEOUT_SECONDS ,
76
+ tls = False ,
77
+ tls_cert = None ,
78
+ tls_key = None ):
74
79
super (Client , self ).__init__ ()
80
+ if tls and not (tls_cert and tls_key ):
81
+ raise RuntimeError ('tls_key and tls_cert are required.' )
82
+ if tls and not base_url .startswith ('https' ):
83
+ raise RuntimeError ('TLS: base_url has to start with https://' )
75
84
if base_url is None :
76
85
base_url = "http+unix://var/run/docker.sock"
77
86
if 'unix:///' in base_url :
@@ -87,7 +96,12 @@ def __init__(self, base_url=None, version=DEFAULT_DOCKER_API_VERSION,
87
96
self ._timeout = timeout
88
97
self ._auth_configs = auth .load_config ()
89
98
90
- self .mount ('http+unix://' , unixconn .UnixAdapter (base_url , timeout ))
99
+ if tls :
100
+ self .cert = (tls_cert , tls_key )
101
+ self .verify = False # We assume the server.crt will we self signed
102
+ self .mount ('https://' , requests .adapters .HTTPAdapter ())
103
+ else :
104
+ self .mount ('http+unix://' , unixconn .UnixAdapter (base_url , timeout ))
91
105
92
106
def _set_request_timeout (self , kwargs ):
93
107
"""Prepare the kwargs for an HTTP request by inserting the timeout
0 commit comments