From 4345081e6f9b7555ad23d460f02dcdf84e55c772 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 14 Jun 2021 17:23:41 +0200 Subject: [PATCH] Rename 'password' into 'credentials' in authenticator stuff for semantic, because we could also need a login or other stuff --- moulinette/authentication.py | 24 ++++++++++++------------ moulinette/interfaces/api.py | 10 +++++----- moulinette/interfaces/cli.py | 2 +- test/src/authenticators/dummy.py | 4 ++-- test/src/authenticators/yoloswag.py | 4 ++-- test/test_auth.py | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/moulinette/authentication.py b/moulinette/authentication.py index 3c93340b..0a6c302a 100644 --- a/moulinette/authentication.py +++ b/moulinette/authentication.py @@ -21,7 +21,7 @@ class BaseAuthenticator(object): Each authenticators must implement an Authenticator class derived from this class which must overrides virtual properties and methods. It is used to authenticate and manage session. It implements base - methods to authenticate with a password or a session token. + methods to authenticate with credentials or a session token. Authenticators configurations are identified by a profile name which must be given on instantiation - with the corresponding vendor @@ -32,14 +32,14 @@ class BaseAuthenticator(object): # Virtual methods # Each authenticator classes must implement these methods. - def authenticate(self, password=None): + def authenticate(self, credentials=None): """Attempt to authenticate - Attempt to authenticate with given password. It should raise an + Attempt to authenticate with given credentials. It should raise an AuthenticationError exception if authentication fails. Keyword arguments: - - password -- A clear text password + - credentials -- A string containing the credentials to be used by the authenticator """ raise NotImplementedError( @@ -48,18 +48,18 @@ class BaseAuthenticator(object): # Authentication methods - def __call__(self, password=None, token=None): + def __call__(self, credentials=None, token=None): """Attempt to authenticate - Attempt to authenticate either with password or with session - token if 'password' is None. If the authentication succeed, the + Attempt to authenticate either with credentials or with session + token if 'credentials' is None. If the authentication succeed, the instance is returned and the session is registered for the token - if 'token' and 'password' are given. + if 'token' and 'credentials' are given. The token is composed by the session identifier and a session hash (the "true token") - to use for encryption - as a 2-tuple. Keyword arguments: - - password -- A clear text password + - credentials -- A string containing the credentials to be used by the authenticator - token -- The session token in the form of (id, hash) """ @@ -70,12 +70,12 @@ class BaseAuthenticator(object): is_authenticated = False # - # Authenticate using the password + # Authenticate using the credentials # - if password: + if credentials: try: # Attempt to authenticate - self.authenticate(password) + self.authenticate(credentials) except MoulinetteError: raise except Exception as e: diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index bea8e84b..a90f1b76 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -249,9 +249,9 @@ class _ActionsMapPlugin(object): def wrapper(): kwargs = {} try: - kwargs["password"] = request.POST.password + kwargs["credentials"] = request.POST.credentials except KeyError: - raise HTTPResponse("Missing password parameter", 400) + raise HTTPResponse("Missing credentials parameter", 400) kwargs["profile"] = request.POST.get( "profile", self.actionsmap.default_authentication @@ -347,7 +347,7 @@ class _ActionsMapPlugin(object): # Routes callbacks - def login(self, password, profile): + def login(self, credentials, profile): """Log in to an authenticator profile Attempt to authenticate to a given authenticator profile and @@ -355,7 +355,7 @@ class _ActionsMapPlugin(object): if needed. Keyword arguments: - - password -- A clear text password + - credentials -- Some credentials to use for login - profile -- The authenticator profile name to log in """ @@ -383,7 +383,7 @@ class _ActionsMapPlugin(object): try: # Attempt to authenticate authenticator = self.actionsmap.get_authenticator(profile) - authenticator(password, token=(s_id, s_new_token)) + authenticator(credentials, token=(s_id, s_new_token)) except MoulinetteError as e: if len(s_tokens) > 0: try: diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index ca377781..5298ea84 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -538,7 +538,7 @@ class Interface(BaseInterface): # moulinette is used to create a CLI for non-root user that needs to # auth somehow but hmpf -.- msg = m18n.g("password") - return authenticator(password=self._do_prompt(msg, True, False, color="yellow")) + return authenticator(credentials=self._do_prompt(msg, True, False, color="yellow")) def _do_prompt(self, message, is_password, confirm, color="blue"): """Prompt for a value diff --git a/test/src/authenticators/dummy.py b/test/src/authenticators/dummy.py index 4b1b1a59..8de685be 100644 --- a/test/src/authenticators/dummy.py +++ b/test/src/authenticators/dummy.py @@ -18,9 +18,9 @@ class Authenticator(BaseAuthenticator): def __init__(self, *args, **kwargs): pass - def authenticate(self, password=None): + def authenticate(self, credentials=None): - if not password == self.name: + if not credentials == self.name: raise MoulinetteError("invalid_password") return diff --git a/test/src/authenticators/yoloswag.py b/test/src/authenticators/yoloswag.py index 335fe9bc..a632d1b8 100644 --- a/test/src/authenticators/yoloswag.py +++ b/test/src/authenticators/yoloswag.py @@ -18,9 +18,9 @@ class Authenticator(BaseAuthenticator): def __init__(self, *args, **kwargs): pass - def authenticate(self, password=None): + def authenticate(self, credentials=None): - if not password == self.name: + if not credentials == self.name: raise MoulinetteError("invalid_password") return diff --git a/test/test_auth.py b/test/test_auth.py index 84a03f54..d4f74162 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -10,7 +10,7 @@ class TestAuthAPI: if password is None: password = "dummy" - data = {"password": password} + data = {"credentials": password} if profile: data["profile"] = profile