|
12 | 12 |
|
13 | 13 | from contextlib import suppress
|
14 | 14 | from importlib import import_module
|
| 15 | +from importlib.metadata import entry_points |
15 | 16 | from logging import getLogger
|
16 | 17 | from pathlib import Path
|
17 |
| -from pkg_resources import iter_entry_points |
18 | 18 |
|
19 | 19 | from cryptography.fernet import Fernet
|
20 | 20 | from django.core.exceptions import ImproperlyConfigured
|
|
81 | 81 | "pulpcore.app",
|
82 | 82 | ]
|
83 | 83 |
|
84 |
| -# Enumerate the installed Pulp plugins during the loading process for use in the status API |
85 |
| -INSTALLED_PULP_PLUGINS = [] |
86 |
| - |
87 |
| -for entry_point in iter_entry_points("pulpcore.plugin"): |
88 |
| - plugin_app_config = entry_point.load() |
89 |
| - INSTALLED_PULP_PLUGINS.append(entry_point.module_name) |
90 |
| - INSTALLED_APPS.append(plugin_app_config) |
91 |
| - |
92 | 84 | # Optional apps that help with development, or augment Pulp in some non-critical way
|
93 | 85 | OPTIONAL_APPS = [
|
94 | 86 | "crispy_forms",
|
|
314 | 306 |
|
315 | 307 | # HERE STARTS DYNACONF EXTENSION LOAD (Keep at the very bottom of settings.py)
|
316 | 308 | # Read more at https://dynaconf.readthedocs.io/en/latest/guides/django.html
|
317 |
| -from dynaconf import DjangoDynaconf, Validator # noqa |
| 309 | +from dynaconf import DjangoDynaconf, Dynaconf, Validator # noqa |
318 | 310 |
|
319 | 311 | # Validators
|
320 | 312 | content_origin_validator = Validator(
|
|
380 | 372 | )
|
381 | 373 |
|
382 | 374 |
|
| 375 | +def load_plugin_config_hook(settings): |
| 376 | + # Enumerate the installed Pulp plugins during the loading process for use in the status API |
| 377 | + ENABLED_PLUGINS = getattr(settings, "ENABLED_PLUGINS", None) |
| 378 | + installed_plugins = [] |
| 379 | + installed_plugin_apps = [] |
| 380 | + |
| 381 | + for entry_point in entry_points()["pulpcore.plugin"]: |
| 382 | + if ENABLED_PLUGINS is not None and entry_point.name not in ENABLED_PLUGINS: |
| 383 | + continue |
| 384 | + installed_plugins.append(entry_point.module) |
| 385 | + installed_plugin_apps.append(entry_point.load()) |
| 386 | + |
| 387 | + plugin_settings = Dynaconf( |
| 388 | + PRELOAD_FOR_DYNACONF=[f"{module}.app.settings" for module in installed_plugins] |
| 389 | + ) |
| 390 | + |
| 391 | + data = {"dynaconf_merge": True} |
| 392 | + data.update(plugin_settings.as_dict()) |
| 393 | + data.update(settings.as_dict()) |
| 394 | + data["INSTALLED_APPS"].extend(installed_plugin_apps) |
| 395 | + data["INSTALLED_APPS"].append("dynaconf_merge_unique") |
| 396 | + return data |
| 397 | + |
| 398 | + |
383 | 399 | settings = DjangoDynaconf(
|
384 | 400 | __name__,
|
385 | 401 | ENVVAR_PREFIX_FOR_DYNACONF="PULP",
|
386 | 402 | ENV_SWITCHER_FOR_DYNACONF="PULP_ENV",
|
387 |
| - PRELOAD_FOR_DYNACONF=[ |
388 |
| - "{}.app.settings".format(plugin_name) for plugin_name in INSTALLED_PULP_PLUGINS |
389 |
| - ], |
390 | 403 | ENVVAR_FOR_DYNACONF="PULP_SETTINGS",
|
| 404 | + post_hooks=(load_plugin_config_hook,), |
391 | 405 | load_dotenv=False,
|
392 | 406 | validators=[
|
393 | 407 | api_root_validator,
|
|
0 commit comments