Skip to content

Commit

Permalink
Merge pull request #7120 from freedomofpress/6784-hot-reload
Browse files Browse the repository at this point in the history
fix(`SecureDropConfig`): pass `env` for inferring debug mode
  • Loading branch information
zenmonkeykstop committed Feb 29, 2024
2 parents 703e325 + 8bde6e7 commit ae491cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions securedrop/sdconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class SecureDropConfig:

RQ_WORKER_NAME: str

env: str = "prod"

@property
def TEMP_DIR(self) -> Path:
# We use a directory under the SECUREDROP_DATA_ROOT instead of `/tmp` because
Expand Down Expand Up @@ -115,6 +117,8 @@ def _parse_config_from_file(config_module_name: str) -> SecureDropConfig:
config_from_local_file, "SCRYPT_PARAMS", dict(N=2**14, r=8, p=1)
)

env = getattr(config_from_local_file, "env", "prod")

try:
final_securedrop_root = Path(config_from_local_file.SECUREDROP_ROOT)
except AttributeError:
Expand Down Expand Up @@ -188,6 +192,7 @@ def _parse_config_from_file(config_module_name: str) -> SecureDropConfig:
)

return SecureDropConfig(
env=env,
JOURNALIST_APP_FLASK_CONFIG_CLS=parsed_journ_flask_config,
SOURCE_APP_FLASK_CONFIG_CLS=parsed_source_flask_config,
GPG_KEY_DIR=final_gpg_key_dir,
Expand Down
8 changes: 6 additions & 2 deletions securedrop/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ def test_parse_current_config():
try:
current_config_file.write_text(current_sample_config.read_text())

# When trying to parse it, it succeeds
assert _parse_config_from_file(f"tests.{current_config_module}")
# When trying to parse it, it succeeds...
parsed_config = _parse_config_from_file(f"tests.{current_config_module}")
assert parsed_config

# ...and has one of our `env` values rather than one of Flask's:
assert parsed_config.env in ["prod", "dev", "test"]

finally:
current_config_file.unlink(missing_ok=True)

0 comments on commit ae491cc

Please sign in to comment.