feat: add ssl mode with non url connection + add redis cluster support (#494)

This commit is contained in:
Vincent Renaville
2025-05-12 09:45:42 +02:00
committed by GitHub
co-authored by GitHub
parent 416a4660ae
commit e529e00fd7
2 changed files with 23 additions and 3 deletions
+8
View File
@@ -13,6 +13,14 @@ The storage of sessions in Redis is activated using environment variables.
* ``ODOO_SESSION_REDIS_PORT`` is the redis port (default is ``6379``) * ``ODOO_SESSION_REDIS_PORT`` is the redis port (default is ``6379``)
* ``ODOO_SESSION_REDIS_PASSWORD`` is the password for the AUTH command * ``ODOO_SESSION_REDIS_PASSWORD`` is the password for the AUTH command
(optional) (optional)
* ``ODOO_SESSION_REDIS_SSL`` is the SSL connection (default is ``true``)
(optional)
* ``ODOO_SESSION_REDIS_SSL_CERT_REQS`` is the SSL certificate requirements (default is
``required``), needed to be disabled when using self-signed certificates
(optional)
* ``ODOO_SESSION_REDIS_CLUSTER`` the redis in cluster mode (default is ``false``)
(optional)
* ``ODOO_SESSION_REDIS_URL`` is an alternative way to define the Redis server * ``ODOO_SESSION_REDIS_URL`` is an alternative way to define the Redis server
address. It's the preferred way when you're using the ``rediss://`` protocol. address. It's the preferred way when you're using the ``rediss://`` protocol.
* ``ODOO_SESSION_REDIS_PREFIX`` is the prefix for the session keys (optional) * ``ODOO_SESSION_REDIS_PREFIX`` is the prefix for the session keys (optional)
+15 -3
View File
@@ -40,8 +40,10 @@ url = os.getenv("ODOO_SESSION_REDIS_URL")
password = os.getenv("ODOO_SESSION_REDIS_PASSWORD") password = os.getenv("ODOO_SESSION_REDIS_PASSWORD")
expiration = os.getenv("ODOO_SESSION_REDIS_EXPIRATION") expiration = os.getenv("ODOO_SESSION_REDIS_EXPIRATION")
anon_expiration = os.getenv("ODOO_SESSION_REDIS_EXPIRATION_ANONYMOUS") anon_expiration = os.getenv("ODOO_SESSION_REDIS_EXPIRATION_ANONYMOUS")
# For non url connections
ssl = os.getenv("ODOO_SESSION_REDIS_SSL", "1")
ssl_cert_reqs = os.getenv("ODOO_SESSION_REDIS_SSL_CERT_REQS", "1")
redis_cluster = os.getenv("ODOO_SESSION_REDIS_CLUSTER", "0")
@lazy_property @lazy_property
def session_store(self): def session_store(self):
if sentinel_host: if sentinel_host:
@@ -49,8 +51,18 @@ def session_store(self):
redis_client = sentinel.master_for(sentinel_master_name) redis_client = sentinel.master_for(sentinel_master_name)
elif url: elif url:
redis_client = redis.from_url(url) redis_client = redis.from_url(url)
elif is_true(redis_cluster):
redis_client = redis.RedisCluster(
host=host,
port=port,
password=password,
ssl=is_true(ssl),
ssl_cert_reqs=is_true(ssl_cert_reqs))
else: else:
redis_client = redis.Redis(host=host, port=port, password=password) redis_client = redis.Redis(
host=host, port=port, password=password,
ssl=is_true(ssl),
ssl_cert_reqs=is_true(ssl_cert_reqs))
return RedisSessionStore( return RedisSessionStore(
redis=redis_client, redis=redis_client,
prefix=prefix, prefix=prefix,