
    _j                         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d	S )    )OptionalTuple)UserIdentity)DEFAULT_DATABASEDEFAULT_TENANT)ChromaAuthErroruser_identity4overwrite_singleton_tenant_database_access_from_authreturnc                     |sdS d}d}| j         }| j        }|r|dk    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          Y/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/auth/utils/__init__.py(_singleton_tenant_database_if_applicabler      s    & @ zFH&K",N {c)) 3 00!""a''C7I,I,I.//2H8    Nuser_provided_tenantuser_provided_databasec                 "   t          | |          \  }}|r)|t          k    r|r||k    rt          d| d| d          |r)|t          k    r|r||k    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!   *   sJ    	1#=q	 	 	 	Q N22 3...  P(<  P  Pj  P  P  P  Q  Q  	QY"&666 7222  X*@  X  XR^  X  X  X  Y  Y  	Y !*$8N$J$J
 %K)".&<@P&P&P
 'Q!-!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:>,8 #3-,8 %SM	,8
 8C=(3-'(,8 ,8 ,8 ,8 ,8 ,8r   