
    LKi                    J   S SK Jr  S SKJr  S SKJr  S SKJrJrJ	r	J
r
JrJr  S SKJr  S SKJr  S SKJrJr  \" S5      r\" S	5      r " S
 S\5      r\
\\4   r " S S\5      r\ " S S5      5       r " S S\5      r " S S\\5      r\ " S S5      5       r " S S\5      rg)    )annotations)abstractmethod)Enum)AnyListOptionalDictTupleTypeVar)	dataclass)	SecretStr)	ComponentSystemTSc                      \ rS rSrSrg)	AuthError    N)__name__
__module____qualname____firstlineno____static_attributes__r       X/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/auth/__init__.pyr   r      s    r   r   c                  D   ^  \ rS rSrSrSU 4S jjr\SS j5       rSrU =r	$ )ClientAuthProvider!   z
ClientAuthProvider is responsible for providing authentication headers for
client requests. Client implementations (in our case, just the FastAPI
client) must inject these headers into their requests.
c                $   > [         TU ]  U5        g Nsuper__init__selfsystem	__class__s     r   r$   ClientAuthProvider.__init__(        r   c                    g r!   r   )r&   s    r   authenticateClientAuthProvider.authenticate+       r   r   r'   r   returnNone)r0   ClientAuthHeaders)
r   r   r   r   __doc__r$   r   r,   r   __classcell__r(   s   @r   r   r   !   s!    !  r   r   c                  N    \ rS rSr% SrS\S'   SrS\S'   SrS\S	'   SrS
\S'   Sr	g)UserIdentity0   a}  
UserIdentity represents the identity of a user. In general, not all fields
will be populated, and the fields that are populated will depend on the
authentication provider.

The idea is that the AuthenticationProvider is responsible for populating
_all_ information known about the user, and the AuthorizationProvider is
responsible for making decisions based on that information.
struser_idNOptional[str]tenantzOptional[List[str]]	databaseszOptional[Dict[str, Any]]
attributesr   )
r   r   r   r   r3   __annotations__r<   r=   r>   r   r   r   r   r7   r7   0   s0     L FM %)I") ,0J(/r   r7   c                  j   ^  \ rS rSrSrS	U 4S jjr\S
S j5       rSS jrSS jr	    SS jr
SrU =r$ )ServerAuthenticationProviderE   a  
ServerAuthenticationProvider is responsible for authenticating requests. If
a ServerAuthenticationProvider is configured, it will be called by the
server to authenticate requests. If no ServerAuthenticationProvider is
configured, all requests will be authenticated.

The ServerAuthenticationProvider should return a UserIdentity object if the
request is authenticated for use by the ServerAuthorizationProvider.
c                   > [         TU ]  U5        UR                  R                  U l        UR                  R
                  U l        g r!   )r#   r$   settingschroma_server_auth_ignore_paths_ignore_auth_paths;chroma_overwrite_singleton_tenant_database_access_from_auth4overwrite_singleton_tenant_database_access_from_authr%   s     r   r$   %ServerAuthenticationProvider.__init__P   s>      OO;; 	 OOWW 	Ar   c                    g r!   r   )r&   headerss     r   authenticate_or_raise2ServerAuthenticationProvider.authenticate_or_raiseY   r.   r   c                    X R                   R                  5       ;   a"  UR                  5       U R                   U   ;   a  gg)NTF)rF   keysupper)r&   verbpaths      r   ignore_operation-ServerAuthenticationProvider.ignore_operation]   s6    ++0022

 7 7 ==r   c                   S nS nU R                   R                  R                  (       a"  [        U R                   R                  S   5      nU R                   R                  R                  (       a"  [        U R                   R                  S   5      nU(       d  U(       d  [        S5      eU(       a  U(       a  [        S5      eU(       a*  UR                  S5       Vs/ s H  o3(       d  M  UPM     sn$ U(       a&  [        US5       nUR                  5       sS S S 5        $ [        S5      es  snf ! , (       d  f       N= f)N$chroma_server_authn_credentials_filechroma_server_authn_credentialszNNo credentials file or credentials found in [chroma_server_authn_credentials].zDBoth credentials file and credentials found.Please provide only one.
rShould never happen)	_systemrD   rV   r9   rW   
ValueErrorsplitopen	readlines)r&   _creds_file_credscfs        r   read_creds_or_creds_file5ServerAuthenticationProvider.read_creds_or_creds_filee   s    <<  EE%%&LMK <<  @@../PQRF65  6+  %||D171!QA177k3'1{{} ('.//	 8''s   
D.-D.	D33
Ec                4   U R                   (       a  U(       d  gSnSnUR                  (       a  UR                  S:w  a  UR                  nUR                  (       a;  [        UR                  5      S:X  a"  UR                  S   S:w  a  UR                  S   nX#4$ )a  
If settings.chroma_overwrite_singleton_tenant_database_access_from_auth
is False, this function always returns (None, None).

If settings.chroma_overwrite_singleton_tenant_database_access_from_auth
is True, follows the following logic:
- If the user only has access to a single tenant, this function will
  return that tenant as its first return value.
- If the user only has access to a single database, this function will
  return that database as its second return value. If the user has
  access to multiple tenants and/or databases, including "*", this
  function will return None for the corresponding value(s).
- If the user has access to multiple tenants and/or databases this
  function will return None for the corresponding value(s).
)NNN*   r   )rH   r<   r=   len)r&   userr<   databases       r   'singleton_tenant_database_if_applicableDServerAuthenticationProvider.singleton_tenant_database_if_applicable   sw    $ HHPT;;4;;#-[[F>>c$..1Q64>>!;LPS;S~~a(Hr   )rF   rH   r/   )rK   zDict[str, str]r0   r7   )rQ   r9   rR   r9   r0   boolr0   z	List[str])rj   zOptional[UserIdentity]r0   z#Tuple[Optional[str], Optional[str]])r   r   r   r   r3   r$   r   rL   rS   rd   rl   r   r4   r5   s   @r   rA   rA   E   sE    
  06 * 	,   r   rA   c                  l    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrSrSrSrSrSrSrSrSrSrSrg)AuthzAction   zJ
The set of actions that can be authorized by the authorization provider.
zsystem:resetztenant:create_tenantztenant:get_tenantzdb:create_databasezdb:get_databasezdb:delete_databasezdb:list_databaseszdb:list_collectionszdb:count_collectionszdb:create_collectionzdb:get_or_create_collectionzcollection:get_collectionzcollection:delete_collectionzcollection:update_collectionzcollection:addzcollection:deletezcollection:getzcollection:queryzcollection:countzcollection:updatezcollection:upsertr   N)r   r   r   r   r3   RESETCREATE_TENANT
GET_TENANTCREATE_DATABASEGET_DATABASEDELETE_DATABASELIST_DATABASESLIST_COLLECTIONSCOUNT_COLLECTIONSCREATE_COLLECTIONGET_OR_CREATE_COLLECTIONGET_COLLECTIONDELETE_COLLECTIONUPDATE_COLLECTIONADDDELETEGETQUERYCOUNTUPDATEUPSERTr   r   r   r   rq   rq      sx     E*M$J*O$L*O(N,..<0N66
C F
CEE F Fr   rq   c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   Srg)	AuthzResource   z:
The resource being accessed in an authorization request.
r;   r<   rk   
collectionr   N)r   r   r   r   r3   r?   r   r   r   r   r   r      s     r   r   c                  ^   ^  \ rS rSrSrSU 4S jjr\        SS j5       rS	S jrSr	U =r
$ )
ServerAuthorizationProvider   aX  
ServerAuthorizationProvider is responsible for authorizing requests. If a
ServerAuthorizationProvider is configured, it will be called by the server
to authorize requests. If no ServerAuthorizationProvider is configured, all
requests will be authorized.

ServerAuthorizationProvider should raise an exception if the request is not
authorized.
c                $   > [         TU ]  U5        g r!   r"   r%   s     r   r$   $ServerAuthorizationProvider.__init__   r*   r   c                    g r!   r   )r&   rj   actionresources       r   authorize_or_raise.ServerAuthorizationProvider.authorize_or_raise   s     	r   c                v   S nS nU R                   R                  R                  (       a  U R                   R                  S   nU R                   R                  R                  (       a"  [	        U R                   R                  S   5      nU(       d  U(       d  [        S5      eU(       a  U(       a  [        S5      eU(       a*  UR                  S5       Vs/ s H  o3(       d  M  UPM     sn$ U(       a&  [        US5       nUR                  5       sS S S 5        $ [        S5      es  snf ! , (       d  f       N= f)Nchroma_server_authz_config_filechroma_server_authz_configz9No authz configuration file or authz configuration found.zTBoth authz configuration file and authz configuration found.Please provide only one.rX   rY   rZ   )	r[   rD   r   r   r9   r\   r]   r^   r_   )r&   _config_file_configrb   rc   s        r   read_config_or_config_file6ServerAuthorizationProvider.read_config_or_config_file   s    <<  @@<<001RSL<<  ;;$,,//0LMNGGK  G+  &}}T282!aA288lC(A{{} )(.//	 9((s   
D%$D% D**
D8r   r/   )rj   r7   r   rq   r   r   r0   r1   ro   )r   r   r   r   r3   r$   r   r   r   r   r4   r5   s   @r   r   r      sK    !  *5AN	 
0 0r   r   N) 
__future__r   abcr   enumr   typingr   r   r   r	   r
   r   dataclassesr   pydanticr   chromadb.configr   r   r   r   	Exceptionr   r9   r2   r   r7   rA   rq   r   r   r   r   r   <module>r      s    "    " 
 CLCL		 	 i(   0 0 0(U 9 U p!#t !8   )0) )0r   