diff --git a/agkyra/syncer/setup.py b/agkyra/syncer/setup.py index 5ac804ea1a623bd63ccecd55819347b1c4cdb0c8..34517be1292810762ce4b71a0b9671811b014412 100644 --- a/agkyra/syncer/setup.py +++ b/agkyra/syncer/setup.py @@ -22,7 +22,7 @@ from agkyra.syncer.database import SqliteFileStateDB from agkyra.syncer.messaging import Messager from agkyra.syncer import utils -from kamaki.clients import ClientError +from kamaki.clients import ClientError, KamakiSSLError from kamaki.clients.astakos import AstakosClient from kamaki.clients.pithos import PithosClient @@ -50,6 +50,23 @@ def get_instance(elems): return utils.hash_string(data) +def ssl_fall_back(method): + """Catch an SSL error while executing a method, patch kamaki and retry""" + def wrap(self, *args, **kwargs): + try: + return method(self, *args, **kwargs) + except KamakiSSLError as ssle: + 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()) + return method(self, *args, **kwargs) + wrap.__name__ = method.__name__ + wrap.__doc__ = method.__doc__ + return wrap + + class SyncerSettings(): def __init__(self, auth_url, auth_token, container, local_root_path, *args, **kwargs): @@ -155,6 +172,7 @@ class SyncerSettings(): os.mkdir(path) return path + @ssl_fall_back def _get_pithos_client(self, auth_url, token, container): try: astakos = AstakosClient(auth_url, token) @@ -176,8 +194,8 @@ class SyncerSettings(): client.get_container_info(container) except ClientError as e: if e.status == 404: - logger.warning("Container '%s' does not exist, creating..." - % container) + logger.warning( + "Container '%s' does not exist, creating..." % container) try: client.create_container(container) except ClientError: diff --git a/setup.py b/setup.py index 4d32e98796cd9e5ed9c47d197fcb5bef8b22d10a..8cbfae1cdeccbf1e7a0dd1c58a7b539aaf10a834 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ INSTALL_REQUIRES = [ 'watchdog', 'psutil', 'ws4py', + 'certifi', ] EXTRAS_REQUIRES = {