Move init_authenticator to actionsmap.py for clarity to avoid spreading this shit over 72 files

This commit is contained in:
Alexandre Aubin 2019-08-20 05:55:06 +02:00
parent 65fe685a90
commit ebc37ea014
2 changed files with 10 additions and 22 deletions

View file

@ -7,9 +7,9 @@ import yaml
import cPickle as pickle import cPickle as pickle
from time import time from time import time
from collections import OrderedDict from collections import OrderedDict
from importlib import import_module
from moulinette import m18n, msignals from moulinette import m18n, msignals
from moulinette.core import init_authenticator
from moulinette.cache import open_cachefile from moulinette.cache import open_cachefile
from moulinette.globals import init_moulinette_env from moulinette.globals import init_moulinette_env
from moulinette.core import (MoulinetteError, MoulinetteLock) from moulinette.core import (MoulinetteError, MoulinetteLock)
@ -445,12 +445,20 @@ class ActionsMap(object):
def get_authenticator_for_profile(self, auth_profile): def get_authenticator_for_profile(self, auth_profile):
# Fetch the configuration for the authenticator module as defined in the actionmap
try: try:
auth_conf = self.parser.global_conf['authenticator'][auth_profile] auth_conf = self.parser.global_conf['authenticator'][auth_profile]
except KeyError: except KeyError:
raise ValueError("Unknown authenticator profile '%s'" % auth_profile) raise ValueError("Unknown authenticator profile '%s'" % auth_profile)
return init_authenticator(auth_conf) # Load and initialize the authenticator module
try:
mod = import_module('moulinette.authenticators.%s' % auth_conf["vendor"])
except ImportError:
logger.exception("unable to load authenticator vendor '%s'", auth_conf["vendor"])
raise MoulinetteError('error_see_log')
else:
return mod.Authenticator(**auth_conf)
def check_authentication_if_required(self, args, **kwargs): def check_authentication_if_required(self, args, **kwargs):

View file

@ -396,26 +396,6 @@ def init_interface(name, kwargs={}, actionsmap={}):
return interface(amap, **kwargs) return interface(amap, **kwargs)
def init_authenticator(auth_conf):
"""Return a new authenticator instance
Retrieve the given authenticator vendor and return a new instance of
its Authenticator class for the given profile.
Keyword arguments:
- vendor -- The authenticator vendor name
- name -- The authenticator profile name
- kwargs -- A dict of arguments for the authenticator profile
"""
try:
mod = import_module('moulinette.authenticators.%s' % auth_conf["vendor"])
except ImportError:
logger.exception("unable to load authenticator vendor '%s'", auth_conf["vendor"])
raise MoulinetteError('error_see_log')
else:
return mod.Authenticator(**auth_conf)
def clean_session(session_id, profiles=[]): def clean_session(session_id, profiles=[]):
"""Clean a session cache """Clean a session cache