From ac4a4c34b1ca253fd2e84a2bc8b4bfe9a94a2880 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 2 Jan 2020 12:17:12 +0800 Subject: [PATCH] use default authenticator if none is defined --- moulinette/interfaces/__init__.py | 65 +++++++++++++++---------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index 27c86da6..2f6c7c23 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -256,45 +256,44 @@ class BaseActionsMapParser(object): raise MoulinetteError("error_see_log") # -- 'authenticator' - try: + if "authenticator" in configuration: auth = configuration["authenticator"] - except KeyError: - pass else: - if not is_global and isinstance(auth, str): - try: - # Store needed authenticator profile - conf["authenticator"] = self.global_conf["authenticator"][auth] - except KeyError: - logger.error( - "requesting profile '%s' which is undefined in " - "global configuration of 'authenticator'", - auth, - ) - raise MoulinetteError("error_see_log") - elif is_global and isinstance(auth, dict): - if len(auth) == 0: - logger.warning( - "no profile defined in global configuration " - "for 'authenticator'" - ) - else: - auths = {} - for auth_name, auth_conf in auth.items(): - 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: + auth = 'default' + if not is_global and isinstance(auth, str): + # Store needed authenticator profile + if auth not in self.global_conf["authenticator"]: logger.error( - "expecting a dict of profile(s) or a profile name " - "for configuration 'authenticator', got %r", + "requesting profile '%s' which is undefined in " + "global configuration of 'authenticator'", auth, ) raise MoulinetteError("error_see_log") + else: + conf["authenticator"] = auth + elif is_global and isinstance(auth, dict): + if len(auth) == 0: + logger.warning( + "no profile defined in global configuration " + "for 'authenticator'" + ) + else: + auths = {} + for auth_name, auth_conf in auth.items(): + 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 " + "for configuration 'authenticator', got %r", + auth, + ) + raise MoulinetteError("error_see_log") return conf