Skip to content

Commit

Permalink
Validate settings before running Pulp instance
Browse files Browse the repository at this point in the history
When token authentization is enabled, 4 additional variables have to be
set. The state of these variables is now checked, while properly
informing the user, instead of relying on exceptions raised later during
the instance's run.

closes pulp#1550
  • Loading branch information
MichalPysik committed Jun 25, 2024
1 parent ce05037 commit 462ea3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/1550.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pulp Container specific settings are now properly validated at startup of a Pulp instance.
24 changes: 24 additions & 0 deletions pulp_container/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from pulpcore.plugin import PulpPluginAppConfig
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured


class PulpContainerPluginAppConfig(PulpPluginAppConfig):
Expand All @@ -11,3 +13,25 @@ class PulpContainerPluginAppConfig(PulpPluginAppConfig):

def ready(self):
super().ready()

if missing_settings := self.get_missing_settings():
raise ImproperlyConfigured(
f"Missing required settings for token authentication: {', '.join(missing_settings)}"
)

def get_missing_settings(self):
# Checks only needed if token auth is enabled
if str(getattr(settings, "TOKEN_AUTH_DISABLED", False)).lower() == "true":
return None

missing_settings = []
if getattr(settings, "TOKEN_SERVER", None) is None:
missing_settings.append("TOKEN_SERVER")
if getattr(settings, "TOKEN_SIGNATURE_ALGORITHM", None) is None:
missing_settings.append("TOKEN_SIGNATURE_ALGORITHM")
if getattr(settings, "PUBLIC_KEY_PATH", None) is None:
missing_settings.append("PUBLIC_KEY_PATH")
if getattr(settings, "PRIVATE_KEY_PATH", None) is None:
missing_settings.append("PRIVATE_KEY_PATH")

return missing_settings

0 comments on commit 462ea3c

Please sign in to comment.