refactor(tokens-repo): delete is_token_name_pair_valid from auth

redis/token-repo
Houkime 2022-12-21 16:17:56 +00:00
parent 20410ec790
commit 2a239e35ad
2 changed files with 1 additions and 11 deletions

View File

@ -12,7 +12,6 @@ from selfprivacy_api.utils.auth import (
is_recovery_token_exists,
is_recovery_token_valid,
is_token_name_exists,
is_token_name_pair_valid,
get_token_name,
)
@ -56,7 +55,7 @@ class CannotDeleteCallerException(Exception):
def delete_api_token(caller_token: str, token_name: str) -> None:
"""Delete the token"""
if is_token_name_pair_valid(token_name, caller_token):
if TOKEN_REPO.is_token_name_pair_valid(token_name, caller_token):
raise CannotDeleteCallerException("Cannot delete caller's token")
if not is_token_name_exists(token_name):
raise NotFoundException("Token not found")

View File

@ -79,15 +79,6 @@ def is_token_name_exists(token_name):
return token_name in [t["name"] for t in tokens["tokens"]]
def is_token_name_pair_valid(token_name, token):
"""Check if token name and token pair exists"""
with ReadUserData(UserDataFiles.TOKENS) as tokens:
for t in tokens["tokens"]:
if t["name"] == token_name and t["token"] == token:
return True
return False
def get_token_name(token: str) -> typing.Optional[str]:
"""Return the name of the token provided"""
with ReadUserData(UserDataFiles.TOKENS) as tokens: