
    ei                         d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	 dede
deee   ee   f   fdZ	 	 ddede
d
ee   dee   deee   ee   f   f
dZy	)    )OptionalTuple)UserIdentity)DEFAULT_DATABASEDEFAULT_TENANT)ChromaAuthErroruser_identity4overwrite_singleton_tenant_database_access_from_authreturnc                     |syd}d}| j                   }| j                  }|r|dk7  r|}|r+t        |      }t        |      dk(  rd|vrt	        |      d   }||fS )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   )tenant	databasessetlenlist)r	   r
   r   databaseuser_tenantuser_databasesuser_databases_sets          f/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/chromadb/auth/utils/__init__.py(_singleton_tenant_database_if_applicabler      sy    & @FH&&K",,N{c) 0!"a'C7I,I./2H8    Nuser_provided_tenantuser_provided_databasec                     t        | |      \  }}|r"|t        k7  r|r||k7  rt        d| d| d      |r"|t        k7  r|r||k7  rt        d| d| d      |r	|t        k(  r|r|}|r	|t        k(  r|r|}||fS )N)r	   r
   zTenant z does not match z5 from the server. Are you sure the tenant is correct?z	Database z7 from the server. Are you sure the database is correct?)r   r   r   r   )r	   r
   r   r   
new_tenantnew_databases         r   maybe_set_tenant_and_databaser!   *   s     	1#=q	 	 N2..(<'==Mj\  ZO  P  Q  	Q"&6622	*@)AAQR^Q_  `W  X  Y  	Y !$8N$J
)"&<@P&P
!-!777r   r   )typingr   r   chromadb.authr   chromadb.configr   r   chromadb.errorsr   boolstrr   r!    r   r   <module>r)      s    " & < +:> 8C=(3-'(J +/,0	,8,8:>,8 #3-,8 %SM	,8
 8C=(3-'(,8r   