Skip to content

Commit 94cb0bd

Browse files
committed
Fixed bugs, clearer error messages
1 parent 72c29ee commit 94cb0bd

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

docker/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, base_url=None, version=DEFAULT_DOCKER_API_VERSION,
6161
self._timeout = timeout
6262
self._auth_configs = auth.load_config()
6363

64-
""" Use SSLAdapter for the ability to specify SSL version """
64+
# Use SSLAdapter for the ability to specify SSL version
6565
if isinstance(tls, TLSConfig):
6666
tls.configure_client(self)
6767
elif tls:

docker/tls.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66

77
class TLSConfig(object):
8+
cert = None
9+
verify = None
10+
ssl_version = None
11+
812
def __init__(self, tls, tls_cert=None, tls_key=None, tls_verify=False,
913
tls_ca_cert=None, ssl_version=None):
1014
# Argument compatibility/mapping with
@@ -25,11 +29,12 @@ def __init__(self, tls, tls_cert=None, tls_key=None, tls_verify=False,
2529
if not (tls_cert and tls_key) or (not os.path.isfile(tls_cert) or
2630
not os.path.isfile(tls_key)):
2731
raise errors.TLSParameterError(
28-
'You must provide either both "tls_cert"/"tls_key" files, '
29-
'or neither, in order to use TLS.')
32+
'Client certificate must provide certificate and key files'
33+
' through tls_cert and tls_key params respectively'
34+
)
3035
self.cert = (tls_cert, tls_key)
3136

32-
# Either set tls_verify to True (public/default CA checks) or to the
37+
# Either set verify to True (public/default CA checks) or to the
3338
# path of a CA Cert file.
3439
if tls_verify:
3540
if not tls_ca_cert:
@@ -38,14 +43,13 @@ def __init__(self, tls, tls_cert=None, tls_key=None, tls_verify=False,
3843
self.verify = tls_ca_cert
3944
else:
4045
raise errors.TLSParameterError(
41-
'If "tls_verify" is set, then "tls_ca_cert" must be blank'
42-
' (to check public CA list) OR a path to a Cert File.'
46+
'Invalid CA certificate provided for `tls_ca_cert`.'
4347
)
44-
else:
45-
self.verify = False
4648

4749
def configure_client(self, client):
48-
client.verify = self.verify
4950
client.ssl_version = self.ssl_version
50-
client.cert = self.cert
51-
self.mount('https://', ssladapter.SSLAdapter(self.ssl_version))
51+
if self.verify is not None:
52+
client.verify = self.verify
53+
if self.cert:
54+
client.cert = self.cert
55+
client.mount('https://', ssladapter.SSLAdapter(self.ssl_version))

0 commit comments

Comments
 (0)