From 69577c2854d334cf3bfb9be566aa032615ad1285 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 26 Dec 2022 14:29:05 +0000 Subject: [PATCH] refactor(tokens-repo): delete get_recovery_key_status from auth utils --- selfprivacy_api/graphql/queries/api_queries.py | 17 ++++++++--------- selfprivacy_api/utils/auth.py | 17 ----------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/selfprivacy_api/graphql/queries/api_queries.py b/selfprivacy_api/graphql/queries/api_queries.py index 7994a8f..7cf7c3e 100644 --- a/selfprivacy_api/graphql/queries/api_queries.py +++ b/selfprivacy_api/graphql/queries/api_queries.py @@ -4,13 +4,14 @@ import datetime import typing import strawberry from strawberry.types import Info -from selfprivacy_api.actions.api_tokens import get_api_tokens_with_caller_flag +from selfprivacy_api.actions.api_tokens import ( + get_api_tokens_with_caller_flag, + get_api_recovery_token_status, +) from selfprivacy_api.graphql import IsAuthenticated -from selfprivacy_api.utils import parse_date from selfprivacy_api.dependencies import get_api_version as get_api_version_dependency from selfprivacy_api.utils.auth import ( - get_recovery_token_status, is_recovery_token_exists, is_recovery_token_valid, ) @@ -51,7 +52,7 @@ def get_recovery_key_status() -> ApiRecoveryKeyStatus: expiration_date=None, uses_left=None, ) - status = get_recovery_token_status() + status = get_api_recovery_token_status() if status is None: return ApiRecoveryKeyStatus( exists=False, @@ -63,11 +64,9 @@ def get_recovery_key_status() -> ApiRecoveryKeyStatus: return ApiRecoveryKeyStatus( exists=True, valid=is_recovery_token_valid(), - creation_date=parse_date(status["date"]), - expiration_date=parse_date(status["expiration"]) - if status["expiration"] is not None - else None, - uses_left=status["uses_left"] if status["uses_left"] is not None else None, + creation_date=status.date, + expiration_date=status.expiration, + uses_left=status.uses_left, ) diff --git a/selfprivacy_api/utils/auth.py b/selfprivacy_api/utils/auth.py index 53dffd7..53df508 100644 --- a/selfprivacy_api/utils/auth.py +++ b/selfprivacy_api/utils/auth.py @@ -132,23 +132,6 @@ def is_recovery_token_valid(): return datetime.now() < parse_date(recovery_token["expiration"]) -def get_recovery_token_status(): - """Get recovery token date of creation, expiration and uses left""" - with ReadUserData(UserDataFiles.TOKENS) as tokens: - if "recovery_token" not in tokens: - return None - recovery_token = tokens["recovery_token"] - return { - "date": recovery_token["date"], - "expiration": recovery_token["expiration"] - if "expiration" in recovery_token - else None, - "uses_left": recovery_token["uses_left"] - if "uses_left" in recovery_token - else None, - } - - def _get_recovery_token(): """Get recovery token""" with ReadUserData(UserDataFiles.TOKENS) as tokens: