From bfe7460c79fabcd61c683d66f4ecbc45f0340c21 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Fri, 24 Jul 2026 21:11:26 -0500 Subject: [PATCH] fix(config): add a collision-safe env var name for custom endpoint keys Both the Desktop panel and the CLI setup flow need somewhere in .env to put a custom endpoint's API key. Deriving the name from the endpoint's hostname collapses two servers on one machine onto a single slot, and every IP-based local endpoint slugs to a digit-leading name that save_env_value rejects outright. Key off the endpoint's own identity and keep a fixed prefix. Co-authored-by: asorry75 <33794789+asorry75@users.noreply.github.com> Co-authored-by: webtecnica <75556242+webtecnica@users.noreply.github.com> --- hermes_cli/config.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hermes_cli/config.py b/hermes_cli/config.py index d4e9ed843caa..cc03c5a57b5c 100644 --- a/hermes_cli/config.py +++ b/hermes_cli/config.py @@ -8209,6 +8209,25 @@ def save_env_value(key: str, value: str): invalidate_env_cache() +def custom_endpoint_key_env(identity: str) -> str: + """Env var name holding a custom endpoint's API key. + + ``identity`` is whatever names the endpoint on the calling path — the + Desktop panel's endpoint id, or ``host:port`` for the CLI setup flow. + Two properties matter: + + - It keys off the endpoint's own identity, not just its hostname, so two + endpoints on one host (``127.0.0.1:8000`` and ``:8001``) get separate + slots instead of the second save clobbering the first's credential. + - The fixed ``HERMES_CUSTOM_`` prefix keeps the result a valid POSIX name + even when the slug starts with a digit, which every IP-based local + endpoint does (``127.0.0.1`` → ``127_0_0_1``). ``save_env_value`` + rejects digit-leading names outright. + """ + slug = re.sub(r"[^A-Z0-9]+", "_", str(identity or "").upper()).strip("_") + return f"HERMES_CUSTOM_{slug}_API_KEY" if slug else "HERMES_CUSTOM_API_KEY" + + def remove_env_value(key: str) -> bool: """Remove a key from ~/.hermes/.env and os.environ.