diff --git a/session_redis/http.py b/session_redis/http.py index c10f84c..ad6e394 100644 --- a/session_redis/http.py +++ b/session_redis/http.py @@ -6,8 +6,8 @@ import os from .strtobool import strtobool -import odoo from odoo import http +from odoo.tools import config from odoo.tools.func import lazy_property from .session import RedisSessionStore @@ -52,22 +52,10 @@ def session_store(self): redis_client = redis.from_url(url) else: redis_client = redis.Redis(host=host, port=port, password=password) - return RedisSessionStore( - redis=redis_client, - prefix=prefix, - expiration=expiration, - anon_expiration=anon_expiration, - session_class=http.OpenERPSession, - ) - - -def session_gc(session_store): - """Do not garbage collect the sessions - - Redis keys are automatically cleaned at the end of their - expiration. - """ - return + return RedisSessionStore(redis=redis_client, prefix=prefix, + expiration=expiration, + anon_expiration=anon_expiration, + session_class=http.Session) def purge_fs_sessions(path): @@ -89,14 +77,8 @@ if is_true(os.environ.get("ODOO_SESSION_REDIS")): sentinel_port, ) else: - _logger.debug( - "HTTP sessions stored in Redis with prefix '%s' on " "%s:%s", - prefix or "", - host, - port, - ) - - http.Root.session_store = session_store - http.session_gc = session_gc + _logger.debug("HTTP sessions stored in Redis with prefix '%s' on " + "%s:%s", prefix or '', host, port) + http.Application.session_store = session_store # clean the existing sessions on the file system - purge_fs_sessions(odoo.tools.config.session_dir) + purge_fs_sessions(config.session_dir) diff --git a/session_redis/session.py b/session_redis/session.py index 4c8457e..57ab9e0 100644 --- a/session_redis/session.py +++ b/session_redis/session.py @@ -4,6 +4,7 @@ import json import logging +from odoo.service import security from odoo.tools._vendor.sessions import SessionStore from . import json_encoding @@ -96,3 +97,18 @@ class RedisSessionStore(SessionStore): keys = self.redis.keys('%s*' % self.prefix) _logger.debug("a listing redis keys has been called") return [key[len(self.prefix):] for key in keys] + + def rotate(self, session, env): + self.delete(session) + session.sid = self.generate_key() + if session.uid and env: + session.session_token = security.compute_session_token(session, env) + self.save(session) + + def vacuum(self): + """ Do not garbage collect the sessions + + Redis keys are automatically cleaned at the end of their + expiration. + """ + return None