From f6c229d2ef07e0c01049da740a3bcec15378bd32 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 6 Dec 2021 23:44:07 +0100 Subject: [PATCH] feat(core): Selected authentification plugin is always enabled --- flaschengeist/app.py | 34 ++++++++++++++++++-------------- flaschengeist/flaschengeist.toml | 4 ---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/flaschengeist/app.py b/flaschengeist/app.py index b886f78..a2933fe 100644 --- a/flaschengeist/app.py +++ b/flaschengeist/app.py @@ -36,18 +36,21 @@ class CustomJSONEncoder(JSONEncoder): def __load_plugins(app): - logger.info("Search for plugins") + logger.debug("Search for plugins") + app.config["FG_PLUGINS"] = {} for entry_point in pkg_resources.iter_entry_points("flaschengeist.plugins"): - logger.debug("Found plugin: >{}<".format(entry_point.name)) - plugin = None - if entry_point.name in config and config[entry_point.name].get("enabled", False): + logger.debug(f"Found plugin: >{entry_point.name}<") + + if entry_point.name == config["FLASCHENGEIST"]["auth"] or ( + entry_point.name in config and config[entry_point.name].get("enabled", False) + ): + logger.debug(f"Load plugin {entry_point.name}") try: - logger.info(f"Load plugin {entry_point.name}") plugin = entry_point.load() if not hasattr(plugin, "name"): setattr(plugin, "name", entry_point.name) - plugin = plugin(config[entry_point.name]) + plugin = plugin(config.get(entry_point.name, {})) if hasattr(plugin, "blueprint") and plugin.blueprint is not None: app.register_blueprint(plugin.blueprint) except: @@ -55,17 +58,18 @@ def __load_plugins(app): f"Plugin {entry_point.name} was enabled, but could not be loaded due to an error.", exc_info=True, ) - del plugin continue - if isinstance(plugin, AuthPlugin): - logger.debug(f"Found authentication plugin: {entry_point.name}") - if entry_point.name == config["FLASCHENGEIST"]["auth"]: - app.config["FG_AUTH_BACKEND"] = plugin + if isinstance(plugin, AuthPlugin): + if entry_point.name != config["FLASCHENGEIST"]["auth"]: + logger.debug(f"Unload not configured AuthPlugin {entry_point.name}") + del plugin + continue + else: + logger.info(f"Using authentication plugin: {entry_point.name}") + app.config["FG_AUTH_BACKEND"] = plugin else: - del plugin - continue - if plugin: - app.config["FG_PLUGINS"][entry_point.name] = plugin + logger.info(f"Using plugin: {entry_point.name}") + app.config["FG_PLUGINS"][entry_point.name] = plugin if "FG_AUTH_BACKEND" not in app.config: logger.error("No authentication plugin configured or authentication plugin not found") raise RuntimeError("No authentication plugin configured or authentication plugin not found") diff --git a/flaschengeist/flaschengeist.toml b/flaschengeist/flaschengeist.toml index 335a3c3..2ef5c84 100644 --- a/flaschengeist/flaschengeist.toml +++ b/flaschengeist/flaschengeist.toml @@ -44,12 +44,8 @@ allowed_mimetypes = [ "image/webp" ] -[auth_plain] -enabled = true - [auth_ldap] # Full documentation https://flaschengeist.dev/Flaschengeist/flaschengeist/wiki/plugins_auth_ldap -enabled = false # host = "localhost" # port = 389 # base_dn = "dc=example,dc=com"