Mercurial > libervia-backend
diff src/memory/memory.py @ 1212:628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 21 Sep 2014 13:10:55 +0200 |
parents | 96fb74a4714d |
children | b5928601d7aa |
line wrap: on
line diff
--- a/src/memory/memory.py Sun Sep 21 13:06:53 2014 +0200 +++ b/src/memory/memory.py Sun Sep 21 13:10:55 2014 +0200 @@ -47,14 +47,16 @@ self._sessions = dict() self.timeout = timeout or Sessions.DEFAULT_TIMEOUT - def newSession(self, session_data=None, profile=None): + def newSession(self, session_data=None, session_id=None, profile=None): """ Create a new session @param session_data: mutable data to use, default to a dict + @param session_id (str): force the session_id to the given string @param profile: if set, the session is owned by the profile, and profileGet must be used instead of __getitem__ @return: session_id, session_data """ - session_id = str(uuid4()) + if session_id is None: + session_id = str(uuid4()) timer = reactor.callLater(self.timeout, self._purgeSession, session_id) if session_data is None: session_data = {} @@ -268,7 +270,7 @@ """ def gotPersonalKey(personal_key): """Create the session for this profile and store the personal key""" - self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile) + self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=profile) log.debug('auth session created for profile %s' % profile) d = PersistentDict(C.MEMORY_CRYPTO_NAMESPACE, profile).load() @@ -319,7 +321,7 @@ @return: Deferred """ personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict - self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, name) # will be encrypted by setParam + self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam d = self.params.asyncCreateProfile(name) d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name)) return d