mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-11 10:29:30 +00:00
refactor(tokens-repo): move create_token to abstract class
This commit is contained in:
parent
572ec75c39
commit
682cd4ae87
|
@ -31,9 +31,13 @@ class AbstractTokensRepository(ABC):
|
|||
def get_tokens(self) -> list[Token]:
|
||||
"""Get the tokens"""
|
||||
|
||||
@abstractmethod
|
||||
def create_token(self, device_name: str) -> Token:
|
||||
"""Create new token"""
|
||||
new_token = Token.generate(device_name)
|
||||
|
||||
self._store_token(new_token)
|
||||
|
||||
return new_token
|
||||
|
||||
@abstractmethod
|
||||
def delete_token(self, input_token: Token) -> None:
|
||||
|
@ -102,3 +106,7 @@ class AbstractTokensRepository(ABC):
|
|||
self, mnemonic_phrase: str, device_name: str
|
||||
) -> Token:
|
||||
"""Use the mnemonic new device key"""
|
||||
|
||||
@abstractmethod
|
||||
def _store_token(self, new_token: Token):
|
||||
"""Store a token directly"""
|
||||
|
|
|
@ -39,15 +39,8 @@ class JsonTokensRepository(AbstractTokensRepository):
|
|||
|
||||
return tokens_list
|
||||
|
||||
def create_token(self, device_name: str) -> Token:
|
||||
"""Create new token"""
|
||||
new_token = Token.generate(device_name)
|
||||
|
||||
self.__store_token(new_token)
|
||||
|
||||
return new_token
|
||||
|
||||
def __store_token(self, new_token: Token):
|
||||
def _store_token(self, new_token: Token):
|
||||
"""Store a token directly"""
|
||||
with WriteUserData(UserDataFiles.TOKENS) as tokens_file:
|
||||
tokens_file["tokens"].append(
|
||||
{
|
||||
|
@ -73,7 +66,7 @@ class JsonTokensRepository(AbstractTokensRepository):
|
|||
|
||||
if input_token in self.get_tokens():
|
||||
self.delete_token(input_token)
|
||||
self.__store_token(new_token)
|
||||
self._store_token(new_token)
|
||||
return new_token
|
||||
|
||||
raise TokenNotFound("Token not found!")
|
||||
|
|
Loading…
Reference in a new issue