Ë
    tPêjë   ã                   óV   — d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	  G d„ de	«      Z
y)	ag  
Custom Secret Manager Integration

This module provides a base class for implementing custom secret managers in LiteLLM.

Usage:
    from litellm.integrations.custom_secret_manager import CustomSecretManager

    class MySecretManager(CustomSecretManager):
        def __init__(self):
            super().__init__(secret_manager_name="my_secret_manager")

        async def async_read_secret(
            self,
            secret_name: str,
            optional_params=None,
            timeout=None,
        ):
            # Your implementation here
            return await self._fetch_secret_from_service(secret_name)

        def sync_read_secret(
            self,
            secret_name: str,
            optional_params=None,
            timeout=None,
        ):
            # Your implementation here
            return self._fetch_secret_from_service_sync(secret_name)

    # Set your custom secret manager
    import litellm
    from litellm.types.secret_managers.main import KeyManagementSystem

    litellm.secret_manager_client = MySecretManager()
    litellm._key_management_system = KeyManagementSystem.CUSTOM
é    )Úabstractmethod)ÚAnyN)Úverbose_logger)ÚBaseSecretManagerc                   óä  ‡ — e Zd ZdZ	 ddedz  fˆ fd„Ze	 	 ddededz  dee	j                  z  dz  dedz  fd	„«       Ze	 	 ddededz  dee	j                  z  dz  dedz  fd
„«       Z	 	 	 	 ddedededz  dedz  dee	j                  z  dz  deez  dz  deeef   fd„Z	 	 	 ddededz  dedz  dee	j                  z  dz  def
d„Zdefd„Zddee	j                  z  dz  defd„Zdefd„Zˆ xZS )ÚCustomSecretManageray  
    Base class for implementing custom secret managers.

    This class provides a standard interface for implementing custom secret management
    integrations in LiteLLM. Users can extend this class to integrate their own secret
    management systems.

    Example:
        ```python
        from litellm.integrations.custom_secret_manager import CustomSecretManager

        class MyVaultSecretManager(CustomSecretManager):
            def __init__(self, vault_url: str, token: str):
                super().__init__(secret_manager_name="my_vault")
                self.vault_url = vault_url
                self.token = token

            async def async_read_secret(self, secret_name: str, optional_params=None, timeout=None):
                # Implementation for reading secrets from your vault
                async with httpx.AsyncClient() as client:
                    response = await client.get(
                        f"{self.vault_url}/v1/secret/{secret_name}",
                        headers={"X-Vault-Token": self.token},
                        timeout=timeout
                    )
                    return response.json()["data"]["value"]

            def sync_read_secret(self, secret_name: str, optional_params=None, timeout=None):
                # Sync implementation
                with httpx.Client() as client:
                    response = client.get(
                        f"{self.vault_url}/v1/secret/{secret_name}",
                        headers={"X-Vault-Token": self.token},
                        timeout=timeout
                    )
                    return response.json()["data"]["value"]
        ```
    NÚsecret_manager_namec                 ób   •— t         ‰| �  «        |xs d| _        t        j                  d«       y)a5  
        Initialize the CustomSecretManager.

        Args:
            secret_manager_name: A descriptive name for your secret manager.
                                This is used for logging and debugging purposes.
            **kwargs: Additional keyword arguments to pass to your secret manager.
        Úcustom_secret_managerz!Initialized custom secret managerN)ÚsuperÚ__init__r	   r   Úinfo)Úselfr	   ÚkwargsÚ	__class__s      €úo/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/integrations/custom_secret_manager.pyr   zCustomSecretManager.__init__X   s-   ø€ ô 	‰ÑÔØ#6Ò#QÐ:QˆÔ Ü×ÑÐ?Õ@ó    Úsecret_nameÚoptional_paramsÚtimeoutÚreturnc              ƒ   ó   K  — y­w)a¦  
        Asynchronously read a secret from your custom secret manager.

        Args:
            secret_name: Name/path of the secret to read
            optional_params: Additional parameters specific to your secret manager
            timeout: Request timeout

        Returns:
            The secret value if found, None otherwise

        Raises:
            Exception: If there's an error reading the secret
        N© ©r   r   r   r   s       r   Úasync_read_secretz%CustomSecretManager.async_read_secreti   s   è ø� ùs   ‚c                  ó   — y)a¥  
        Synchronously read a secret from your custom secret manager.

        Args:
            secret_name: Name/path of the secret to read
            optional_params: Additional parameters specific to your secret manager
            timeout: Request timeout

        Returns:
            The secret value if found, None otherwise

        Raises:
            Exception: If there's an error reading the secret
        Nr   r   s       r   Úsync_read_secretz$CustomSecretManager.sync_read_secret   s   � r   Úsecret_valueÚdescriptionÚtagsc              ƒ   ó<   K  — t        d| j                  › d�«      ‚­w)aÛ  
        Asynchronously write a secret to your custom secret manager.

        This is optional to implement. If your secret manager supports writing secrets,
        you can override this method.

        Args:
            secret_name: Name/path of the secret to write
            secret_value: Value to store
            description: Description of the secret
            optional_params: Additional parameters specific to your secret manager
            timeout: Request timeout
            tags: Optional tags to apply to the secret

        Returns:
            Response from the secret manager containing write operation details

        Raises:
            NotImplementedError: If write operations are not supported
        z)Write operations are not implemented for z5. Override async_write_secret() to add write support.©ÚNotImplementedErrorr	   )r   r   r   r   r   r   r    s          r   Úasync_write_secretz&CustomSecretManager.async_write_secret•   s0   è ø€ ô: "Ø7¸×8PÑ8PÐ7Qð RBð Bó
