示例#1
0
    def _get_syncer(self, url, creds=None):
        """
        Get a synchronizer for C{url} using C{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:
            wlock = self._sync_db_write_lock
            syncer = SoledadSynchronizer(
                self,
                SoledadSyncTarget(url,
                                  self._replica_uid,
                                  creds=creds,
                                  crypto=self._crypto,
                                  sync_db=self._sync_db,
                                  sync_db_write_lock=wlock))
            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
    def do_sync(self, target_name):
        """
        Perform sync using SoledadSynchronizer, SoledadSyncTarget
        and Token auth.
        """
        if self.token:
            extra = dict(creds={
                'token': {
                    'uuid': 'user-uuid',
                    'token': 'auth-token',
                }
            })
            target_url = self.getURL(target_name)
            syncdb = getattr(self.db1, "_sync_db", None)

            syncer = SoledadSynchronizer(
                self.db1,
                target.SoledadSyncTarget(target_url,
                                         crypto=self._soledad._crypto,
                                         sync_db=syncdb,
                                         **extra))
            # Keep a reference to be able to know when the sync
            # has finished.
            self.syncer = syncer
            return syncer.sync(autocreate=True,
                               defer_decryption=DEFER_DECRYPTION)
        else:
            return test_sync.TestDbSync.do_sync(self, target_name)
示例#3
0
 def do_sync(self, target_name):
     """
     Perform sync using SoledadSynchronizer, SoledadSyncTarget
     and Token auth.
     """
     extra = {}
     extra = dict(
         creds={'token': {
             'uuid': 'user-uuid',
             'token': 'auth-token',
         }})
     target_url = self.getURL(target_name)
     return SoledadSynchronizer(
         self.db,
         target.SoledadSyncTarget(target_url,
                                  crypto=self._soledad._crypto,
                                  **extra)).sync(autocreate=True,
                                                 defer_decryption=False)
示例#4
0
    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))