o
    mqi                     @  s   d dl mZ d dlmZmZ d dlmZ d dlm	Z	m
Z
 ddlmZ e	r=d dlma d dlma d d	lma d d
lmZ ndadadadddZG dd deee
e f ZG dd deZddgZdS )    )annotations)IteratorMapping)cached_property)TYPE_CHECKINGOptional   )EnvSettingsSourcedefaultCredentialsSecretManagerServiceClient)BaseSettingsNreturnNonec               
   C  sN   zddl ma ddlma ddlma W d S  ty& }  ztd| d } ~ ww )Nr   r
   r   r   zjGCP Secret Manager dependencies are not installed, run `pip install pydantic-settings[gcp-secret-manager]`)google.authr   google_auth_defaultgoogle.auth.credentialsr   google.cloud.secretmanagerr   ImportError)e r   n/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/pydantic_settings/sources/providers/gcp.pyimport_gcp_secret_manager   s   r   c                   @  sn   e Zd ZU ded< ded< d"ddZed#ddZed$ddZd%d&ddZ	d'ddZ
d(ddZd)dd Zd!S )*GoogleSecretManagerMappingzdict[str, str | None]_loaded_secretsr   _secret_clientsecret_client
project_idstrcase_sensitiveboolr   r   c                 C  s   i | _ || _|| _|| _d S N)r   r   _project_id_case_sensitive)selfr   r    r"   r   r   r   __init__(   s   
z#GoogleSecretManagerMapping.__init__c                 C  s   | j | jS r$   )r   Zcommon_project_pathr%   r'   r   r   r   _gcp_project_path.   s   z,GoogleSecretManagerMapping._gcp_project_path	list[str]c                 C  sP   g }| j j| jd}|D ]}| j |jdd}| js | }|| q|S )N)parentsecret )	r   Zlist_secretsr*   Zparse_secret_pathnamegetr&   lowerappend)r'   rvZsecretsr-   r/   r   r   r   _secret_names2   s   z(GoogleSecretManagerMapping._secret_nameslatestkeyversionc                 C  s   | j | j||S r$   )r   Zsecret_version_pathr%   )r'   r6   r7   r   r   r   _secret_version_path>   s   z/GoogleSecretManagerMapping._secret_version_path
str | Nonec                 C  st   | j s| }|| jvr5|| jvrt|z| jj| |djj	
d| j|< W n ty4   t|w | j| S )N)r/   zUTF-8)r&   r1   r   r4   KeyErrorr   Zaccess_secret_versionr8   payloaddatadecode	Exception)r'   r6   r   r   r   __getitem__A   s   



z&GoogleSecretManagerMapping.__getitem__intc                 C  
   t | jS r$   )lenr4   r)   r   r   r   __len__R      
z"GoogleSecretManagerMapping.__len__Iterator[str]c                 C  rA   r$   )iterr4   r)   r   r   r   __iter__U   rD   z#GoogleSecretManagerMapping.__iter__N)r   r   r    r!   r"   r#   r   r   r   r!   )r   r+   )r5   )r6   r!   r7   r!   r   r!   )r6   r!   r   r9   )r   r@   )r   rE   )__name__
__module____qualname____annotations__r(   propertyr*   r   r4   r8   r?   rC   rG   r   r   r   r   r   $   s   
 


r   c                      s\   e Zd ZU ded< ded< ded< 							dd  fddZd!ddZd"ddZ  ZS )#!GoogleSecretManagerSettingsSourcer   _credentialsr   r   r!   r%   NTsettings_clstype[BaseSettings]credentialsCredentials | Noner    r9   
env_prefixenv_parse_none_strenv_parse_enumsbool | Noner   !SecretManagerServiceClient | Noner"   r   r   c	                   s   t d u std u std u rt  |r|st \}	}
|d u r|	}|d u r.t|
tr*|
}ntd|| _|| _|r:|| _	nt | jd| _	t
 j|||d||d d S )Nzproject_id is required to be specified either as an argument or from the google.auth.default. See https://google-auth.readthedocs.io/en/master/reference/google.auth.html#google.auth.default)rR   F)r"   rT   Zenv_ignore_emptyrU   rV   )r   r   r   r   
isinstancer!   AttributeErrorrO   r%   r   superr(   )r'   rP   rR   r    rT   rU   rV   r   r"   Z_credsr%   	__class__r   r   r(   ^   s2   


z*GoogleSecretManagerSettingsSource.__init__Mapping[str, Optional[str]]c                 C  s   t | j| j| jdS )N)r    r"   )r   r   r%   r"   r)   r   r   r   _load_env_vars   s   z0GoogleSecretManagerSettingsSource._load_env_varsc                 C  s   | j j d| jd| jdS )Nz(project_id=z, env_nested_delimiter=))r]   rI   r%   Zenv_nested_delimiterr)   r   r   r   __repr__   s   z*GoogleSecretManagerSettingsSource.__repr__)NNNNNNT)rP   rQ   rR   rS   r    r9   rT   r9   rU   r9   rV   rW   r   rX   r"   rW   r   r   )r   r^   rH   )rI   rJ   rK   rL   r(   r_   ra   __classcell__r   r   r\   r   rN   Y   s   
 
1rN   )r   r   )
__future__r   Z_annotationscollections.abcr   r   	functoolsr   typingr   r   envr	   r   r   r   r   r   r   r   Zpydantic_settings.mainr   r   r!   r   rN   __all__r   r   r   r   <module>   s"    
5?