Island: Add IUserDatastore

This commit is contained in:
Mike Salvatore 2021-11-18 08:52:16 -05:00
parent a3bdda2051
commit 52f461f425
2 changed files with 40 additions and 0 deletions

View File

@ -18,6 +18,10 @@ class AlreadyRegisteredError(RegistrationNotNeededError):
""" Raise to indicate the reason why registration is not required """
class UnknownUserError(Exception):
""" Raise to indicate that authentication failed """
class IncorrectCredentialsError(Exception):
""" Raise to indicate that authentication failed """

View File

@ -0,0 +1,36 @@
import abc
from monkey_island.cc.environment.user_creds import UserCreds
class IUserDatastore(metaclass=abc.ABCMeta):
"""
Allows user credentials to be stored and retrieved.
"""
@abc.abstractmethod
def has_registered_users(self) -> bool:
"""
Checks if there are any registered user.
:return: True if any users have been registered, False otherwise
:rtype: bool
"""
@abc.abstractmethod
def add_user(self, credentials: UserCreds):
"""
Adds a new user to the datastore.
:param UserCreds credentials: New user credentials to persistant storage.
:raises InvalidRegistrationCredentialsError: if the credentials are malformed
:raises AlreadyRegisteredError: if the user has already been registered
"""
@abc.abstractmethod
def get_user_credentials(self, username: str) -> UserCreds:
"""
Gets the user matching `username` from storage.
:param str username: The username for which credentials will be retrieved
:return: User credentials for username
:rtype: UserCreds
:raises UnknownUserError: if the username does not exist
"""