summaryrefslogtreecommitdiff
path: root/client/src/leap/soledad/client/api.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/leap/soledad/client/api.py')
-rw-r--r--client/src/leap/soledad/client/api.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py
index 76d6acc3..63b1dfc0 100644
--- a/client/src/leap/soledad/client/api.py
+++ b/client/src/leap/soledad/client/api.py
@@ -42,6 +42,7 @@ except ImportError:
from StringIO import StringIO
from u1db.remote import http_client
from u1db.remote.ssl_match_hostname import match_hostname
+from twisted.plugin import getPlugins
from zope.interface import implements
from leap.common.config import get_path_prefix
@@ -70,6 +71,28 @@ Soledad client and server.
"""
SOLEDAD_CERT = None
+# A whitelist of modules from where to collect plugins dynamically.
+# For the moment restricted to leap namespace, but the idea is that we can pass
+# other "trusted" modules as options to the initialization of soledad.
+PLUGGABLE_LEAP_MODULES = ('mail', 'keymanager')
+
+
+# TODO move to leap.common
+
+def collect_plugins(interface):
+ """
+ Traverse a whitelist of modules and collect all the plugins that implement
+ the passed interface.
+ """
+ plugins = []
+ for namespace in PLUGGABLE_LEAP_MODULES:
+ try:
+ module = __import__('leap.%s.plugins' % namespace, fromlist='.')
+ plugins = plugins + list(getPlugins(interface, module))
+ except ImportError:
+ pass
+ return plugins
+
class Soledad(object):
"""
@@ -656,6 +679,20 @@ class Soledad(object):
defer_decryption=defer_decryption)
def _sync_callback(local_gen):
+ self._last_received_docs = self._dbsyncer.received_docs
+ print "***"
+ print "LAST RECEIVED (API)", self._last_received_docs
+ print "***"
+ received_doc_ids = self._dbsyncer.received_docs
+
+ # Post-Sync Hooks
+ synced_plugin = soledad_interfaces.ISoledadPostSyncPlugin
+ if received_doc_ids:
+ suitable_plugins = collect_plugins(synced_plugin)
+ for plugin in suitable_plugins:
+ # TODO filter the doc_ids here
+ plugin.process_received_docs(received_doc_ids)
+
soledad_events.emit(
soledad_events.SOLEDAD_DONE_DATA_SYNC, self.uuid)
return local_gen