Skip to content

Commit

Permalink
Allow selecting enabled plugins
Browse files Browse the repository at this point in the history
fixes #5235

Co-Authored-By: Pedro Brochado <[email protected]>
  • Loading branch information
mdellweg and pedro-psb committed Feb 17, 2025
1 parent acea1e5 commit f7b6020
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGES/5235.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``ENABLED_PLUGINS`` option to allow selecting installed plugins to be enabled.
5 changes: 5 additions & 0 deletions docs/admin/reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 21 additions & 13 deletions pulpcore/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -264,4 +264,4 @@ replace = "version = \"{new_version}\""

filename = "./pyproject.toml"
search = "version = \"{current_version}\""
replace = "version = \"{new_version}\""
replace = "version = \"{new_version}\""

0 comments on commit f7b6020

Please sign in to comment.