-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate settings before running Pulp instance
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
1 parent
05c2f1c
commit 4ac1d9c
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dynaconf import Validator | ||
import sys | ||
|
||
|
||
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. | ||
""" | ||
if "collectstatic" in sys.argv: | ||
return {} | ||
|
||
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 {} |