summaryrefslogtreecommitdiff
path: root/src/leap/soledad/backends
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/soledad/backends')
-rw-r--r--src/leap/soledad/backends/couch.py17
-rw-r--r--src/leap/soledad/backends/leap_backend.py45
2 files changed, 27 insertions, 35 deletions
diff --git a/src/leap/soledad/backends/couch.py b/src/leap/soledad/backends/couch.py
index 95090510..4dcea3f8 100644
--- a/src/leap/soledad/backends/couch.py
+++ b/src/leap/soledad/backends/couch.py
@@ -387,7 +387,8 @@ class CouchDatabase(ObjectStoreDatabase):
indexes = {}
for name, idx in self._indexes.iteritems():
indexes[name] = {}
- for attr in [INDEX_NAME_KEY, INDEX_DEFINITION_KEY, INDEX_VALUES_KEY]:
+ for attr in [self.INDEX_NAME_KEY, self.INDEX_DEFINITION_KEY,
+ self.INDEX_VALUES_KEY]:
indexes[name][attr] = getattr(idx, '_' + attr)
return json.dumps(indexes)
@@ -404,8 +405,8 @@ class CouchDatabase(ObjectStoreDatabase):
"""
dict = {}
for name, idx_dict in json.loads(indexes).iteritems():
- idx = InMemoryIndex(name, idx_dict[INDEX_DEFINITION_KEY])
- idx._values = idx_dict[INDEX_VALUES_KEY]
+ idx = InMemoryIndex(name, idx_dict[self.INDEX_DEFINITION_KEY])
+ idx._values = idx_dict[self.INDEX_VALUES_KEY]
dict[name] = idx
return dict
@@ -435,8 +436,9 @@ class CouchServerState(ServerState):
@rtype: CouchDatabase
"""
# TODO: open couch
- return CouchDatabase.open_database(self.couch_url + '/' + dbname,
- create=False)
+ return CouchDatabase.open_database(
+ self.couch_url + '/' + dbname,
+ create=False)
def ensure_database(self, dbname):
"""
@@ -448,8 +450,9 @@ class CouchServerState(ServerState):
@return: The CouchDatabase object and the replica uid.
@rtype: (CouchDatabase, str)
"""
- db = CouchDatabase.open_database(self.couch_url + '/' + dbname,
- create=True)
+ db = CouchDatabase.open_database(
+ self.couch_url + '/' + dbname,
+ create=True)
return db, db._replica_uid
def delete_database(self, dbname):
diff --git a/src/leap/soledad/backends/leap_backend.py b/src/leap/soledad/backends/leap_backend.py
index 9750ffad..81f6c211 100644
--- a/src/leap/soledad/backends/leap_backend.py
+++ b/src/leap/soledad/backends/leap_backend.py
@@ -30,33 +30,22 @@ except ImportError:
from u1db import Document
from u1db.remote import utils
-from u1db.remote.http_target import HTTPSyncTarget
-from u1db.remote.http_database import HTTPDatabase
from u1db.errors import BrokenSyncStream
+from u1db.remote.http_target import HTTPSyncTarget
from leap.common.keymanager import KeyManager
from leap.common.check import leap_assert
+from leap.soledad.auth import (
+ set_token_credentials,
+ _sign_request,
+)
#
# Exceptions
#
-class NoDefaultKey(Exception):
- """
- Exception to signal that there's no default OpenPGP key configured.
- """
- pass
-
-
-class NoSoledadCryptoInstance(Exception):
- """
- Exception to signal that no Soledad instance was found.
- """
- pass
-
-
class DocumentNotEncrypted(Exception):
"""
Raised for failures in document encryption.
@@ -267,6 +256,18 @@ class LeapSyncTarget(HTTPSyncTarget):
receiving.
"""
+ #
+ # Token auth methods.
+ #
+
+ set_token_credentials = set_token_credentials
+
+ _sign_request = _sign_request
+
+ #
+ # Modified HTTPSyncTarget methods.
+ #
+
@staticmethod
def connect(url, crypto=None):
return LeapSyncTarget(url, crypto=crypto)
@@ -403,15 +404,3 @@ class LeapSyncTarget(HTTPSyncTarget):
res = self._parse_sync_stream(data, return_doc_cb, ensure_callback)
data = None
return res['new_generation'], res['new_transaction_id']
-
- def set_token_credentials(self, address, token):
- self._creds = {'token': (address, token)}
-
- def _sign_request(self, method, url_query, params):
- if 'token' in self._creds:
- address, token = self._creds['token']
- auth = '%s:%s' % (address, token)
- return [('Authorization', 'Token %s' % auth.encode('base64'))]
- else:
- return HTTPSyncTarget._sign_request(
- self, method, url_query, params)