summaryrefslogtreecommitdiff
path: root/src/leap/soledad/backends
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-05-04 10:46:46 -0300
committerdrebs <drebs@leap.se>2013-05-04 10:46:46 -0300
commit6904b5f21fb680b94fcf5ec38c295c4823e31445 (patch)
treeca4d29315c9e14a4680a5055a60cdeb6b4f3ba60 /src/leap/soledad/backends
parent08b4d702d4c3d7427d8f794fa3176a5c63a52d18 (diff)
Encapsulate token-based auth in a class.
Diffstat (limited to 'src/leap/soledad/backends')
-rw-r--r--src/leap/soledad/backends/leap_backend.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/leap/soledad/backends/leap_backend.py b/src/leap/soledad/backends/leap_backend.py
index 46c787a9..2585379a 100644
--- a/src/leap/soledad/backends/leap_backend.py
+++ b/src/leap/soledad/backends/leap_backend.py
@@ -35,10 +35,7 @@ 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,
-)
+from leap.soledad.auth import TokenBasedAuth
#
# Exceptions
@@ -249,7 +246,7 @@ class LeapDocument(Document):
# LeapSyncTarget
#
-class LeapSyncTarget(HTTPSyncTarget):
+class LeapSyncTarget(HTTPSyncTarget, TokenBasedAuth):
"""
A SyncTarget that encrypts data before sending and decrypts data after
receiving.
@@ -259,9 +256,32 @@ class LeapSyncTarget(HTTPSyncTarget):
# Token auth methods.
#
- set_token_credentials = set_token_credentials
+ def set_token_credentials(self, uuid, token):
+ """
+ Store given credentials so we can sign the request later.
+
+ @param uuid: The user's uuid.
+ @type uuid: str
+ @param token: The authentication token.
+ @type token: str
+ """
+ TokenBasedAuth.set_token_credentials(self, uuid, token)
- _sign_request = _sign_request
+ def _sign_request(self, method, url_query, params):
+ """
+ Return an authorization header to be included in the HTTP request.
+
+ @param method: The HTTP method.
+ @type method: str
+ @param url_query: The URL query string.
+ @type url_query: str
+ @param params: A list with encoded query parameters.
+ @type param: list
+
+ @return: The Authorization header.
+ @rtype: list of tuple
+ """
+ return TokenBasedAuth._sign_request(self, method, url_query, params)
#
# Modified HTTPSyncTarget methods.