auth.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """``hermes auth`` subcommand parser."""
  2. from __future__ import annotations
  3. from typing import Callable
  4. def build_auth_parser(subparsers, *, cmd_auth: Callable) -> None:
  5. """Attach the ``auth`` subcommand to ``subparsers``."""
  6. auth_parser = subparsers.add_parser("auth", help="Manage pooled provider credentials")
  7. auth_subparsers = auth_parser.add_subparsers(dest="auth_action")
  8. auth_add = auth_subparsers.add_parser("add", help="Add a pooled credential")
  9. auth_add.add_argument(
  10. "provider", help="Provider id (for example: anthropic, openai-codex, openrouter)")
  11. auth_add.add_argument(
  12. "--type", dest="auth_type", choices=["oauth", "api-key", "api_key"],
  13. help="Credential type to add")
  14. auth_add.add_argument("--label", help="Optional display label")
  15. auth_add.add_argument(
  16. "--priority", type=int,
  17. help="Place the new credential at this priority (0 = tried first under fill_first); "
  18. "appends last when omitted")
  19. auth_add.add_argument("--api-key", help="API key value (otherwise prompted securely)")
  20. auth_add.add_argument("--portal-url", help="Nous portal base URL")
  21. auth_add.add_argument("--inference-url", help="Nous inference base URL")
  22. auth_add.add_argument("--client-id", help="OAuth client id")
  23. auth_add.add_argument("--scope", help="OAuth scope override")
  24. auth_add.add_argument(
  25. "--no-browser", action="store_true", help="Do not auto-open a browser for OAuth login")
  26. auth_add.add_argument(
  27. "--browser", action="store_true",
  28. help="openai-codex only: sign in with the browser authorization-code (PKCE) flow on "
  29. "http://localhost:1455/auth/callback instead of the default device-code flow; falls back "
  30. "to device code when that port is busy (config: auth.codex_login_flow)")
  31. auth_add.add_argument("--timeout", type=float, help="OAuth/network timeout in seconds")
  32. auth_add.add_argument(
  33. "--insecure", action="store_true", help="Disable TLS verification for OAuth login")
  34. auth_add.add_argument("--ca-bundle", help="Custom CA bundle for OAuth login")
  35. auth_list = auth_subparsers.add_parser("list", help="List pooled credentials")
  36. auth_list.add_argument("provider", nargs="?", help="Optional provider filter")
  37. auth_remove = auth_subparsers.add_parser(
  38. "remove", help="Remove a pooled credential by index, id, or label")
  39. auth_remove.add_argument("provider", help="Provider id")
  40. auth_remove.add_argument("target", help="Credential index, entry id, or exact label")
  41. auth_reset = auth_subparsers.add_parser(
  42. "reset", help="Clear exhaustion status for a provider's credentials (all, or one target)")
  43. auth_reset.add_argument("provider", help="Provider id")
  44. auth_reset.add_argument(
  45. "target", nargs="?",
  46. help="Optional credential index, entry id, or exact label; clears every credential when omitted")
  47. auth_priority = auth_subparsers.add_parser(
  48. "priority", help="Move a pooled credential to a priority (0 = tried first under fill_first)")
  49. auth_priority.add_argument("provider", help="Provider id")
  50. auth_priority.add_argument("target", help="Credential index, entry id, or exact label")
  51. auth_priority.add_argument("priority", type=int, help="New priority; others are renumbered")
  52. auth_refresh = auth_subparsers.add_parser(
  53. "refresh", help="Refresh a pooled OAuth credential's tokens and clear its cooldown")
  54. auth_refresh.add_argument("provider", help="Provider id")
  55. auth_refresh.add_argument(
  56. "target", nargs="?",
  57. help="Credential index, entry id, or exact label (required when the pool holds more than one)")
  58. auth_status = auth_subparsers.add_parser("status", help="Show auth status for a provider")
  59. auth_status.add_argument("provider", help="Provider id")
  60. auth_logout = auth_subparsers.add_parser(
  61. "logout", help="Log out a provider and clear stored auth state")
  62. auth_logout.add_argument("provider", help="Provider id")
  63. auth_upgrade = auth_subparsers.add_parser(
  64. "upgrade", help="Sign in with a Nous account, keeping your connectors")
  65. auth_upgrade.add_argument(
  66. "--no-browser", action="store_true", help="Do not auto-open a browser for sign-in")
  67. auth_upgrade.add_argument("--timeout", type=float, help="Network timeout in seconds")
  68. auth_parser.set_defaults(func=cmd_auth)