
    hN                     V    d dl mZmZ d dlmZmZmZmZ d dlZd dl	m
Z
  G d de      Zy)    )ABCabstractmethod)AnyDictOptionalUnionN)verbose_loggerc                      e Zd ZdZe	 	 ddedee   deee	e
j                  f      dee   fd       Ze	 	 ddedee   deee	e
j                  f      dee   fd       Ze	 	 	 dded	ed
ee   dee   deee	e
j                  f      deeef   fd       Ze	 	 	 ddedee   dee   deee	e
j                  f      def
d       Z	 	 ddedededee   deee	e
j                  f      defdZy)BaseSecretManagerzD
    Abstract base class for secret management implementations.
    Nsecret_nameoptional_paramstimeoutreturnc                    K   yw)a  
        Asynchronously read a secret from the secret manager.

        Args:
            secret_name (str): Name/path of the secret to read
            optional_params (Optional[dict]): Additional parameters specific to the secret manager
            timeout (Optional[Union[float, httpx.Timeout]]): Request timeout

        Returns:
            Optional[str]: The secret value if found, None otherwise
        N selfr   r   r   s       g/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/secret_managers/base_secret_manager.pyasync_read_secretz#BaseSecretManager.async_read_secret   s     $ 	   c                      y)a  
        Synchronously read a secret from the secret manager.

        Args:
            secret_name (str): Name/path of the secret to read
            optional_params (Optional[dict]): Additional parameters specific to the secret manager
            timeout (Optional[Union[float, httpx.Timeout]]): Request timeout

        Returns:
            Optional[str]: The secret value if found, None otherwise
        Nr   r   s       r   sync_read_secretz"BaseSecretManager.sync_read_secret"   s    $ 	    secret_valuedescriptionc                    K   yw)ak  
        Asynchronously write a secret to the secret manager.

        Args:
            secret_name (str): Name/path of the secret to write
            secret_value (str): Value to store
            description (Optional[str]): Description of the secret. Some secret managers allow storing a description with the secret.
            optional_params (Optional[dict]): Additional parameters specific to the secret manager
            timeout (Optional[Union[float, httpx.Timeout]]): Request timeout
        Returns:
            Dict[str, Any]: Response from the secret manager containing write operation details
        Nr   )r   r   r   r   r   r   s         r   async_write_secretz$BaseSecretManager.async_write_secret6   s     * 	r   recovery_window_in_daysc                    K   yw)a  
        Async function to delete a secret from the secret manager

        Args:
            secret_name: Name of the secret to delete
            recovery_window_in_days: Number of days before permanent deletion (default: 7)
            optional_params: Additional parameters specific to the secret manager
            timeout: Request timeout

        Returns:
            dict: Response from the secret manager containing deletion details
        Nr   )r   r   r   r   r   s        r   async_delete_secretz%BaseSecretManager.async_delete_secretM   s     ( 	r   current_secret_namenew_secret_namenew_secret_valuec                   K   	 | j                  |||       d{   }|t        d| d      | j                  ||d| ||       d{   }| j                  |||       d{   }|t        d|       | j                  |d||	       d{    |S 7 7 Q7 77 # t        j
                  $ rZ}	t        j                  d
t        |	j                  j                               t        d|	j                  j                         d}	~	wt        j                  $ r t        d      t        $ r%}
t        j                  d
t        |
              d}
~
ww xY ww)ak  
        Async function to rotate a secret by creating a new one and deleting the old one.
        This allows for both value and name changes during rotation.

        Args:
            current_secret_name: Current name of the secret
            new_secret_name: New name for the secret
            new_secret_value: New value for the secret
            optional_params: Additional AWS parameters
            timeout: Request timeout

        Returns:
            dict: Response containing the new secret details

        Raises:
            ValueError: If the secret doesn't exist or if there's an HTTP error
        )r   r   r   NzCurrent secret z
 not foundzRotated from )r   r   r   r   r   zFailed to verify new secret    )r   r   r   r   z0Error rotating secret in AWS Secrets Manager: %szHTTP error occurred: zTimeout error occurred)r   
ValueErrorr   r    httpxHTTPStatusErrorr	   	exceptionstrresponsetextTimeoutException	Exception)r   r!   r"   r#   r   r   
old_secretcreate_response
new_secreterres              r   async_rotate_secretz%BaseSecretManager.async_rotate_secretc   s    24	#55/ /  6   J ! ?3F2Gz!RSS %)$;$;+-+,?+@A / %< % O  $55+ /  6   J ! #??P!QRR **/() /	 +    #"I $$ 	J$$BCLL%%& 4S\\5F5F4GHII%% 	7566 	$$BCF 		s{   EB% B1B% BB% )B!*,B% B#B% EB% B% !B% #B% %E8AD)E6 EEE)NN)NNN)r%   NN)__name__
__module____qualname____doc__r   r*   r   dictr   floatr'   Timeoutr   r   r   r   r   intr    r4   r   r   r   r   r   	   s     +/9=	 "$ %u}} 456	
 
# &  +/9=	 "$ %u}} 456	
 
# & 
 &**.9=  c]	
 "$ %u}} 456 
c3h ,  23*.9= "*# "$	
 %u}} 456 
 4 +/9=M M M 	M
 "$M %u}} 456M 
Mr   r   )abcr   r   typingr   r   r   r   r'   litellmr	   r   r   r   r   <module>r@      s"    # - -  "g gr   