forked from p15670423/monkey
Island: Add IUserDatastore
This commit is contained in:
parent
a3bdda2051
commit
52f461f425
|
@ -18,6 +18,10 @@ class AlreadyRegisteredError(RegistrationNotNeededError):
|
||||||
""" Raise to indicate the reason why registration is not required """
|
""" Raise to indicate the reason why registration is not required """
|
||||||
|
|
||||||
|
|
||||||
|
class UnknownUserError(Exception):
|
||||||
|
""" Raise to indicate that authentication failed """
|
||||||
|
|
||||||
|
|
||||||
class IncorrectCredentialsError(Exception):
|
class IncorrectCredentialsError(Exception):
|
||||||
""" Raise to indicate that authentication failed """
|
""" Raise to indicate that authentication failed """
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
"""
|
Loading…
Reference in New Issue