+
    jHàjÐ  ã                  óR  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
HtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt R
 R ltR R ltR R ltR R ltR R ltR R ltR R ltR R lt R)R R llt!R R lt"R R lt#R  R! lt$R"R#R$R/R% R& llt%R' R( lt&R# )*zøHelpers shared by the Bitwarden and 1Password ``hermes secrets`` CLIs.

Import-light on purpose: ``hermes_cli.secrets_cli`` must stay free of the Bitwarden backend
(``cryptography``) at import time, so nothing here touches a secret-source backend.
)ÚannotationsN)ÚPath)ÚCallableÚIterableÚOptionalÚSequence)ÚConsole)ÚPanel)ÚTable)Úload_configÚsave_config)Úmasked_secret_promptc               ó    € V ^8„  d   QhRRRR/# )é   ÚbÚboolÚreturnÚstr© )Úformats   "Ú?/home/ubuntu/.hermes/hermes-agent/hermes_cli/_secrets_common.pyÚ__annotate__r      s   € ÷ :ñ :ˆ$ð :�3ñ :ó    c                ó   € V '       d   R # R# )z[green]yes[/green]z[dim]no[/dim]r   )r   s   &r   Úynr      s   € ß#$ÐÐ9¨/Ð9r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚcfgÚdictÚsectionr   r   r   )r   s   "r   r   r      s!   € ÷ 9ñ 9�Tð 9 Cð 9¨Dñ 9r   c                ój   € V P                  R4      ;'       g    / P                  V4      ;'       g    / # )z&``cfg["secrets"][section]`` or ``{}``.Úsecrets)Úget)r   r   s   &&r   Úsection_cfgr"      s,   € à�G‰G�IÓ×$Ð$ "×)Ñ)¨'Ó2×8Ð8°bÐ8r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   Úkeyr   r   r   )r   s   "r   r   r   !   s!   € ÷ /ñ /�ð /˜Cð / Cñ /r   c                óh   € \        V P                  VR4      ;'       g    R4      P                  4       # )z8A stripped string config value; ``""`` for missing/None.Ú )r   r!   Ústrip)r   r$   s   &&r   Úcfg_strr(   !   s)   € äˆs�w‰w�s˜BÓ×%Ð% 2Ó&×,Ñ,Ó.Ð.r   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   Únamer   Ú	help_textr   Útupler   )r   s   "r   r   r   &   s!   € ÷ 0ñ 0ˆcð 0˜cð 0°ñ 0r   c                ó    € V \        RRV/VB 3# )z;One ``add_argument`` spec for :func:`register_subcommands`.Úhelpr   )r   )r+   r,   Úkwargss   &&,r   Úargr1   &   s   € à”Ñ/˜9Ð/¨Ñ/Ð/Ð/r   c               ó$   € V ^8„  d   QhRRRRRR/# r*   r   )r   s   "r   r   r   +   s!   € ÷ 5ñ 5ˆsð 5˜sð 5 uñ 5r   c                ó   € \        WRR7      # )z?A boolean ``store_true`` spec for :func:`register_subcommands`.Ú
store_true)Úaction)r1   )r+   r,   s   &&r   Úflagr6   +   s   € äˆt |Ô4Ð4r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   Úparentzargparse.ArgumentParserÚdestr   Úcommandsr   r   ÚNoner   )r   s   "r   r   r   0   s*   € ÷ 'ñ 'Ð!8ð 'Àð 'Èxð 'Ð\`ñ 'r   c                óÆ   € V P                  VR7      pV FH  w  rErgVP                  WER7      pV F  w  ršVP                  ! V	3/ V
B  K  	  VP                  VR7       KJ  	  R# )zLAttach ``(name, help, handler, [arg(...), ...])`` subcommands to ``parent``.)r9   )r/   )ÚfuncN)Úadd_subparsersÚ
add_parserÚadd_argumentÚset_defaults)r8   r9   r:   Úsubr+   r,   r=   Ú	argumentsÚparserÚarg_namer0   s   &&&        r   Úregister_subcommandsrF   0   se   € à
×
Ñ
 TÐ
Ó
*€CÛ,4Ñ(ˆ˜Ø—‘ �Ó5ˆÛ )ÑˆHØ×Ò Ñ3¨FÔ3ñ !*à×Ñ ÐÖ&ó	 -5r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   Úconsoler   r   r   Úproductr   Úcommandr   r   r   )r   s   "r   r   r   :   s0   € ÷ ñ ˜Wð ¨4ð ¸#ð Èð ÐPTñ r   c                óh   € VP                  R4      '       d   R# V P                  RV RV R24       R# )zTPrint the "integration is disabled" hint and return False unless ``cfg["enabled"]``.ÚenabledTz[yellow]z/ integration is disabled.  Run `hermes secrets z setup` first.[/yellow]F)r!   Úprint)rH   r   rI   rJ   s   &&&&r   Úrequire_enabledrN   :   s=   € à
‡w�wˆy×ÒÙØ‡M�M�H˜W˜Ið &%Ø%, IÐ-DðFô Gár   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   rH   r   Útitler   Úrowsr   r   r;   r   )r   s   "r   r   r   C   s.   € ÷ Bñ B ð B°ð B¸8ð BÈñ Br   c                óÚ   € \        RRR	R7      pVP                  RRR7       VP                  R4       V F  w  rEVP                  WE4       K  	  V P                  \	        W1RR7      4       R# )
zGTwo-column key/value table inside a cyan panel (the ``status`` layout).FN)Úshow_headerÚboxÚpaddingr&   Úbold)ÚstyleÚcyan)rP   Úborder_style)é    r   )r
   Ú
add_columnÚadd_rowrM   r	   )rH   rP   rQ   ÚtableÚlabelÚvalues   &&&   r   Úprint_status_panelr`   C   s\   € ä˜e¨°vÔ>€EØ	×Ñ�R˜vÐÔ&Ø	×Ñ�RÔÛ‰ˆØ�‰�eÖ#ñ à‡M�M”%˜¸Ô@ÖAr   c               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# )r   rH   r   Úcolumnsr   rQ   r   ÚwarningszIterable[str]Úindentr   r   r;   r   )r   s   "r   r   r   M   sA   € ÷ @ñ @˜ð @¨8ð @¸8ð @Ø'ð@Ø69ð@ØCGñ@r   c                ó&  € \        RRR7      pV F4  p\        V\        4      '       d   V/ 3MTw  rxVP                  ! V3/ VB  K6  	  V F  p	VP                  ! V	!   K  	  V P                  V4       V F  p
V P                  V RV
 24       K  	  R# )z›Headed table; ``columns`` entries are ``header`` or ``(header, add_column kwargs)``.

``warnings`` are echoed after the table, one ``warning:`` line each.
TrV   )rS   Úheader_stylez[yellow]warning:[/yellow] N)r
   Ú
isinstancer   r[   r\   rM   )rH   rb   rQ   rc   rd   r]   ÚcolÚheaderr0   ÚrowÚws   &&&&&      r   Úprint_tablerl   M   sŒ   € ô ˜d°Ô8€EÛˆÜ&0°´c×&:Ò&:˜#˜r™À‰ˆØ×Ò˜Ñ* 6Ô*ñ ó ˆØ�Š�sÔñ à‡M�M�%ÔÛˆØ�‰˜˜Ð :¸1¸#Ð>Ö?ó r   c               ó    € V ^8„  d   QhRRRR/# )r   Úbinaryr   r   r   r   )r   s   "r   r   r   ^   s   € ÷ 	ñ 	˜ð 	 ñ 	r   c           
     óF  €  \         P                  ! \        V 4      R.RRRR^RR7      pVP                  ^ 8X  dD   VP                  ;'       g    VP
                  P                  4       P                  4       ^ ,          #  R#   \        \         P                  3 d     R# i ; i)zIReturn the first line of ``<binary> --version`` or ``"version unknown"``.z	--versionTzutf-8ÚreplaceF)Úcapture_outputÚtextÚencodingÚerrorsÚtimeoutÚcheckzversion unknown)
Ú
subprocessÚrunr   Ú
returncodeÚstdoutÚstderrr'   Ú
splitlinesÚOSErrorÚTimeoutExpired)rn   Úress   & r   Úcli_versionr€   ^   s•   € ðÜ�nŠnœc &›k¨;Ð7ÈÐSWÐbiØ$-°qÀôGˆà�>‰>˜QÔØ—J‘J×,Ð, #§*¡*×3Ñ3Ó5×@Ñ@ÓBÀ1ÕEÐEð ñ øô ”Z×.Ñ.Ð/ô ØÙðús   ‚AB Á/B ÂB ÂB c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r   j   s   € ÷ 
ñ 
˜ñ 
r   c                 óJ   € ^ RI Hp  V ! RRR7      pVP                  RR4       V# )u¦   Env for a secret-manager CLI child (``bws`` / ``op``).

Intentionally receives tokens â€” no scrub, no HOME rewrite (both CLIs store state under the
real user home).
)Úbuild_subprocess_envF)Úscrub_secretsÚinherit_profile_homeÚNO_COLORÚ1)Útools.environments.localrƒ   Ú
setdefault)rƒ   Úenvs     r   Úsecret_cli_envr‹   j   s&   € õ >á
¨UÈÔ
O€CØ‡N�N�:˜sÔ#Ø€Jr   c               óH   € V ^8„  d   QhRRRRRRRRRRR	RR
RRRRRRRRRRR/# )r   rH   r   ÚgivenúOptional[str]Ú	token_envr   r6   ÚintroÚpromptÚverifyzOptional[Callable[[str], bool]]ÚsavezCallable[[str, str], object]Úenv_pathzCallable[[], object]Úclear_cachesÚdisabled_noter   Úintr   )r   s   "r   r   r   w   su   € ÷ "ñ "Øð"Ø*ð"Ø7:ð"ØEHð"ØQTð"Ø^að"à+ð"à3Oð"ð #ð"ð 3Gð"ð !ð	"ð
 	ñ"r   c               ó"  € T;'       g    RP                  4       pV'       gf   \        P                  P                  4       '       g   V P	                  RV R24       ^# V P	                  V4       \        V4      P                  4       pV'       g   V P	                  R4       ^# Ve   V! V4      '       g   ^# V! W+4       V\        P                  V&   V	! 4        V P	                  RV! 4        RV R24       V
'       d   V P	                  V
4       ^ # )uR  Shared ``token`` subcommand: prompt, optionally verify, then persist. Returns the exit code.

``verify(token)`` prints its own diagnostics and returns False to abort without touching
.env â€” so a bad paste never bricks the working token; None skips verification
(``--no-verify``). ``save``/``env_path`` are passed in (not imported here) so each CLI
module's own ``save_env_value``/``get_env_path`` bindings â€” which tests monkeypatch â€” stay
in effect. Old cached pulls are keyed on the previous token's fingerprint; clearing them
makes the next startup fetch fresh with the new credential.
r&   u$   [red]No TTY â€” pass the token with ú.[/red]z![red]Empty token, aborting.[/red]u   [green]âœ“[/green] stored in z as z..  Takes effect on the next Hermes invocation.)r'   ÚsysÚstdinÚisattyrM   r   ÚosÚenviron)rH   r�   r�   r6   r�   r‘   r’   r“   r”   r•   r–   Útokens   &&&$$$$$$$$ r   Úrotate_tokenr    w   sà   € ð �[ˆ[�b×ÑÓ!€EßÜ�y‰y×Ñ×!Ò!Ø�M‰MÐ@ÀÀÀgÐNÔOÙØ�‰�eÔÜ$ VÓ,×2Ñ2Ó4ˆßØ�‰Ð9Ô:ÙØÒ¡&¨§-¢-ÙÙˆÔØ!„B‡J�JˆyÑÙ„NØ‡M�MÐ1±(³*°¸TÀ)Àð M@ð @ô AçØ�‰�mÔ$Ùr   Úallow_emptyFÚempty_messagec               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# )r   rH   r   r‘   r   Úcountr—   r¡   r   r¢   rŽ   r   r   )r   s   "r   r   r   œ   sA   € ÷ Hñ H˜'ð H¨3ð H°sð HØ"ðHØ;HðHØTWñHr   c               óN  €  V P                  V4      P                  4       pV'       g&   V'       d   ^ # V'       d   V P                  V4       KM   \        V4      p^Tu;8:  d
   T8:  d    T#  T P                  RT R24       Kƒ    \         d    T P                  R4        K¢  i ; i)z·Loop until the user enters an integer in ``1..count``; return it.

Blank input returns 0 when ``allow_empty``; otherwise ``empty_message`` (if any)
is printed and the prompt repeats.
z  [red]Enter a number.[/red]u     [red]Out of range â€” pick 1-r™   )Úinputr'   rM   r—   Ú
ValueError)rH   r‘   r¤   r¡   r¢   ÚchoiceÚidxs   &&&$$  r   Úprompt_indexrª   œ   s—   € ð Ø—‘˜vÓ&×,Ñ,Ó.ˆßßÙßØ—‘˜mÔ,Ùð	Ü�f“+ˆCð �Ö�uÕØˆJð à�‰Ð7¸°w¸gÐFÖGøô ô 	Ø�M‰MÐ8Ô9Úð	ús   ÁB ÂB$Â#B$c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   Úmessager   r—   r   )r   s   "r   r   r   µ   s!   € ÷ ñ  3ð °ð ¸ñ r   c                ó¬   € \        4       pRVP                  R/ 4      P                  V / 4      R&   \        V4       \        4       P	                  V4       ^ # )zOSet ``secrets.<section>.enabled = False`` in config.yaml and print ``message``.Fr    rL   )r   r‰   r   r   rM   )r   r¬   r   s   && r   Údisable_secret_sourcer®   µ   sD   € ä
‹-€CØGL€C‡N�N�9˜bÓ!×,Ñ,¨W°bÓ9¸)ÑDÜ�ÔÜƒI‡O�O�GÔÙr   )r   r&   )'Ú__doc__Ú
__future__r   Úargparser�   rw   rš   Úpathlibr   Útypingr   r   r   r   Úrich.consoler   Ú
rich.panelr	   Ú
rich.tabler
   Úhermes_cli.configr   r   Úhermes_cli.secret_promptr   r   r"   r(   r1   r6   rF   rN   r`   rl   r€   r‹   r    rª   r®   r   r   r   Ú<module>r¹      s�   ðñõ #ã Û 	Û Û 
Ý ß 9Ó 9å  Ý Ý ç 6Ý 9õ:õ9õ
/õ
0õ
5õ
'õõB÷@õ"	õ
õ"ðJHØ%*ðHØKO÷H÷2r   