feat(gateway): GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS opt-out for relay-exclusive mode
Deployments that intentionally mix connector-fronted and direct ingress can set GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS=true to keep directly- connected messaging adapters enabled beside the relay. Unset, the GATEWAY_RELAY_URL env stamp keeps its exclusive behavior. Like the trigger, the opt-out is a deploy-stamp env var, not config.yaml.
This commit is contained in:
+9
-1
@@ -2772,7 +2772,15 @@ def _apply_env_overrides(config: GatewayConfig) -> None:
|
||||
# Deployments that configure relay only via gateway.relay_url in
|
||||
# config.yaml keep the old additive behavior (relay beside direct
|
||||
# adapters).
|
||||
if relay_url_env:
|
||||
#
|
||||
# Opt-out: GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS=true keeps direct
|
||||
# adapters running beside the relay for deployments that intentionally
|
||||
# mix both ingress paths. Like the trigger, it is a deploy-stamp env var,
|
||||
# not a config.yaml setting.
|
||||
allow_direct = os.getenv(
|
||||
"GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS", ""
|
||||
).strip().lower() in ("1", "true", "yes", "on")
|
||||
if relay_url_env and not allow_direct:
|
||||
non_messaging = {Platform.LOCAL, Platform.API_SERVER, Platform.WEBHOOK}
|
||||
for platform, platform_config in config.platforms.items():
|
||||
if platform is Platform.RELAY or platform in non_messaging:
|
||||
|
||||
@@ -746,6 +746,31 @@ class TestLoadGatewayConfig:
|
||||
assert config.platforms[Platform.TELEGRAM].enabled is True
|
||||
|
||||
|
||||
def test_relay_env_url_opt_out_keeps_direct_platforms(self, tmp_path, monkeypatch):
|
||||
"""GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS=true opts a deployment out of
|
||||
the relay-exclusive sweep: direct adapters stay enabled beside the
|
||||
relay even with the GATEWAY_RELAY_URL env stamp present."""
|
||||
hermes_home = tmp_path / ".hermes"
|
||||
hermes_home.mkdir()
|
||||
config_path = hermes_home / "config.yaml"
|
||||
config_path.write_text(
|
||||
"gateway:\n"
|
||||
" platforms:\n"
|
||||
" telegram:\n"
|
||||
" enabled: true\n"
|
||||
" bot_token: '123:abc'\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
|
||||
monkeypatch.setenv("GATEWAY_RELAY_URL", "https://connector.example/relay")
|
||||
monkeypatch.setenv("GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS", "true")
|
||||
|
||||
config = load_gateway_config()
|
||||
|
||||
assert config.platforms[Platform.RELAY].enabled is True
|
||||
assert config.platforms[Platform.TELEGRAM].enabled is True
|
||||
|
||||
|
||||
def test_thread_require_mention_yaml_does_not_overwrite_env(self, tmp_path, monkeypatch):
|
||||
"""Explicit env var should win over config.yaml (env > yaml precedence)."""
|
||||
hermes_home = tmp_path / ".hermes"
|
||||
|
||||
Reference in New Issue
Block a user