Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions pulpcore/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from contextlib import suppress
from importlib import import_module
from importlib.metadata import entry_points
from logging import getLogger
from pathlib import Path

from cryptography.fernet import Fernet
Expand Down Expand Up @@ -629,6 +628,49 @@ def enable_v4_hook(settings):
return data


def api_root_hook(settings):
# protocol://host:port/{API_ROOT}{domain}/api/{version}/
# All of the below are DEPRECATED, and should be replaced by calling
# pulpcore.plugin.find_url.find_api_root() (q.v.)
if settings.API_ROOT_REWRITE_HEADER:
api_root = "/<path:api_root>/"
else:
api_root = settings.API_ROOT
return {
"V3_API_ROOT": api_root + "api/v3/",
"V3_DOMAIN_API_ROOT": api_root + "<slug:pulp_domain>/api/v3/",
"V3_API_ROOT_NO_FRONT_SLASH": (api_root + "api/v3/").lstrip("/"),
"V3_DOMAIN_API_ROOT_NO_FRONT_SLASH": (api_root + "<slug:pulp_domain>/api/v3/").lstrip("/"),
}


def forbidden_checksums_hook(settings):
return {
"FORBIDDEN_CHECKSUMS": sorted(
set(constants.ALL_KNOWN_CONTENT_CHECKSUMS).difference(
settings.ALLOWED_CONTENT_CHECKSUMS
)
),
}


def validate_db_encryption_key_hook(settings):
if Path(sys.argv[0]).name in ["pytest", "sphinx-build"] or (
len(sys.argv) >= 2 and sys.argv[1] in ["collectstatic", "openapi"]
):
return {}
try:
with open(settings.DB_ENCRYPTION_KEY, "rb") as key_file:
Fernet(key_file.read())
except Exception as ex:
raise ImproperlyConfigured(
"Could not load DB_ENCRYPTION_KEY file '{file}': {err}".format(
file=settings.DB_ENCRYPTION_KEY, err=ex
)
)
return {}

@pedro-psb pedro-psb Jul 21, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, if on setting depend on another setting, it should be inside a hook, and not after the dynaconf instantiation. For instance, FORBIDDEN_CHECKSUMS was not picking up the user provided ALLOWED_CONTENT_CHECKSUMS.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize this was a PR on 3.115 - we need this on main, please

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I should have opened against main and then added the backport label.
Was caught in moment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



del preload_settings

settings = DjangoDynaconf(
Expand Down Expand Up @@ -657,40 +699,11 @@ def enable_v4_hook(settings):
otel_middleware_hook,
saml2_settings_hook,
enable_v4_hook,
api_root_hook,
forbidden_checksums_hook,
validate_db_encryption_key_hook,
),
dynaboxify=False,
)

_logger = getLogger(__name__)


if not (
Path(sys.argv[0]).name in ["pytest", "sphinx-build"]
or (len(sys.argv) >= 2 and sys.argv[1] in ["collectstatic", "openapi"])
):
try:
with open(DB_ENCRYPTION_KEY, "rb") as key_file:
Fernet(key_file.read())
except Exception as ex:
raise ImproperlyConfigured(
("Could not load DB_ENCRYPTION_KEY file '{file}': {err}").format(
file=DB_ENCRYPTION_KEY, err=ex
)
)


FORBIDDEN_CHECKSUMS = set(constants.ALL_KNOWN_CONTENT_CHECKSUMS).difference(
ALLOWED_CONTENT_CHECKSUMS
)

# protocol://host:port/{API_ROOT}{domain}/api/{version}/
# All of the below are DEPRECATED, and should be replaced by calling
# pulpcore.plugin.find_url.find_api_root() (q.v.)
if settings.API_ROOT_REWRITE_HEADER:
api_root = "/<path:api_root>/"
else:
api_root = settings.API_ROOT
settings.set("V3_API_ROOT", api_root + "api/v3/") # Not user configurable
settings.set("V3_DOMAIN_API_ROOT", api_root + "<slug:pulp_domain>/api/v3/")
settings.set("V3_API_ROOT_NO_FRONT_SLASH", settings.V3_API_ROOT.lstrip("/"))
settings.set("V3_DOMAIN_API_ROOT_NO_FRONT_SLASH", settings.V3_DOMAIN_API_ROOT.lstrip("/"))
# HERE ENDS DYNACONF EXTENSION LOAD (No more code below this line)
Loading