
    3i                         S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  S SK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 SKJr  \R4                  " \5      rS	S
/rSr " S S
\5      r " S S	\5      r g)    N)override)	SecretStr)UserIdentityServerAuthenticationProviderClientAuthProviderClientAuthHeaders	AuthError)System)ChromaAuthError)OpenTelemetryGranularitytrace_method)Dict!BasicAuthenticationServerProviderBasicAuthClientProviderAuthorizationc                   P   ^  \ rS rSrSrS\SS4U 4S jjr\S\4S j5       r	Sr
U =r$ )	r   &   z
Client auth provider for basic auth. The credentials are passed as a
base64-encoded string in the Authorization header prepended with "Basic ".
systemreturnNc                    > [         TU ]  U5        UR                  U l        UR                  R	                  S5        [        [        UR                  R                  5      5      U l        g )Nchroma_client_auth_credentials)	super__init__settings	_settingsrequirer   strr   _creds)selfr   	__class__s     \/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/auth/basic_authn/__init__.pyr    BasicAuthClientProvider.__init__,   sI      @AFOO$R$R ST    c                     [         R                  " U R                  R                  5        R	                  S5      5      R                  S5      n[        [        SU 35      0$ )Nutf-8zBasic )base64	b64encoder   get_secret_valueencodedecodeAUTHORIZATION_HEADERr   )r   encodeds     r!   authenticate$BasicAuthClientProvider.authenticate2   sY    ""{{++-.66w?

&/ 	 !)fWI,>"?
 	
r#   r   r   )__name__
__module____qualname____firstlineno____doc__r
   r   r   r   r-   __static_attributes____classcell__r    s   @r!   r   r   &   s:    
Uv U$ U 
/ 
 
r#   c                      ^  \ rS rSrSrS\SS4U 4S jjr\" S\R                  5      \
S\\\4   S\4S	 j5       5       rS
rU =r$ )r   <   a  
Server auth provider for basic auth. The credentials are read from
`chroma_server_authn_credentials_file` and each line must be in the format
<username>:<bcrypt passwd>.

Expects tokens to be passed as a base64-encoded string in the Authorization
header prepended with "Basic".
r   r   Nc                   > [         TU ]  U5        UR                  U l        0 U l        U R                  5       nU H  nUR                  5       (       d  M  UR                  5       R                  S5       Vs/ s H  oDPM     nnU(       a  US   (       a  [        U5      S:w  d  [        U5      (       d  [        SU S35      eUS   nUS   nX`R                  ;   a  [        S5      e[        U5      U R                  U'   M     g s  snf )N:r      z$Invalid htpasswd credentials found: z3. Lines must be exactly <username>:<bcrypt passwd>.   zXDuplicate username found in [chroma_server_authn_credentials]. Usernames must be unique.)r   r   r   r   r   read_creds_or_creds_filestripsplitlenall
ValueErrorr   )	r   r   credslinev
_raw_credsusernamepasswordr    s	           r!   r   *BasicAuthenticationServerProvider.__init__F   s     ,.--/D::<<%)ZZ\%7%7%<=%<!%<J=qM
Oq(: ::, GH H  "!}H!!}H;;& 0 
 %.h$7DKK!-  >s   6Dz.BasicAuthenticationServerProvider.authenticateheadersc           	          [         R                  5       UR                  5       ;  a  [        [         S-   5      eU[         R                  5          n[        R
                  " SSU5      nUR                  5       n[        R                  " U5      R                  S5      nSU;  a  [        S5      eUR                  SS5      u  pE[        U5      n[        U5      nX@R                  ;  a  [        S5      e[        R                  " UR                  S5      U R                  U   R!                  5       R                  S5      5      nU(       d  [        S5      e[#        US	9$ ! [         a+  n[$        R'                  S
[)        U5       35         S nAOS nAf[*         ax  n[,        R.                  " UR0                  5      nUS   n	U	R2                  n
U	R4                  n[$        R'                  S[7        U5      R8                   SU SU
 35         S nAOS nAff = f[:        R<                  " [>        R@                  " SS5      5        [C        5       e)Nz header not foundz^Basic  r%   r;   z#Invalid Authorization header formatr=   zInvalid username or password)user_idz7BasicAuthenticationServerProvider.authenticate failed: zNBasicAuthenticationServerProvider.authenticate failed: Failed to authenticate z at gMbP?g{Gzt?)"r+   lowerkeysr	   resubr?   r&   	b64decoder*   r@   r   r   bcryptcheckpwr)   r(   r   loggererrorrepr	Exception	traceback
extract_tb__traceback__linenofilenametyper0   timesleeprandomuniformr   )r   rK   _auth_headerbase64_decodedrH   rI   
_pwd_checketblast_call_stackline_numberr_   s               r!   authenticate_or_raise7BasicAuthenticationServerProvider.authenticate_or_raisee   s   
$	#))+7<<>A 47J JKK"#7#=#=#?@L66*b,?L'--/L#--l;BB7KN.( EFF!/!5!5c1!=H8}H8}H{{* >??(H%668??HJ  >??11 	LLI$q'S   		%%aoo6B fO)00K&//HLL**.q'*:*:);4z;-Y 		 	

NN5%(	
 s%   EE 
H(!FHA.HHr/   )r0   r1   r2   r3   r4   r
   r   r   r   ALLr   r   r   r   rl   r5   r6   r7   s   @r!   r   r   <   s`    8v 8$ 8> 8:R:V:V ) T#s(^ )  )  ) r#   )!r&   rc   rR   ra   r[   rU   logging	overridesr   pydanticr   chromadb.authr   r   r   r   r	   chromadb.configr
   chromadb.errorsr    chromadb.telemetry.opentelemetryr   r   typingr   	getLoggerr0   rW   __all__r+   r   r    r#   r!   <module>rz      s{      	        # +  
		8	$.0I
J& 
0 
,V (D V r#   