From f7b6020ced445749017becd322f6d339eb55faa1 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 #5235 Co-Authored-By: Pedro Brochado --- CHANGES/5235.feature | 1 + docs/admin/reference/settings.md | 5 +++++ pulpcore/app/settings.py | 34 ++++++++++++++++++++------------ pyproject.toml | 4 ++-- 4 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 CHANGES/5235.feature diff --git a/CHANGES/5235.feature b/CHANGES/5235.feature new file mode 100644 index 00000000000..ca6e2f966f6 --- /dev/null +++ b/CHANGES/5235.feature @@ -0,0 +1 @@ +Added ``ENABLED_PLUGINS`` option to allow selecting installed plugins to be enabled. diff --git a/docs/admin/reference/settings.md b/docs/admin/reference/settings.md index 8d895020cc9..8ebb2fe0f6b 100644 --- a/docs/admin/reference/settings.md +++ b/docs/admin/reference/settings.md @@ -196,6 +196,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 diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py index e03678ed2a5..b7b52e04c4a 100644 --- a/pulpcore/app/settings.py +++ b/pulpcore/app/settings.py @@ -120,14 +120,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 entry_points(group="pulpcore.plugin"): - plugin_app_config = entry_point.load() - INSTALLED_PULP_PLUGINS.append(entry_point.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", @@ -390,9 +382,17 @@ # HERE STARTS DYNACONF EXTENSION LOAD (Keep at the very bottom of settings.py) # Read more at https://www.dynaconf.com/django/ -from dynaconf import DjangoDynaconf, Validator # noqa +from dynaconf import DjangoDynaconf, Dynaconf, Validator # noqa # Validators + +enabled_plugins_validator = Validator( + "ENABLED_PLUGINS", + is_type_of=list, + len_min=1, + when=Validator("ENABLED_PLUGINS", must_exist=True), +) + storage_keys = ("STORAGES.default.BACKEND", "DEFAULT_FILE_STORAGE") storage_validator = ( Validator("REDIRECT_TO_OBJECT_STORAGE", eq=False) @@ -493,23 +493,31 @@ def otel_middleware_hook(settings): __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", load_dotenv=False, validators=[ api_root_validator, cache_validator, + enabled_plugins_validator, sha256_validator, storage_validator, unknown_algs_validator, json_header_auth_validator, authentication_json_header_openapi_security_scheme_validator, ], - post_hooks=otel_middleware_hook, + post_hooks=(otel_middleware_hook,), ) +# Select enabled plugins and load their settings. +enabled_plugins = settings.get("ENABLED_PLUGINS", None) +for entry_point in entry_points(group="pulpcore.plugin"): + if enabled_plugins and entry_point.name not in enabled_plugins: + continue + if (plugin_app := entry_point.load()) not in settings.INSTALLED_APPS: + settings.load_file(f"{entry_point.module}.app.settings") + settings.INSTALLED_APPS += [plugin_app] +INSTALLED_APPS = settings.INSTALLED_APPS + # begin compatibility layer for DEFAULT_FILE_STORAGE # Remove on pulpcore=3.85 or pulpcore=4.0 diff --git a/pyproject.toml b/pyproject.toml index 8b9e25b18e3..c7d74f42ca6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ dependencies = [ "drf-access-policy>=1.1.2,<1.5.1", "drf-nested-routers>=0.93.4,<=0.94.1", "drf-spectacular==0.27.2", # We monkeypatch this so we need a very narrow requirement string - "dynaconf>=3.1.12,<3.3.0", + "dynaconf>=3.2.5,<3.3.0", "gunicorn>=20.1,<23.1.0", "importlib-metadata>=6.0.1,<=6.0.1", # Pinned to fix opentelemetry dependency solving issues with pip "jinja2>=3.1,<=3.1.5", @@ -264,4 +264,4 @@ replace = "version = \"{new_version}\"" filename = "./pyproject.toml" search = "version = \"{current_version}\"" -replace = "version = \"{new_version}\"" \ No newline at end of file +replace = "version = \"{new_version}\""