The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): digest a bound secret's endpoint URLs in normalized form
Teknium62054cf908fa
diff --git a/gateway/session_policy_credentials.py b/gateway/session_policy_credentials.pyindex 98b434ece45..1118e2d6b45 100644--- a/gateway/session_policy_credentials.py+++ b/gateway/session_policy_credentials.py@@ -158,6 +158,16 @@ def _resolved(owner, block, config):return list(resolved_route(block, config))+# Endpoint fields holding a URL: digested in normalize_route_base_url's form, so a re-spelling of the same+# endpoint (host case, a trailing slash, the scheme's default port) is not a moved endpoint.+_URL_KEYS = ('base_url', 'api', 'url')+++def _url(value):+ from hermes_cli.route_identity import normalize_route_base_url+ return normalize_route_base_url(str(value or '').strip())++def _binding(config, path):"""Digest of the endpoint the secret at *path* authenticates in the frozen *config* (a terminal-scopesecret, ``path[0] is None``, authenticates no endpoint)."""@@ -167,9 +177,13 @@ def _binding(config, path):if isinstance(block, dict) and _route_owner(config, path) is not None:# A route's key authenticates what it resolves to: a named ``providers:`` entry's URL included.endpoint['resolved'] = _resolved(owner, block, config)+ endpoint['resolved'][-1] = _url(endpoint['resolved'][-1])elif isinstance(block, dict) and path[0] in _ENTRY_SECTIONS:from hermes_cli.runtime_provider_custom import _entry_url- endpoint['resolved'] = str(_entry_url(block) or '')+ endpoint['resolved'] = _url(_entry_url(block))+ for key in _URL_KEYS:+ if isinstance(endpoint.get(key), str):+ endpoint[key] = _url(endpoint[key])return hashlib.sha256(json.dumps([list(path), endpoint], sort_keys=True).encode()).hexdigest()diff --git a/tests/gateway/test_config_secret_scope.py b/tests/gateway/test_config_secret_scope.pyindex 3d517efd7d3..0c972113c1f 100644--- a/tests/gateway/test_config_secret_scope.py+++ b/tests/gateway/test_config_secret_scope.py@@ -383,6 +383,24 @@ def test_an_unrelated_route_edit_keeps_an_auxiliary_and_fallback_key(tmp_path, massert recovered['fallback_providers']['api_key'] == 'K-fb'[email protected]('spelling', ['http://GOOD.invalid/v1', 'http://good.invalid/v1/', 'HTTP://good.invalid:80/v1'])+def test_a_cosmetic_url_respelling_keeps_the_key(tmp_path, monkeypatch, spelling):+ """@unsupportedpastels minor: host case, a trailing slash or the scheme's default port is the same+ endpoint (normalize_route_base_url), so re-spelling it is not a moved endpoint."""+ cfg = {**_BASE, 'model': {**_BASE['model'], 'api_key': 'K-model'},+ 'providers': {'team': {'base_url': _A, 'api_key': 'K-team'}},+ 'auxiliary': {'compression': {'provider': 'team', 'model': 'm', 'api_key': 'K-aux'}}}+ owner, policy = _bind(tmp_path, monkeypatch, cfg)++ def respell(c):+ c['model']['base_url'] = spelling+ c['providers']['team']['base_url'] = spelling+ recovered = _repointed(policy, respell).config(owner())+ assert recovered['model']['api_key'] == 'K-model'+ assert recovered['providers']['team']['api_key'] == 'K-team'+ assert recovered['auxiliary']['compression']['api_key'] == 'K-aux'++def _loopback():"""Two real loopback HTTP servers recording the Authorization each request carries."""import threading