From 3ccf10225d31c81fe92a36c32cd890fd910e4aa4 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Tue, 27 Feb 2024 13:19:15 +0100 Subject: [PATCH] Allow selecting enabled plugins fixes TBA --- CHANGES/+select_plugins.feature | 1 + pulpcore/app/settings.py | 41 +++++++++++++++++++--------- staging_docs/admin/learn/settings.md | 5 ++++ 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 CHANGES/+select_plugins.feature diff --git a/CHANGES/+select_plugins.feature b/CHANGES/+select_plugins.feature new file mode 100644 index 00000000000..ca6e2f966f6 --- /dev/null +++ b/CHANGES/+select_plugins.feature @@ -0,0 +1 @@ +Added ``ENABLED_PLUGINS`` option to allow selecting installed plugins to be enabled. diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py index 23026460cc6..a17d4224fd9 100644 --- a/pulpcore/app/settings.py +++ b/pulpcore/app/settings.py @@ -12,9 +12,10 @@ from contextlib import suppress from importlib import import_module +from importlib.metadata import entry_points +from pkg_resources import iter_entry_points from logging import getLogger from pathlib import Path -from pkg_resources import iter_entry_points from cryptography.fernet import Fernet from django.core.exceptions import ImproperlyConfigured @@ -81,14 +82,6 @@ "pulpcore.app", ] -# Enumerate the installed Pulp plugins during the loading process for use in the status API -INSTALLED_PULP_PLUGINS = [] - -for entry_point in iter_entry_points("pulpcore.plugin"): - plugin_app_config = entry_point.load() - INSTALLED_PULP_PLUGINS.append(entry_point.module_name) - INSTALLED_APPS.append(plugin_app_config) - # Optional apps that help with development, or augment Pulp in some non-critical way OPTIONAL_APPS = [ "crispy_forms", @@ -314,7 +307,7 @@ # HERE STARTS DYNACONF EXTENSION LOAD (Keep at the very bottom of settings.py) # Read more at https://dynaconf.readthedocs.io/en/latest/guides/django.html -from dynaconf import DjangoDynaconf, Validator # noqa +from dynaconf import DjangoDynaconf, Dynaconf, Validator # noqa # Validators content_origin_validator = Validator( @@ -380,14 +373,36 @@ ) +def load_plugin_config_hook(settings): + # Enumerate the installed Pulp plugins during the loading process for use in the status API + ENABLED_PLUGINS = getattr(settings, "ENABLED_PLUGINS", None) + installed_plugins = [] + installed_plugin_apps = [] + + for entry_point in entry_points()["pulpcore.plugin"]: + if ENABLED_PLUGINS is not None and entry_point.name not in ENABLED_PLUGINS: + continue + installed_plugins.append(entry_point.module) + installed_plugin_apps.append(entry_point.load()) + + plugin_settings = Dynaconf( + PRELOAD_FOR_DYNACONF=[f"{module}.app.settings" for module in installed_plugins] + ) + + data = {"dynaconf_merge": True} + data.update(plugin_settings.as_dict()) + data.update(settings.as_dict()) + data["INSTALLED_APPS"].extend(installed_plugin_apps) + data["INSTALLED_APPS"].append("dynaconf_merge_unique") + return data + + settings = DjangoDynaconf( __name__, ENVVAR_PREFIX_FOR_DYNACONF="PULP", ENV_SWITCHER_FOR_DYNACONF="PULP_ENV", - PRELOAD_FOR_DYNACONF=[ - "{}.app.settings".format(plugin_name) for plugin_name in INSTALLED_PULP_PLUGINS - ], ENVVAR_FOR_DYNACONF="PULP_SETTINGS", + post_hooks=(load_plugin_config_hook,), load_dotenv=False, validators=[ api_root_validator, diff --git a/staging_docs/admin/learn/settings.md b/staging_docs/admin/learn/settings.md index 84efeae6eb3..8562593672a 100644 --- a/staging_docs/admin/learn/settings.md +++ b/staging_docs/admin/learn/settings.md @@ -157,6 +157,11 @@ The password for Redis. Pulp defines the following settings itself: +### ENABLED_PLUGINS + +An optional list of plugin names. +If provided, Pulp will limit loading plugins to this list. +If omitted, Pulp will load all installed plugins. ### API_ROOT