memory: Sessions.newSession can be called with a forced session ID

This commit is contained in:
souliane 2014-09-21 13:10:55 +02:00
commit 830b6d8ef6

View file

@ -47,14 +47,16 @@ class Sessions(object):
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 @@ class Memory(object):
"""
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 @@ class Memory(object):
@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