mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Rename 'password' into 'credentials' in authenticator stuff for semantic, because we could also need a login or other stuff
This commit is contained in:
parent
f985507761
commit
4345081e6f
6 changed files with 23 additions and 23 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,7 +10,7 @@ class TestAuthAPI:
|
|||
if password is None:
|
||||
password = "dummy"
|
||||
|
||||
data = {"password": password}
|
||||
data = {"credentials": password}
|
||||
if profile:
|
||||
data["profile"] = profile
|
||||
|
||||
|
|
Loading…
Reference in a new issue