libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [2/5] libcloud git commit: committed fix
Date Sun, 02 Apr 2017 01:55:21 GMT
committed fix


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/3637d7cc
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/3637d7cc
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/3637d7cc

Branch: refs/heads/trunk
Commit: 3637d7cc1c8b0f852edfad5ed3f7a6f808c2b788
Parents: 64e0b3c
Author: Anthony Shaw <anthonyshaw@apache.org>
Authored: Sun Apr 2 11:37:30 2017 +1000
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Sun Apr 2 11:37:30 2017 +1000

----------------------------------------------------------------------
 libcloud/httplib_ssl.py | 66 ++++++++++----------------------------------
 1 file changed, 14 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/3637d7cc/libcloud/httplib_ssl.py
----------------------------------------------------------------------
diff --git a/libcloud/httplib_ssl.py b/libcloud/httplib_ssl.py
index a88ea0d..cf1c749 100644
--- a/libcloud/httplib_ssl.py
+++ b/libcloud/httplib_ssl.py
@@ -22,7 +22,7 @@ import os
 import warnings
 import requests
 from requests.adapters import HTTPAdapter
-from requests.packages.urllib3.util.ssl_ import create_urllib3_context
+from requests.packages.urllib3.poolmanager import PoolManager
 
 import libcloud.security
 from libcloud.utils.py3 import urlparse, PY3
@@ -38,57 +38,18 @@ ALLOW_REDIRECTS = 1
 HTTP_PROXY_ENV_VARIABLE_NAME = 'http_proxy'
 
 
-class SignedX509Adapter(HTTPAdapter):
-    def __init__(self, cert_file=None, key_file=None):
+class SignedHTTPSAdapter(HTTPAdapter):
+    def __init__(self, cert_file, key_file):
         self.cert_file = cert_file
         self.key_file = key_file
+        super(SignedX509Adapter, self).__init__()
 
-    def init_poolmanager(self, *args, **kwargs):
-        self.tls_context = create_urllib3_context()
-        kwargs['ssl_context'] = self.tls_context
-        
-        has_sni = getattr(ssl, 'HAS_SNI', False)
-
-        if has_sni:
-            self.tls_context.verify_mode = ssl.CERT_REQUIRED
-
-            if self.cert_file and self.key_file:
-                self.tls_context.load_cert_chain(
-                    certfile=self.cert_file,
-                    keyfile=self.key_file,
-                    password=None)
-
-            if self.ca_cert:
-                self.tls_context.load_verify_locations(cafile=self.ca_cert)
-
-            try:
-                self.sock = self.tls_context.wrap_socket(
-                    sock,
-                    server_hostname=self.host,
-                )
-            except:
-                exc = sys.exc_info()[1]
-                exc = get_socket_error_exception(ssl_version=ssl_version,
-                                                 exc=exc)
-                raise exc
-        else:
-            # SNI support not available
-            try:
-                self.sock = ssl.wrap_socket(
-                    sock,
-                    self.key_file,
-                    self.cert_file,
-                    cert_reqs=ssl.CERT_REQUIRED,
-                    ca_certs=self.ca_cert,
-                    ssl_version=ssl_version
-                )
-            except:
-                exc = sys.exc_info()[1]
-                exc = get_socket_error_exception(ssl_version=ssl_version,
-                                                 exc=exc)
-                raise exc
-        
-        return super(HTTPAdapter, self).init_poolmanager(*args, **kwargs)
+    def init_poolmanager(self, connections, maxsize, block=False):
+        self.poolmanager = PoolManager(
+            num_pools=connections, maxsize=maxsize,
+            block=block,
+            cert_file=self.cert_file,
+            key_file=self.key_file)
 
 
 class LibcloudBaseConnection(object):
@@ -199,7 +160,7 @@ class LibcloudBaseConnection(object):
         Setup request signing by mounting a signing
         adapter to the session
         """
-        self.session.mount("https", SignedX509Adapter(cert_file, key_file))
+        self.session.mount('https://', SignedHTTPSAdapter(cert_file, key_file))
 
 
 class LibcloudConnection(LibcloudBaseConnection):
@@ -220,11 +181,12 @@ class LibcloudConnection(LibcloudBaseConnection):
 
         self._setup_verify()
         self._setup_ca_cert()
-        
+
         LibcloudBaseConnection.__init__(self)
-        
+
         if 'cert_file' in kwargs or 'key_file' in kwargs:
             self._setup_signing(**kwargs)
+
         if proxy_url:
             self.set_http_proxy(proxy_url=proxy_url)
         self.session.timeout = kwargs.get('timeout', 60)


Mime
View raw message