
    hP                     D    d dl Z d dlmZmZmZmZ ddlmZ  G d d      Zy)    N)DictAnyOptionalUnion   )UnauthorizedErrorc                   R   e Zd Zddedee   fdZdeeef   fdZ	 ddede	eee
f   ej                  f   fdZ	 dd	ed
eee
f   deee
f   dede	eee
f   ej                  f   f
dZ	 dd	edede	eee
f   ej                  f   fdZ	 dd	edede	eee
f   ej                  f   fdZy)CredentialsManagementClientNbase_urlapi_keyc                 >    |j                  d      | _        || _        y)a"  
        Initialize the CredentialsManagementClient.

        Args:
            base_url (str): The base URL of the LiteLLM proxy server (e.g., "http://localhost:8000")
            api_key (Optional[str]): API key for authentication. If provided, it will be sent as a Bearer token.
        /N)rstrip	_base_url_api_key)selfr   r   s      \/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/proxy/client/credentials.py__init__z$CredentialsManagementClient.__init__   s     "-    returnc                 J    ddi}| j                   rd| j                    |d<   |S )z
        Get the headers for API requests, including authorization if api_key is set.

        Returns:
            Dict[str, str]: Headers to use for API requests
        zContent-Typezapplication/jsonzBearer Authorization)r   )r   headerss     r   _get_headersz(CredentialsManagementClient._get_headers   s0     "#56==)0'@GO$r   return_requestc                    | j                    d}t        j                  d|| j                               }|r|S t        j                         }	 |j                  |j                               }|j                          |j                         S # t        j                  j                  $ r*}|j                  j                  dk(  rt        |       d}~ww xY w)a  
        List all credentials.

        Args:
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        /credentialsGETr     Nr   requestsRequestr   Sessionsendprepareraise_for_statusjson
exceptions	HTTPErrorresponsestatus_coder   )r   r   urlrequestsessionr+   es          r   listz CredentialsManagementClient.list   s    $  -""5#t7H7H7JKN""$	||GOO$56H%%'==?""",, 	zz%%,'**	s   >B C+%CCcredential_namecredential_infocredential_valuesc                    | j                    d}|||d}t        j                  d|| j                         |      }|r|S t        j                         }	 |j                  |j                               }	|	j                          |	j                         S # t        j                  j                  $ r*}
|
j                  j                  dk(  rt        |
       d}
~
ww xY w)a  
        Create a new credential.

        Args:
            credential_name (str): Name of the credential
            credential_info (Dict[str, Any]): Additional information about the credential
            credential_values (Dict[str, Any]): Values for the credential
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        r   )r2   r3   r4   POST)r   r(   r    Nr!   )r   r2   r3   r4   r   r-   datar.   r/   r+   r0   s              r   createz"CredentialsManagementClient.createB   s    0  -  /.!2
 ""638I8I8KRVWN""$	||GOO$56H%%'==?""",, 	zz%%,'**	s   >B C2%CCc                    | j                    d| }t        j                  d|| j                               }|r|S t        j                         }	 |j                  |j                               }|j                          |j                         S # t        j                  j                  $ r*}|j                  j                  dk(  rt        |       d}~ww xY w)aO  
        Delete a credential by name.

        Args:
            credential_name (str): Name of the credential to delete
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/credentials/DELETEr   r    Nr!   r   r2   r   r-   r.   r/   r+   r0   s           r   deletez"CredentialsManagementClient.deleteq   s    (  o->?""8S$:K:K:MNN""$	||GOO$56H%%'==?""",, 	zz%%,'**	   >B C-%CCc                    | j                    d| }t        j                  d|| j                               }|r|S t        j                         }	 |j                  |j                               }|j                          |j                         S # t        j                  j                  $ r*}|j                  j                  dk(  rt        |       d}~ww xY w)aN  
        Get a credential by name.

        Args:
            credential_name (str): Name of the credential to retrieve
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/credentials/by_name/r   r   r    Nr!   r;   s           r   getzCredentialsManagementClient.get   s    (   5o5FG""5#t7H7H7JKN""$	||GOO$56H%%'==?""",, 	zz%%,'**	r=   )N)F)__name__
__module____qualname__strr   r   r   r   boolr   r   r"   r#   r1   r8   r<   r?    r   r   r
   r
      sB   	  	 x} 	 
d38n 
  %!! 
tCH~x///	0!P  %-- c3h-  S>	-
 - 
tCH~x///	0-d  %## # 
tCH~x///	0	#P  %## # 
tCH~x///	0	#r   r
   )	r"   typingr   r   r   r   r)   r   r
   rE   r   r   <module>rG      s     - - )r rr   