o
    ưiP                     @   s>   d dl Z d dlmZmZmZmZ ddlmZ G dd dZdS )    N)DictAnyOptionalUnion   )UnauthorizedErrorc                   @   s   e Zd Zddedee fddZdeeef fddZ		dd
ede	eee
f ejf fd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dZ		dded
ede	eee
f ejf fddZ		dded
ede	eee
f ejf fddZdS )CredentialsManagementClientNbase_urlapi_keyc                 C   s   | d| _|| _dS )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
    r   W/home/app/Keep/.python/lib/python3.10/site-packages/litellm/proxy/client/credentials.py__init__   s   
z$CredentialsManagementClient.__init__returnc                 C   s"   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   headersr   r   r   _get_headers   s   z(CredentialsManagementClient._get_headersFreturn_requestc              
   C   s   | j  d}tjd||  d}|r|S t }z|| }|  | W S  tj	j
yA } z|jjdkr<t| d}~w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&   er   r   r   list   s   
z CredentialsManagementClient.listcredential_namecredential_infocredential_valuesc              
   C   s   | j  d}|||d}tjd||  |d}|r|S t }z|| }	|	  |	 W S  tj	j
yH }
 z|
jjdkrCt|
 d}
~
w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   )r-   r.   r/   POST)r   r#   r   Nr   )r   r-   r.   r/   r   r(   datar)   r*   r&   r+   r   r   r   createB   s&   
z"CredentialsManagementClient.createc              
   C      | j  d| }tjd||  d}|r|S t }z|| }|  | W S  tj	j
yC } z|jjdkr>t| d}~w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   r-   r   r(   r)   r*   r&   r+   r   r   r   deleteq      
z"CredentialsManagementClient.deletec              
   C   r3   )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   r5   r   r   r   get   r7   zCredentialsManagementClient.get)N)F)__name__
__module____qualname__strr   r   r   r   boolr   r   r   r   r,   r2   r6   r8   r   r   r   r   r      sJ    
(


2
(r   )	r   typingr   r   r   r   r$   r   r   r   r   r   r   <module>   s    