o
    ưi?                     @   sP   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 deZdS )    )ABCabstractmethod)AnyDictOptionalUnionN)verbose_loggerc                   @   s\  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dZe		ddedee deee	e
jf  dee fd	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ef  deeef fddZe			ddedee dee deee	e
jf  def
ddZ		ddedededee deee	e
jf  defddZdS )BaseSecretManagerzD
    Abstract base class for secret management implementations.
    Nsecret_nameoptional_paramstimeoutreturnc                       dS )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   r   r   b/home/app/Keep/.python/lib/python3.10/site-packages/litellm/secret_managers/base_secret_manager.pyasync_read_secret   s   z#BaseSecretManager.async_read_secretc                 C   s   dS )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   r   r   r   sync_read_secret"   s   z"BaseSecretManager.sync_read_secretsecret_valuedescriptiontagsc                    r   )a+  
        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
            tags: Optional dict or list of tags to apply, e.g.
                  {"Environment": "Prod", "Owner": "AI-Platform"} or
                  [{"Key": "Environment", "Value": "Prod"}]
        Returns:
            Dict[str, Any]: Response from the secret manager containing write operation details
        Nr   )r   r
   r   r   r   r   r   r   r   r   async_write_secret6   s   z$BaseSecretManager.async_write_secret   recovery_window_in_daysc                    r   )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   r   r   r   async_delete_secretQ   s   z%BaseSecretManager.async_delete_secretcurrent_secret_namenew_secret_namenew_secret_valuec              
      s  zL| j |||dI dH }|du rtd| d| j||d| ||dI dH }| j |||dI dH }|du r?td| | j|d||d	I dH  |W S  tjym }	 ztd
t|	j	j
 td|	j	j
 d}	~	w tjyx   td ty }
 z	td
t|
  d}
~
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   r   z0Error rotating secret in AWS Secrets Manager: %szHTTP error occurred: zTimeout error occurred)r   
ValueErrorr   r   httpxZHTTPStatusErrorr   	exceptionstrresponsetextZTimeoutException	Exception)r   r   r   r   r   r   Z
old_secretZcreate_responseZ
new_secreterrer   r   r   async_rotate_secretg   s\   	
z%BaseSecretManager.async_rotate_secret)NN)NNNN)r   NN)__name__
__module____qualname____doc__r   r"   r   dictr   floatr    Timeoutr   r   listr   r   r   intr   r(   r   r   r   r   r	   	   s    
r	   )abcr   r   typingr   r   r   r   r    Zlitellmr   r	   r   r   r   r   <module>   s
    