local.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """Local Fernet vault as a login backend (the always-on default)."""
  2. from __future__ import annotations
  3. from typing import Dict, List, Optional
  4. from agent.vault_backends.base import LoginBackend
  5. from agent.vault_store import VaultItemMeta
  6. def _store():
  7. # Late import: tests and callers patch ``agent.vault_store.get_vault_store``; binding it here
  8. # at call time keeps that facade name the single seam.
  9. from agent.vault_store import get_vault_store
  10. return get_vault_store()
  11. class LocalLoginBackend(LoginBackend):
  12. name = "local"
  13. display_name = "Hermes vault"
  14. prefix = "vault_"
  15. def list_items(self) -> list[VaultItemMeta]:
  16. return _store().list_items()
  17. def get_meta(self, handle: str) -> Optional[VaultItemMeta]:
  18. return _store().get_meta(handle)
  19. def resolve_password(self, handle: str) -> str:
  20. return str(_store().resolve_secret(handle).get("password") or "")
  21. def resolve_otp(self, handle: str) -> Optional[str]:
  22. from agent.vault_store import totp_now
  23. seed = str(_store().resolve_secret(handle).get("otp_secret") or "")
  24. return totp_now(seed) if seed else None
  25. def resolve_secret(self, handle: str) -> dict[str, str]:
  26. return {k: str(v) for k, v in _store().resolve_secret(handle).items()}