mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Get rid of this 'help' madness and more generally this three-tuppled containing various tuples and weird stuff ... use a simple dict everywhere instead
This commit is contained in:
parent
cad2cd8006
commit
65fe685a90
5 changed files with 22 additions and 34 deletions
|
@ -33,23 +33,20 @@ class Authenticator(BaseAuthenticator):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, name, uri, base_dn, user_rdn=None):
|
||||
def __init__(self, name, vendor, parameters, extra):
|
||||
self.uri = parameters["uri"]
|
||||
self.basedn = parameters["base_dn"]
|
||||
self.userdn = parameters["user_rdn"]
|
||||
self.extra = extra
|
||||
logger.debug("initialize authenticator '%s' with: uri='%s', "
|
||||
"base_dn='%s', user_rdn='%s'", name, uri, base_dn, user_rdn)
|
||||
"base_dn='%s', user_rdn='%s'", name, self.uri, self.basedn, self.userdn)
|
||||
super(Authenticator, self).__init__(name)
|
||||
|
||||
self.uri = uri
|
||||
self.basedn = base_dn
|
||||
if user_rdn:
|
||||
self.userdn = user_rdn
|
||||
if 'cn=external,cn=auth' in user_rdn:
|
||||
if self.userdn:
|
||||
if 'cn=external,cn=auth' in self.userdn:
|
||||
self.authenticate(None)
|
||||
else:
|
||||
self.con = None
|
||||
else:
|
||||
# Initialize anonymous usage
|
||||
self.userdn = ''
|
||||
self.authenticate(None)
|
||||
|
||||
def __del__(self):
|
||||
"""Disconnect and free ressources"""
|
||||
|
|
|
@ -287,7 +287,7 @@ class MoulinetteSignals(object):
|
|||
"""The list of available signals"""
|
||||
signals = {'authenticate', 'prompt', 'display'}
|
||||
|
||||
def authenticate(self, authenticator, help):
|
||||
def authenticate(self, authenticator):
|
||||
"""Process the authentication
|
||||
|
||||
Attempt to authenticate to the given authenticator and return
|
||||
|
@ -297,7 +297,6 @@ class MoulinetteSignals(object):
|
|||
|
||||
Keyword arguments:
|
||||
- authenticator -- The authenticator object to use
|
||||
- help -- The translation key of the authenticator's help message
|
||||
|
||||
Returns:
|
||||
The authenticator object
|
||||
|
@ -305,7 +304,7 @@ class MoulinetteSignals(object):
|
|||
"""
|
||||
if authenticator.is_authenticated:
|
||||
return authenticator
|
||||
return self._authenticate(authenticator, help)
|
||||
return self._authenticate(authenticator)
|
||||
|
||||
def prompt(self, message, is_password=False, confirm=False):
|
||||
"""Prompt for a value
|
||||
|
@ -397,7 +396,7 @@ def init_interface(name, kwargs={}, actionsmap={}):
|
|||
return interface(amap, **kwargs)
|
||||
|
||||
|
||||
def init_authenticator(vendor_and_name, kwargs={}):
|
||||
def init_authenticator(auth_conf):
|
||||
"""Return a new authenticator instance
|
||||
|
||||
Retrieve the given authenticator vendor and return a new instance of
|
||||
|
@ -409,15 +408,13 @@ def init_authenticator(vendor_and_name, kwargs={}):
|
|||
- kwargs -- A dict of arguments for the authenticator profile
|
||||
|
||||
"""
|
||||
(vendor, name) = vendor_and_name
|
||||
try:
|
||||
mod = import_module('moulinette.authenticators.%s' % vendor)
|
||||
mod = import_module('moulinette.authenticators.%s' % auth_conf["vendor"])
|
||||
except ImportError:
|
||||
logger.exception("unable to load authenticator vendor '%s'", vendor)
|
||||
logger.exception("unable to load authenticator vendor '%s'", auth_conf["vendor"])
|
||||
raise MoulinetteError('error_see_log')
|
||||
else:
|
||||
return mod.Authenticator(name, **kwargs)
|
||||
|
||||
return mod.Authenticator(**auth_conf)
|
||||
|
||||
def clean_session(session_id, profiles=[]):
|
||||
"""Clean a session cache
|
||||
|
|
|
@ -266,17 +266,10 @@ class BaseActionsMapParser(object):
|
|||
else:
|
||||
auths = {}
|
||||
for auth_name, auth_conf in auth.items():
|
||||
# Add authenticator profile as a 3-tuple
|
||||
# (identifier, configuration, parameters) with
|
||||
# - identifier: the authenticator vendor and its
|
||||
# profile name as a 2-tuple
|
||||
# - configuration: a dict of additional global
|
||||
# configuration (i.e. 'help')
|
||||
# - parameters: a dict of arguments for the
|
||||
# authenticator profile
|
||||
auths[auth_name] = ((auth_conf.get('vendor'), auth_name),
|
||||
{'help': auth_conf.get('help', None)},
|
||||
auth_conf.get('parameters', {}))
|
||||
auths[auth_name] = {'name': auth_name,
|
||||
'vendor': auth_conf.get('vendor'),
|
||||
'parameters': auth_conf.get('parameters', {}),
|
||||
'extra': {'help': auth_conf.get('help', None)}}
|
||||
conf['authenticator'] = auths
|
||||
else:
|
||||
logger.error("expecting a dict of profile(s) or a profile name "
|
||||
|
|
|
@ -461,7 +461,7 @@ class _ActionsMapPlugin(object):
|
|||
|
||||
# Signals handlers
|
||||
|
||||
def _do_authenticate(self, authenticator, help):
|
||||
def _do_authenticate(self, authenticator):
|
||||
"""Process the authentication
|
||||
|
||||
Handle the core.MoulinetteSignals.authenticate signal.
|
||||
|
|
|
@ -435,7 +435,7 @@ class Interface(BaseInterface):
|
|||
# Set handler for authentication
|
||||
if password:
|
||||
msignals.set_handler('authenticate',
|
||||
lambda a, h: a(password=password))
|
||||
lambda a: a(password=password))
|
||||
|
||||
try:
|
||||
ret = self.actionsmap.process(args, timeout=timeout)
|
||||
|
@ -460,13 +460,14 @@ class Interface(BaseInterface):
|
|||
|
||||
# Signals handlers
|
||||
|
||||
def _do_authenticate(self, authenticator, help):
|
||||
def _do_authenticate(self, authenticator):
|
||||
"""Process the authentication
|
||||
|
||||
Handle the core.MoulinetteSignals.authenticate signal.
|
||||
|
||||
"""
|
||||
# TODO: Allow token authentication?
|
||||
help = authenticator.extra.get("help")
|
||||
msg = m18n.n(help) if help else m18n.g('password')
|
||||
return authenticator(password=self._do_prompt(msg, True, False,
|
||||
color='yellow'))
|
||||
|
|
Loading…
Add table
Reference in a new issue