Kaydet (Commit) ff1f11b1 authored tarafından Sam Alba's avatar Sam Alba

Merge pull request #347 from aanand/override-assert-hostname

Enable the overriding of `assert_hostname` on TLSConfig
...@@ -15,19 +15,27 @@ PoolManager = urllib3.poolmanager.PoolManager ...@@ -15,19 +15,27 @@ PoolManager = urllib3.poolmanager.PoolManager
class SSLAdapter(HTTPAdapter): class SSLAdapter(HTTPAdapter):
'''An HTTPS Transport Adapter that uses an arbitrary SSL version.''' '''An HTTPS Transport Adapter that uses an arbitrary SSL version.'''
def __init__(self, ssl_version=None, **kwargs): def __init__(self, ssl_version=None, assert_hostname=None, **kwargs):
self.ssl_version = ssl_version self.ssl_version = ssl_version
self.assert_hostname = assert_hostname
super(SSLAdapter, self).__init__(**kwargs) super(SSLAdapter, self).__init__(**kwargs)
def init_poolmanager(self, connections, maxsize, block=False): def init_poolmanager(self, connections, maxsize, block=False):
urllib_ver = urllib3.__version__.split('-')[0]
kwargs = { kwargs = {
'num_pools': connections, 'num_pools': connections,
'maxsize': maxsize, 'maxsize': maxsize,
'block': block 'block': block,
'assert_hostname': self.assert_hostname,
} }
if urllib3 and urllib_ver == 'dev' and \ if self.can_override_ssl_version():
StrictVersion(urllib_ver) > StrictVersion('1.5'):
kwargs['ssl_version'] = self.ssl_version kwargs['ssl_version'] = self.ssl_version
self.poolmanager = PoolManager(**kwargs) self.poolmanager = PoolManager(**kwargs)
def can_override_ssl_version(self):
urllib_ver = urllib3.__version__.split('-')[0]
if urllib_ver is None:
return False
if urllib_ver == 'dev':
return True
return StrictVersion(urllib_ver) > StrictVersion('1.5')
...@@ -10,7 +10,7 @@ class TLSConfig(object): ...@@ -10,7 +10,7 @@ class TLSConfig(object):
ssl_version = None ssl_version = None
def __init__(self, client_cert=None, ca_cert=None, verify=None, def __init__(self, client_cert=None, ca_cert=None, verify=None,
ssl_version=None): ssl_version=None, assert_hostname=None):
# Argument compatibility/mapping with # Argument compatibility/mapping with
# http://docs.docker.com/examples/https/ # http://docs.docker.com/examples/https/
# This diverges from the Docker CLI in that users can specify 'tls' # This diverges from the Docker CLI in that users can specify 'tls'
...@@ -20,6 +20,7 @@ class TLSConfig(object): ...@@ -20,6 +20,7 @@ class TLSConfig(object):
# urllib3 sets a default ssl_version if ssl_version is None # urllib3 sets a default ssl_version if ssl_version is None
# http://tinyurl.com/kxga8hb # http://tinyurl.com/kxga8hb
self.ssl_version = ssl_version self.ssl_version = ssl_version
self.assert_hostname = assert_hostname
# "tls" and "tls_verify" must have both or neither cert/key files # "tls" and "tls_verify" must have both or neither cert/key files
# In either case, Alert the user when both are expected, but any are # In either case, Alert the user when both are expected, but any are
...@@ -65,4 +66,7 @@ class TLSConfig(object): ...@@ -65,4 +66,7 @@ class TLSConfig(object):
client.verify = self.verify client.verify = self.verify
if self.cert: if self.cert:
client.cert = self.cert client.cert = self.cert
client.mount('https://', ssladapter.SSLAdapter(self.ssl_version)) client.mount('https://', ssladapter.SSLAdapter(
ssl_version=self.ssl_version,
assert_hostname=self.assert_hostname,
))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment