
    `gj
                        U d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
  ej                  e      Z ej                         Zi Zded<   ddZdd	Zdd
ZddZddZddZy)a	  Module-level registry for DashboardAuthProvider instances.

Plugins call ``register_provider`` via the plugin context hook at startup.
The auth gate middleware iterates ``list_providers()`` and uses
``get_provider`` to dispatch on the session's ``provider`` field.
    )annotationsN)ListOptional)DashboardAuthProviderassert_protocol_compliancez dict[str, DashboardAuthProvider]
_providersc                2   t        t        |              t        5  | j                  t        v rt        d| j                        | t        | j                  <   ddd       t        j                  d| j                  | j                         y# 1 sw Y   5xY w)zRegister a provider.

    Raises:
        TypeError: on protocol violation.
        ValueError: if a provider with the same name is already registered.
    z,dashboard-auth provider already registered: Nz+dashboard-auth: registered provider %r (%s))	r   type_locknamer   
ValueError_loginfodisplay_name)providers    U/root/.hermes/venv/lib/python3.12/site-packages/hermes_cli/dashboard_auth/registry.pyregister_providerr      s     tH~.	 -==J&>x}}>OP  %-
8==!- 	II5x,,- -s   >BBc                d    t         5  t        j                  |       cddd       S # 1 sw Y   yxY w)z@Return the registered provider for ``name``, or None if unknown.N)r   r   get)r   s    r   get_providerr   +   s&    	 $~~d#$ $ $s   &/c                 t    t         5  t        t        j                               cddd       S # 1 sw Y   yxY w)z0All registered providers, in registration order.N)r   listr   values     r   list_providersr   1   s+    	 )J%%'() ) )s   .7c            	         t         5  t        j                         D  cg c]  } t        | dd      s|  c} cddd       S c c} w # 1 sw Y   yxY w)u  Registered providers that support non-interactive token auth.

    The subset of ``list_providers()`` whose ``supports_token`` flag is True,
    in registration order. The ``token_auth`` middleware seam consults these
    (and only these) when a token-authable route is hit, so OAuth/password-only
    providers are never asked to ``verify_token``. Returns an empty list when
    no token provider is registered — a token-authable route then fails
    closed (401), never open.
    supports_tokenFNr   r   r   getattrps    r   list_token_providersr#   7   sL     
 W%,,.Va'!=Mu2UVW WVW W    AAAAAAc            	         t         5  t        j                         D  cg c]  } t        | dd      s|  c} cddd       S c c} w # 1 sw Y   yxY w)zRegistered providers with supports_session True (interactive cookie
    sessions). The login page, /auth/login, and the gate's verify/refresh loops
    consult only these. Mirror of list_token_providers.
    supports_sessionTNr   r!   s    r   list_session_providersr'   E   sM    
 
 X%,,.Wa'!=OQU2VWX XWX Xr$   c                 b    t         5  t        j                          ddd       y# 1 sw Y   yxY w)z"Test-only: drop all registrations.N)r   r   clearr   r   r   clear_providersr*   N   s&    	   s   %.)r   r   returnNone)r   strr+   zOptional[DashboardAuthProvider])r+   zList[DashboardAuthProvider])r+   r,   )__doc__
__future__r   logging	threadingtypingr   r   hermes_cli.dashboard_auth.baser   r   	getLogger__name__r   Lockr   r   __annotations__r   r   r   r#   r'   r*   r   r   r   <module>r8      sj    #   !
 w"	/1
, 1($)WXr   