From 729b7ad0bf3606e11cdec647c6d8d2b7bbd80147 Mon Sep 17 00:00:00 2001
From: Giorgos Korfiatis <gkorf@grnet.gr>
Date: Fri, 11 Sep 2015 15:01:03 +0300
Subject: [PATCH] properly patch with local cacert

---
 agkyra/syncer/setup.py | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/agkyra/syncer/setup.py b/agkyra/syncer/setup.py
index 4239ade..9b13842 100644
--- a/agkyra/syncer/setup.py
+++ b/agkyra/syncer/setup.py
@@ -32,6 +32,9 @@ from kamaki.clients.astakos import AstakosClient
 from kamaki.clients.pithos import PithosClient
 from kamaki.clients.utils import https
 
+# this will be deleted when kamaki 0.13.5 is out
+from kamaki.clients.astakos import AstakosClientError
+
 logger = logging.getLogger(__name__)
 
 
@@ -59,7 +62,6 @@ else:
     ISFROZEN = False
 
 RESOURCES = os.path.join(BASEDIR, 'resources')
-https.patch_with_certs(os.path.join(RESOURCES, 'cacert.pem'))
 
 def get_instance(elems):
     data = "".join(elems)
@@ -76,9 +78,19 @@ def ssl_fall_back(method):
             logger.debug('Kamaki SSL failed %s' % ssle)
             logger.info(
                 'Kamaki SSL failed, fall back to certifi (mozilla certs)')
-            import certifi
-            https.patch_with_certs(certifi.where())
+            https.patch_with_certs(os.path.join(RESOURCES, 'cacert.pem'))
             return method(self, *args, **kwargs)
+        # this will be deleted when kamaki 0.13.5 is out
+        except AstakosClientError as ace:
+            logger.debug('Kamaki failed with error %s' % ace)
+            if '[Errno 2]' in ace.message:
+                logger.info(
+                    'Kamaki SSL failed with AstakosClientError [Errno 2], '
+                    'fall back to certifi (mozilla certs)')
+                https.patch_with_certs(os.path.join(RESOURCES, 'cacert.pem'))
+                return method(self, *args, **kwargs)
+            else:
+                raise
     return wrap
 
 
-- 
GitLab