Rename 'password' into 'credentials' in authenticator stuff for semantic, because we could also need a login or other stuff

This commit is contained in:
Alexandre Aubin 2021-06-14 17:23:41 +02:00
parent f985507761
commit 4345081e6f
6 changed files with 23 additions and 23 deletions

View file

@ -21,7 +21,7 @@ class BaseAuthenticator(object):
Each authenticators must implement an Authenticator class derived Each authenticators must implement an Authenticator class derived
from this class which must overrides virtual properties and methods. from this class which must overrides virtual properties and methods.
It is used to authenticate and manage session. It implements base 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 Authenticators configurations are identified by a profile name which
must be given on instantiation - with the corresponding vendor must be given on instantiation - with the corresponding vendor
@ -32,14 +32,14 @@ class BaseAuthenticator(object):
# Virtual methods # Virtual methods
# Each authenticator classes must implement these methods. # Each authenticator classes must implement these methods.
def authenticate(self, password=None): def authenticate(self, credentials=None):
"""Attempt to authenticate """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. AuthenticationError exception if authentication fails.
Keyword arguments: Keyword arguments:
- password -- A clear text password - credentials -- A string containing the credentials to be used by the authenticator
""" """
raise NotImplementedError( raise NotImplementedError(
@ -48,18 +48,18 @@ class BaseAuthenticator(object):
# Authentication methods # Authentication methods
def __call__(self, password=None, token=None): def __call__(self, credentials=None, token=None):
"""Attempt to authenticate """Attempt to authenticate
Attempt to authenticate either with password or with session Attempt to authenticate either with credentials or with session
token if 'password' is None. If the authentication succeed, the token if 'credentials' is None. If the authentication succeed, the
instance is returned and the session is registered for the token 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 The token is composed by the session identifier and a session
hash (the "true token") - to use for encryption - as a 2-tuple. hash (the "true token") - to use for encryption - as a 2-tuple.
Keyword arguments: 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) - token -- The session token in the form of (id, hash)
""" """
@ -70,12 +70,12 @@ class BaseAuthenticator(object):
is_authenticated = False is_authenticated = False
# #
# Authenticate using the password # Authenticate using the credentials
# #
if password: if credentials:
try: try:
# Attempt to authenticate # Attempt to authenticate
self.authenticate(password) self.authenticate(credentials)
except MoulinetteError: except MoulinetteError:
raise raise
except Exception as e: except Exception as e:

View file

@ -249,9 +249,9 @@ class _ActionsMapPlugin(object):
def wrapper(): def wrapper():
kwargs = {} kwargs = {}
try: try:
kwargs["password"] = request.POST.password kwargs["credentials"] = request.POST.credentials
except KeyError: except KeyError:
raise HTTPResponse("Missing password parameter", 400) raise HTTPResponse("Missing credentials parameter", 400)
kwargs["profile"] = request.POST.get( kwargs["profile"] = request.POST.get(
"profile", self.actionsmap.default_authentication "profile", self.actionsmap.default_authentication
@ -347,7 +347,7 @@ class _ActionsMapPlugin(object):
# Routes callbacks # Routes callbacks
def login(self, password, profile): def login(self, credentials, profile):
"""Log in to an authenticator profile """Log in to an authenticator profile
Attempt to authenticate to a given authenticator profile and Attempt to authenticate to a given authenticator profile and
@ -355,7 +355,7 @@ class _ActionsMapPlugin(object):
if needed. if needed.
Keyword arguments: Keyword arguments:
- password -- A clear text password - credentials -- Some credentials to use for login
- profile -- The authenticator profile name to log in - profile -- The authenticator profile name to log in
""" """
@ -383,7 +383,7 @@ class _ActionsMapPlugin(object):
try: try:
# Attempt to authenticate # Attempt to authenticate
authenticator = self.actionsmap.get_authenticator(profile) 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: except MoulinetteError as e:
if len(s_tokens) > 0: if len(s_tokens) > 0:
try: try:

View file

@ -538,7 +538,7 @@ class Interface(BaseInterface):
# moulinette is used to create a CLI for non-root user that needs to # moulinette is used to create a CLI for non-root user that needs to
# auth somehow but hmpf -.- # auth somehow but hmpf -.-
msg = m18n.g("password") 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"): def _do_prompt(self, message, is_password, confirm, color="blue"):
"""Prompt for a value """Prompt for a value

View file

@ -18,9 +18,9 @@ class Authenticator(BaseAuthenticator):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
pass 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") raise MoulinetteError("invalid_password")
return return

View file

@ -18,9 +18,9 @@ class Authenticator(BaseAuthenticator):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
pass 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") raise MoulinetteError("invalid_password")
return return

View file

@ -10,7 +10,7 @@ class TestAuthAPI:
if password is None: if password is None:
password = "dummy" password = "dummy"
data = {"password": password} data = {"credentials": password}
if profile: if profile:
data["profile"] = profile data["profile"] = profile