env_settings.py 1.1 KB

1234567891011121314151617181920212223242526
  1. """Profile-scoped reads of the ``HERMES_*`` tuning settings cron honours from ``.env``.
  2. A standalone ``hermes -p X gateway run`` loads X's ``.env`` into ``os.environ``, so a bare
  3. ``os.getenv("HERMES_CRON_TIMEOUT")`` is X's value. Under ``gateway.multiplex_profiles`` the same
  4. tick runs inside the default profile's process, where ``os.environ`` holds the DEFAULT profile's
  5. ``.env``. With a secret scope installed (job run + delivery) the scope is authoritative; the tick
  6. loop itself (due-job scan, pool sizing) runs under the profile's home override only, so the
  7. setting is read from that home's ``.env``. Outside multiplex the read is the plain environ.
  8. """
  9. from __future__ import annotations
  10. import os
  11. from agent.secret_scope import current_secret_scope, is_multiplex_active, load_env_file
  12. from hermes_constants import get_hermes_home
  13. def cron_env_setting(name: str, default: str = "") -> str:
  14. if not is_multiplex_active():
  15. return os.getenv(name) or default
  16. scope = current_secret_scope()
  17. if scope is None:
  18. scope = load_env_file(get_hermes_home() / ".env")
  19. value = scope.get(name)
  20. return default if value is None else str(value)