From 19c3193c02ba6ed59b26547ca49cf38f6e474b61 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 21 Oct 2026 12:48:39 +1100 Subject: [PATCH] config: simplify SentryConfig env override (bug 2058322) --- README.md | 2 +- config-development.toml | 2 +- config-docker.toml | 2 +- config-production.toml | 2 +- config-staging.toml | 2 +- config.toml.example | 2 +- git_hg_sync/__main__.py | 6 +++--- git_hg_sync/config.py | 4 +--- tests/data/config.toml | 3 +++ tests/test_config.py | 9 ++------- 10 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 19f9bc1..d714f6d 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ configuration file can be specified with the `--config` (`-c`) option. It contains 6 main sections: - `pulse` holds the exchange configuration (can be overridden by environment, see below) -- `sentry` contains the `sentry_dsn` for monitoring +- `sentry` contains the `dsn` for monitoring - `clones` allows to set the `directory` in which local work clones will be created - `tracked_repositories` provides `name` and source `url` for Git repos to track - `branch_mappings` describes which Git repo and branches should be synced to which Hg repo diff --git a/config-development.toml b/config-development.toml index 20807ed..f0194ab 100644 --- a/config-development.toml +++ b/config-development.toml @@ -13,7 +13,7 @@ heartbeat = 30 queue = "queue/githgsyncdev/pushes" [sentry] -sentry_dsn = "" +dsn = "" [clones] directory = "/clones" diff --git a/config-docker.toml b/config-docker.toml index c58fdf2..3213e58 100644 --- a/config-docker.toml +++ b/config-docker.toml @@ -10,7 +10,7 @@ heartbeat = 30 ssl = false [sentry] -sentry_dsn = "" +dsn = "" [clones] directory = "/clones" diff --git a/config-production.toml b/config-production.toml index 8292fb9..41d0a4b 100644 --- a/config-production.toml +++ b/config-production.toml @@ -17,7 +17,7 @@ routing_key = "" queue = "" [sentry] -sentry_dsn = "" +dsn = "" [clones] directory = "/clones" diff --git a/config-staging.toml b/config-staging.toml index 014ec20..a233ee0 100644 --- a/config-staging.toml +++ b/config-staging.toml @@ -13,7 +13,7 @@ heartbeat = 30 queue = "queue/githgsyncstage/pushes" [sentry] -sentry_dsn = "" +dsn = "" [clones] directory = "/clones" diff --git a/config.toml.example b/config.toml.example index 7f6c8b1..da61df9 100644 --- a/config.toml.example +++ b/config.toml.example @@ -10,7 +10,7 @@ heartbeat = 30 ssl = true [sentry] -sentry_dsn = "" +dsn = "" [clones] directory = "../git_hg_sync_repos/" diff --git a/git_hg_sync/__main__.py b/git_hg_sync/__main__.py index cd598d9..58682ff 100644 --- a/git_hg_sync/__main__.py +++ b/git_hg_sync/__main__.py @@ -86,9 +86,9 @@ def main() -> None: sys.exit(1) sentry_config = config.sentry - if sentry_config and sentry_config.sentry_dsn: - logger.info(f"Sentry DSN: {sentry_config.sentry_dsn}") - sentry_sdk.init(sentry_config.sentry_dsn, max_value_length=4096) + if sentry_config and sentry_config.dsn: + logger.info(f"Sentry DSN: {sentry_config.dsn}") + sentry_sdk.init(sentry_config.dsn, max_value_length=4096) start_app(config, logger) diff --git a/git_hg_sync/config.py b/git_hg_sync/config.py index dbc9ac4..f65afa4 100644 --- a/git_hg_sync/config.py +++ b/git_hg_sync/config.py @@ -8,8 +8,6 @@ from mozlog import get_proxy_logger from pydantic import ( AfterValidator, - AliasChoices, - Field, ValidationInfo, model_validator, ) @@ -57,7 +55,7 @@ class ClonesConfig(BaseSettings): class SentryConfig(BaseSettings): - sentry_dsn: Annotated[str, Field(alias=AliasChoices("sentry_dsn", "dsn"))] = "" + dsn: str = "" class Config(BaseSettings): diff --git a/tests/data/config.toml b/tests/data/config.toml index 32bf267..180fc19 100644 --- a/tests/data/config.toml +++ b/tests/data/config.toml @@ -9,6 +9,9 @@ password = "guest" heartbeat = 30 ssl = false +[sentry] +dsn = "" + [clones] directory = "{directory}/clones" diff --git a/tests/test_config.py b/tests/test_config.py index c348c8c..7f86e86 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -30,18 +30,13 @@ def test_load_config_env_override(monkeypatch: pytest.MonkeyPatch) -> None: "heartbeat": "42", }, "sentry": { - "sentry_dsn": "overridden sentry_dsn", + "dsn": "overridden sentry_dsn", }, } - no_prefix_sections = ["sentry"] - for section, env in overrides.items(): for var, value in env.items(): - if section in no_prefix_sections: - monkeypatch.setenv(f"{var}".upper(), value) - else: - monkeypatch.setenv(f"{section}_{var}".upper(), value) + monkeypatch.setenv(f"{section}_{var}".upper(), value) config = Config.from_file(HERE / "data" / "config.toml")