ð 	
ùó   ‚Úrecovery_window_in_daysc              ƒ   ó<   K  — t        d| j                  › d�«      ‚­w)aŸ  
        Asynchronously delete a secret from your custom secret manager.

        This is optional to implement. If your secret manager supports deleting secrets,
        you can override this method.

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

        Returns:
            Response from the secret manager containing deletion details

        Raises:
            NotImplementedError: If delete operations are not supported
        z*Delete operations are not implemented for z7. Override async_delete_secret() to add delete support.r"   )r   r   r&   r   r   s        r   Úasync_delete_secretz'CustomSecretManager.async_delete_secret·   s0   è ø€ ô2 "Ø8¸×9QÑ9QÐ8Rð SDð Dó
ð 	
ùr%   c                 ó.   — t        j                  d«       y)a=  
        Validate that all required environment variables and configuration are present.

        Override this method to validate your secret manager's configuration.

        Returns:
            True if the environment is valid

        Raises:
            ValueError: If required configuration is missing
        z>No environment validation configured for custom secret managerT)r   Údebug©r   s    r   Úvalidate_environmentz(CustomSecretManager.validate_environmentÕ   s   € ô 	×ÑÐ]Ô^Ør   c              ƒ   óL   K  — t        j                  d| j                  «       y­w)a#  
        Perform a health check on your secret manager.

        This is optional to implement. Override this method to add health check support.

        Args:
            timeout: Request timeout

        Returns:
            True if the secret manager is healthy, False otherwise
        z#Health check not implemented for %sT)r   r*   r	   )r   r   s     r   Úasync_health_checkz&CustomSecretManager.async_health_checkä   s"   è ø€ ô 	×ÑÐBÀD×D\ÑD\Ô]Øùs   ‚"$c                 óP   — d| j                   j                  › d| j                  › d�S )Nú<z(name=z)>)r   Ú__name__r	   r+   s    r   Ú__repr__zCustomSecretManager.__repr__ó   s)   € Ø�4—>‘>×*Ñ*Ð+¨6°$×2JÑ2JÐ1KÈ2ÐNÐNr   )N)NN)NNNN)é   NN)r1   Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   ÚdictÚfloatÚhttpxÚTimeoutr   r   Úlistr   r$   Úintr(   Úboolr,   r.   r2   Ú__classcell__)r   s   @r   r   r   0   sâ  ø„ ñ%ðR +/ñAà  4™ZõAð" ð (,Ø04ñ	àðð  ™ðð ˜Ÿ™Ñ&¨Ñ-ð	ð
 
ˆt‰òó ðð* ð (,Ø04ñ	àðð  ™ðð ˜Ÿ™Ñ&¨Ñ-ð	ð
 
ˆt‰òó ðð2 #'Ø'+Ø04Ø#'ñ 
àð 
ð ð 
ð ˜4‘Zð	 
ð
  ™ð 
ð ˜Ÿ™Ñ&¨Ñ-ð 
ð �T‰k˜DÑ ð 
ð 
ˆc�3ˆh‰ó 
ðJ /0Ø'+Ø04ñ
àð
ð "% t¡ð
ð  ™ð	
ð
 ˜Ÿ™Ñ&¨Ñ-ð
ð 
ó
ð< dó ñ°¸¿¹Ñ0EÈÑ0Lð ÐX\ó ðO˜#÷ Or   r   )r6   Úabcr   Útypingr   r:   Úlitellm._loggingr   Ú+litellm.secret_managers.base_secret_managerr   r   r   r   r   ú<module>rD      s-   ðñ$õL Ý ã å +Ý IôDOÐ+õ DOr   