diff options
author | drebs <drebs@leap.se> | 2013-05-04 10:46:46 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-05-04 10:46:46 -0300 |
commit | 6904b5f21fb680b94fcf5ec38c295c4823e31445 (patch) | |
tree | ca4d29315c9e14a4680a5055a60cdeb6b4f3ba60 /src/leap/soledad/shared_db.py | |
parent | 08b4d702d4c3d7427d8f794fa3176a5c63a52d18 (diff) |
Encapsulate token-based auth in a class.
Diffstat (limited to 'src/leap/soledad/shared_db.py')
-rw-r--r-- | src/leap/soledad/shared_db.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/leap/soledad/shared_db.py b/src/leap/soledad/shared_db.py index 419d8017..3929e828 100644 --- a/src/leap/soledad/shared_db.py +++ b/src/leap/soledad/shared_db.py @@ -29,10 +29,7 @@ except ImportError: from u1db.remote import http_database, http_client -from leap.soledad.auth import ( - set_token_credentials, - _sign_request, -) +from leap.soledad.auth import TokenBasedAuth SOLEDAD_CERT = None @@ -78,7 +75,7 @@ class Unauthorized(Exception): """ -class SoledadSharedDatabase(http_database.HTTPDatabase): +class SoledadSharedDatabase(http_database.HTTPDatabase, TokenBasedAuth): """ This is a shared recovery database that enables users to store their encryption secrets in the server and retrieve them afterwards. @@ -90,9 +87,32 @@ class SoledadSharedDatabase(http_database.HTTPDatabase): # 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 HTTPDatabase methods. |