def sync_via_synchronizer_and_soledad(test, db_source, db_target, trace_hook=None, trace_hook_shallow=None): if trace_hook: test.skipTest("full trace hook unsupported over http") path = test._http_at[db_target] target = SoledadHTTPSyncTarget.connect( test.getURL(path), test._soledad._crypto) target.set_token_credentials('user-uuid', 'auth-token') if trace_hook_shallow: target._set_trace_hook_shallow(trace_hook_shallow) return sync.Synchronizer(db_source, target).sync()
def _get_syncer(self, url, creds=None): """ Get a synchronizer for ``url`` using ``creds``. :param url: The url of the target replica to sync with. :type url: str :param creds: optional dictionary giving credentials. to authorize the operation with the server. :type creds: dict :return: A synchronizer. :rtype: Synchronizer """ return SoledadSynchronizer( self, SoledadHTTPSyncTarget( url, # XXX is the replica_uid ready? self._replica_uid, creds=creds, crypto=self._crypto, cert_file=self._cert_file))
def _get_syncer(self, url, creds=None): """ Get a synchronizer for ``url`` using ``creds``. :param url: The url of the target replica to sync with. :type url: str :param creds: optional dictionary giving credentials. to authorize the operation with the server. :type creds: dict :return: A synchronizer. :rtype: Synchronizer """ # we want to store at most one syncer for each url, so we also store a # hash of the connection credentials and replace the stored syncer for # a certain url if credentials have changed. h = sha256(json.dumps([url, creds])).hexdigest() cur_h, syncer = self._syncers.get(url, (None, None)) if syncer is None or h != cur_h: syncer = SoledadSynchronizer( self, SoledadHTTPSyncTarget( url, # XXX is the replica_uid ready? self._replica_uid, creds=creds, crypto=self._crypto, cert_file=self._cert_file, sync_db=self._sync_db, sync_enc_pool=self._sync_enc_pool)) self._syncers[url] = (h, syncer) # in order to reuse the same synchronizer multiple times we have to # reset its state (i.e. the number of documents received from target # and inserted in the local replica). syncer.num_inserted = 0 return syncer