From c6661ef4d26a6bef6d06c9e7e0527b6f446708ad Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 19 Oct 2020 14:35:38 +0200 Subject: [PATCH] lifecycle: add migration to 0.12 which removes old outpost state from cache --- lifecycle/system_migrations/to_0_12.py | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lifecycle/system_migrations/to_0_12.py diff --git a/lifecycle/system_migrations/to_0_12.py b/lifecycle/system_migrations/to_0_12.py new file mode 100644 index 000000000..64b69d9b4 --- /dev/null +++ b/lifecycle/system_migrations/to_0_12.py @@ -0,0 +1,28 @@ +from pickle import loads # nosec + +from redis import Redis + +from lifecycle.migrate import BaseMigration +from passbook.lib.config import CONFIG + + +class To012Migration(BaseMigration): + def __init__(self) -> None: + self.redis = Redis( + host=CONFIG.y("redis.host"), + port=6379, + db=CONFIG.y("redis.cache_db"), + password=CONFIG.y("redis.password"), + ) + + def needs_migration(self) -> bool: + keys = self.redis.keys(":1:outpost_*") + for key in keys: + value = loads(self.redis.get(key)) # nosec + if isinstance(value, str): + return True + return False + + def run(self): + keys_to_delete = self.redis.keys(":1:outpost_*") + self.redis.delete(*keys_to_delete)