[auth] pass `repo` instead of `vreg` to SessionManager and AuthenticationManager
Those object actually need a repo object to connect and create new session
object. They used to retrieve the repo object using
``vreg.config.repository()``. I'm trying to sanitise the initialisation stack
and get ride of ``config.repository()``, a function that mix factory and cache.
Retrieving the vreg from the repo is trivial (``repo.vreg``) so we now pass the
repo object instead of the vreg.
--- a/doc/4.0.rst Fri Nov 23 16:12:19 2012 +0100
+++ b/doc/4.0.rst Mon Jun 24 12:00:03 2013 +0200
@@ -8,6 +8,9 @@
request and session. And this now happens before the session is linked to the
request.
+* ``SessionManager`` and ``AuthenticationManager`` now take a repo object at
+ initialization time instead of a vreg.
+
Deprecated Code Drops
----------------------
--- a/web/application.py Fri Nov 23 16:12:19 2012 +0100
+++ b/web/application.py Mon Jun 24 12:00:03 2013 +0200
@@ -61,9 +61,10 @@
"""manage session data associated to a session identifier"""
__regid__ = 'sessionmanager'
- def __init__(self, vreg):
+ def __init__(self, repo):
+ vreg = repo.vreg
self.session_time = vreg.config['http-session-time'] or None
- self.authmanager = vreg['components'].select('authmanager', vreg=vreg)
+ self.authmanager = vreg['components'].select('authmanager', repo=repo)
interval = (self.session_time or 0) / 2.
if vreg.config.anonymous_user() is not None:
self.cleanup_anon_session_time = vreg.config['cleanup-anonymous-session-time'] or 5 * 60
@@ -129,8 +130,8 @@
"""authenticate user associated to a request and check session validity"""
__regid__ = 'authmanager'
- def __init__(self, vreg):
- self.vreg = vreg
+ def __init__(self, repo):
+ self.vreg = repo.vreg
def validate_session(self, req, session):
"""check session validity, reconnecting it to the repository if the
@@ -158,9 +159,10 @@
"""a session handler using a cookie to store the session identifier"""
def __init__(self, appli):
+ self.repo = appli.repo
self.vreg = appli.vreg
self.session_manager = self.vreg['components'].select('sessionmanager',
- vreg=self.vreg)
+ repo=self.repo)
global SESSION_MANAGER
SESSION_MANAGER = self.session_manager
if self.vreg.config.mode != 'test':
@@ -172,7 +174,7 @@
def reset_session_manager(self):
data = self.session_manager.dump_data()
self.session_manager = self.vreg['components'].select('sessionmanager',
- vreg=self.vreg)
+ repo=self.repo)
self.session_manager.restore_data(data)
global SESSION_MANAGER
SESSION_MANAGER = self.session_manager
--- a/web/views/authentication.py Fri Nov 23 16:12:19 2012 +0100
+++ b/web/views/authentication.py Mon Jun 24 12:00:03 2013 +0200
@@ -93,9 +93,10 @@
class RepositoryAuthenticationManager(AbstractAuthenticationManager):
"""authenticate user associated to a request and check session validity"""
- def __init__(self, vreg):
- super(RepositoryAuthenticationManager, self).__init__(vreg)
- self.repo = vreg.config.repository(vreg)
+ def __init__(self, repo):
+ super(RepositoryAuthenticationManager, self).__init__(repo)
+ self.repo = repo
+ vreg = repo.vreg
self.log_queries = vreg.config['query-log-file']
self.authinforetrievers = sorted(vreg['webauth'].possible_objects(vreg),
key=lambda x: x.order)