Skip to content

slightly safer config variable setting#62

Open
megies wants to merge 1 commit into
masterfrom
safer_config_getters
Open

slightly safer config variable setting#62
megies wants to merge 1 commit into
masterfrom
safer_config_getters

Conversation

@megies
Copy link
Copy Markdown
Contributor

@megies megies commented May 28, 2026

Could make an actual difference if the desired value is set as an OS environment variable and if that value evaluates to False with bool()

E.g. if trying to set an empty string or the number zero it might inadvertently get overridden by the default value from config.

Wasn't sure what branch to base it on, can rebase it or just cherry-pick this wherever appropriate.

could make an actual difference if the desired value is set as an OS
environment variable and if that value evaluates to False with bool()

E.g. if trying to set an empty string or the number zero it might
inadvertantly get overridden by the default value from config
NikolaosSokos added a commit to NikolaosSokos/ws-availability that referenced this pull request May 28, 2026
Static check: regex over config.py.sample fails if anyone reintroduces
the `os.environ.get(...) or DEFAULT` shape that PR EIDA#62 replaced.

The `or` form falls back to DEFAULT when env is the empty string (and,
in numeric contexts, when env is "0"), silently ignoring an operator
who genuinely wants to set that value.
NikolaosSokos added a commit to NikolaosSokos/ws-availability that referenced this pull request May 28, 2026
BETA.md updates from Tobias's beta review:
- Step 2 install: `cp -n config.py.sample config.py` (no-clobber) replaces
  the two-line `[ -f config.py ] || cp ...` conditional.
- Sentry example for v1.0.3 upgraders uses the PR EIDA#62 safer pattern
  `os.environ.get("X", default)` (we don't want operators copying the
  old leaky shape we just removed).
- One-sentence callout at the top of Install explaining config.py is now
  the only place for MongoDB / FDSNWS-Station / Sentry settings — paired
  with the runtime change from commit 30c86b5.

Regression tests in tests/test_docker_compose.py:
- BETA.md must contain `cp -n config.py.sample config.py` and must NOT
  contain the conditional pattern.
- BETA.md code snippets must NOT use `os.environ.get(...) or X`.

61/61 tests pass.
NikolaosSokos added a commit to NikolaosSokos/ws-availability that referenced this pull request May 28, 2026
Tobias's beta review: "I do firmly believe the number of workers should
be settable in the config, as opposed to having to patch the actual
code — even if it's in a yaml."

Adds gunicorn.conf.py which reads workers from Config.GUNICORN_WORKERS,
defaulting to 1 when config.py isn't present (gunicorn must always be
able to boot). docker-compose.yml's api command now invokes gunicorn
with -c gunicorn.conf.py instead of a hardcoded --workers; same change
on Dockerfile.api's CMD so the image works without compose too.

config.py.sample gets GUNICORN_WORKERS = 1 in both RUNMODE blocks plus
an int-coerced env override using the PR EIDA#62 safer pattern. README.md
gains a config-table row and the Tuning section now points at config.py.

Tests (tests/test_gunicorn_conf.py):
- workers reads from Config.GUNICORN_WORKERS when present
- falls back to 1 when GUNICORN_WORKERS missing
- falls back to 1 when config.py itself is missing
- coerces string env value to int
- docker-compose api command uses -c gunicorn.conf.py, no hardcoded --workers
- Dockerfile.api COPYs gunicorn.conf.py into the image

67/67 tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant