mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-02-02 14:16:38 +00:00
feat(tokens-repo): add migration of tokens to redis
This commit is contained in:
parent
5fbfaa73ea
commit
3344ab7c5d
|
@ -22,6 +22,7 @@ from selfprivacy_api.migrations.providers import CreateProviderFields
|
||||||
from selfprivacy_api.migrations.prepare_for_nixos_2211 import (
|
from selfprivacy_api.migrations.prepare_for_nixos_2211 import (
|
||||||
MigrateToSelfprivacyChannelFrom2205,
|
MigrateToSelfprivacyChannelFrom2205,
|
||||||
)
|
)
|
||||||
|
from selfprivacy_api.migrations.redis_tokens import LoadTokensToRedis
|
||||||
|
|
||||||
migrations = [
|
migrations = [
|
||||||
FixNixosConfigBranch(),
|
FixNixosConfigBranch(),
|
||||||
|
@ -31,6 +32,7 @@ migrations = [
|
||||||
CheckForFailedBindsMigration(),
|
CheckForFailedBindsMigration(),
|
||||||
CreateProviderFields(),
|
CreateProviderFields(),
|
||||||
MigrateToSelfprivacyChannelFrom2205(),
|
MigrateToSelfprivacyChannelFrom2205(),
|
||||||
|
LoadTokensToRedis(),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
48
selfprivacy_api/migrations/redis_tokens.py
Normal file
48
selfprivacy_api/migrations/redis_tokens.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
from selfprivacy_api.migrations.migration import Migration
|
||||||
|
|
||||||
|
from selfprivacy_api.repositories.tokens.json_tokens_repository import (
|
||||||
|
JsonTokensRepository,
|
||||||
|
)
|
||||||
|
from selfprivacy_api.repositories.tokens.redis_tokens_repository import (
|
||||||
|
RedisTokensRepository,
|
||||||
|
)
|
||||||
|
from selfprivacy_api.repositories.tokens.abstract_tokens_repository import (
|
||||||
|
AbstractTokensRepository,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class LoadTokensToRedis(Migration):
|
||||||
|
"""Load Json tokens into Redis"""
|
||||||
|
|
||||||
|
def get_migration_name(self):
|
||||||
|
return "load_tokens_to_redis"
|
||||||
|
|
||||||
|
def get_migration_description(self):
|
||||||
|
return "Loads access tokens and recovery keys from legacy json file into redis token storage"
|
||||||
|
|
||||||
|
def is_repo_empty(self, repo: AbstractTokensRepository) -> bool:
|
||||||
|
if repo.get_tokens() != []:
|
||||||
|
return False
|
||||||
|
if repo.get_recovery_key() is not None:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def is_migration_needed(self):
|
||||||
|
try:
|
||||||
|
if not self.is_repo_empty(JsonTokensRepository()) and self.is_repo_empty(
|
||||||
|
RedisTokensRepository()
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def migrate(self):
|
||||||
|
# Write info about providers to userdata.json
|
||||||
|
try:
|
||||||
|
RedisTokensRepository().clone(JsonTokensRepository())
|
||||||
|
|
||||||
|
print("Done")
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print("Error migrating access tokens from json to redis")
|
Loading…
Reference in a new issue