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 #1550
  • Loading branch information
MichalPysik committed Jun 25, 2024
1 parent ce05037 commit 1f328cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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.
2 changes: 1 addition & 1 deletion pulp_container/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class PulpContainerPluginAppConfig(PulpPluginAppConfig):
python_package_name = "pulp-container"

def ready(self):
super().ready()
super().ready()
28 changes: 28 additions & 0 deletions pulp_container/app/dynaconf_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from dynaconf import Validator


token_auth_disabled_validator = Validator("TOKEN_AUTH_DISABLED", eq=True)
token_server_validator = Validator("TOKEN_SERVER", must_exist=True)
token_signature_algorithm_validator = Validator("TOKEN_SIGNATURE_ALGORITHM", must_exist=True)
public_key_path_validator = Validator("PUBLIC_KEY_PATH", must_exist=True)
private_key_path_validator = Validator("PRIVATE_KEY_PATH", must_exist=True)


def post(settings) -> dict:
"""
Post load hook for Pulp settings to validate Container-specific variables.
"""
container_settings_validator = token_auth_disabled_validator | (
token_server_validator
& token_signature_algorithm_validator
& public_key_path_validator
& private_key_path_validator
)
container_settings_validator.messages["combined"] = (
"When token authentification is enabled ('TOKEN_AUTH_DISABLED=False'), all of the "
"following settings variables must be set: 'TOKEN_SERVER', 'TOKEN_SIGNATURE_ALGORITHM', "
"'PUBLIC_KEY_PATH', 'PRIVATE_KEY_PATH'. Please check your Pulp config file."
)
container_settings_validator.validate(settings)

return {}

0 comments on commit 1f328cd

Please sign in to comment.