From ece565dc8d1bced5bb9d0d872f7831775bf298d2 Mon Sep 17 00:00:00 2001 From: Stefan Negru Date: Fri, 10 Mar 2023 15:31:39 +0200 Subject: [PATCH 1/2] switch to redis library aioredis was included in redis so let us switch to that --- pyproject.toml | 2 +- requirements.txt | 2 +- swift_browser_ui/ui/server.py | 13 +++++++------ tox.ini | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6256bb52a..f05c3064c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ classifiers = [ dependencies = [ "aiohttp-session==2.12.0", "aiohttp==3.8.4", - "aioredis==2.0.1", + "redis==4.5.1", "asyncpg==0.27.0", "certifi==2022.12.7", "click==8.1.3", diff --git a/requirements.txt b/requirements.txt index d31683d77..d538c4068 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ aiohttp==3.8.4 aiohttp-session==2.12.0 -aioredis==2.0.1 +redis==4.5.1 asyncpg==0.27.0 certifi==2022.12.7 click==8.1.3 diff --git a/swift_browser_ui/ui/server.py b/swift_browser_ui/ui/server.py index 546dde30a..391d57b17 100644 --- a/swift_browser_ui/ui/server.py +++ b/swift_browser_ui/ui/server.py @@ -18,8 +18,7 @@ import aiohttp_session import aiohttp_session.redis_storage -import aioredis -import aioredis.sentinel +from redis import asyncio as aioredis from oidcrp.rp_handler import RPHandler @@ -122,12 +121,12 @@ async def on_prepare( redis_user = str(os.environ.get("SWIFT_UI_REDIS_USER", "")) redis_password = str(os.environ.get("SWIFT_UI_REDIS_PASSWORD", "")) - redis: aioredis.Redis + redis_client: aioredis.Redis if sentinel_url and sentinel_port: # we forward the auth to redis so no need for auth on sentinel sentinel = aioredis.sentinel.Sentinel([(str(sentinel_url), int(sentinel_port))]) - redis = sentinel.master_for( + redis_client = sentinel.master_for( service_name=sentinel_master, redis_class=aioredis.Redis, password=redis_password, @@ -140,9 +139,11 @@ async def on_prepare( redis_creds = "" if redis_user and redis_password: redis_creds = f"{redis_user}:{redis_password}@" - redis = aioredis.from_url(f"redis://{redis_creds}{redis_host}:{redis_port}") + redis_client = aioredis.from_url( + f"redis://{redis_creds}{redis_host}:{redis_port}" + ) storage = aiohttp_session.redis_storage.RedisStorage( - redis, + redis_client, cookie_name="SWIFT_UI_SESSION", ) app["seckey"] = base64.urlsafe_b64decode(cryptography.fernet.Fernet.generate_key()) diff --git a/tox.ini b/tox.ini index ff40352e6..a13072e17 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,7 @@ deps = mypy types-requests types-certifi + types-redis # Mypy fails if 3rd party library doesn't have type hints configured. # Alternative to ignoring imports would be to write custom stub files, which # could be done at some point. From e223e88a09af6fbac46ffa1588a313a8fe356da8 Mon Sep 17 00:00:00 2001 From: Stefan Negru Date: Fri, 10 Mar 2023 15:37:56 +0200 Subject: [PATCH 2/2] add changelog to redis --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b942a3532..a9928d746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,7 +67,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - (GL #944) Replace buefy b-select with c-select from `csc-ui` - (GL #944) Replace buefy b-loading with c-loader from `csc-ui` and remove unused b-loading - (GL #944) Replace buefy b-table with c-data-table from `csc-ui` -- (GL #944) Replace buefy dialogs with c-modal from `csc-ui` +- (GH #1028) Switch from `aioredis` to `redis` library due to deprecation +- (GH #1025) add timeout to `requests` as recommended by `bandit` ### Fixed