secrets.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """``hermes secrets`` subcommand parser."""
  2. from __future__ import annotations
  3. def build_secrets_parser(subparsers) -> None:
  4. """Attach the ``secrets`` subcommand to ``subparsers``."""
  5. secrets_parser = subparsers.add_parser(
  6. "secrets", help="Manage external secret sources (Bitwarden, 1Password)",
  7. description="Pull API keys from an external secret manager at process startup "
  8. "instead of storing them in ~/.hermes/.env. Supports Bitwarden "
  9. "Secrets Manager and 1Password. See: "
  10. "https://hermes-agent.nousresearch.com/docs/user-guide/secrets/")
  11. secrets_subparsers = secrets_parser.add_subparsers(dest="secrets_command")
  12. secrets_bw = secrets_subparsers.add_parser(
  13. "bitwarden", aliases=["bw"], help="Bitwarden Secrets Manager integration")
  14. secrets_op = secrets_subparsers.add_parser(
  15. "onepassword", aliases=["op", "1password"], help="1Password (op:// references) integration")
  16. # Lazy import: secrets_cli pulls cryptography's native extension, which on Windows
  17. # maps into the updater process and defers its self-lock preflight. secrets_cli
  18. # defers its backend import to first use, so register_cli here costs no crypto load.
  19. # Lazy-import secrets_cli: the module imports agent.secret_sources.bitwarden which loads
  20. # cryptography._rust.pyd. See #86781.
  21. from hermes_cli import secrets_cli as _secrets_cli
  22. from hermes_cli import onepassword_secrets_cli as _op_secrets_cli
  23. _secrets_cli.register_cli(secrets_bw)
  24. _op_secrets_cli.register_cli(secrets_op)
  25. def _dispatch_secrets(args):
  26. sub = getattr(args, "secrets_command", None)
  27. if sub is None:
  28. secrets_parser.print_help()
  29. return 0
  30. return args.func(args)
  31. secrets_parser.set_defaults(func=_dispatch_secrets)