o
    hg                     @  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   {/var/www/html/construction_image-detection-poc/venv/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strr   r   c                 C  s   i | _ || _|| _d S N)r   r   _project_id)selfr   r    r   r   r   __init__(   s   
z#GoogleSecretManagerMapping.__init__c                 C  s   | j | jS r"   )r   common_project_pathr#   r$   r   r   r   _gcp_project_path-   s   z,GoogleSecretManagerMapping._gcp_project_path	list[str]c                   s    fdd j j jdD S )Nc                   s"   g | ]} j |jd dqS )secret )r   parse_secret_pathnameget).0r*   r'   r   r   
<listcomp>3   s    z<GoogleSecretManagerMapping._secret_names.<locals>.<listcomp>)parent)r   list_secretsr(   r'   r   r'   r   _secret_names1   s   
z(GoogleSecretManagerMapping._secret_nameslatestkeyversionc                 C  s   | j | j||S r"   )r   secret_version_pathr#   )r$   r5   r6   r   r   r   _secret_version_path8   s   z/GoogleSecretManagerMapping._secret_version_path
str | Nonec                 C  sf   || j vr.|| jvrt|z| jj| |djjd| j |< W n t	y-   t|w | j | S )N)r-   zUTF-8)
r   r3   KeyErrorr   access_secret_versionr8   payloaddatadecode	Exception)r$   r5   r   r   r   __getitem__;   s   



z&GoogleSecretManagerMapping.__getitem__intc                 C  
   t | jS r"   )lenr3   r'   r   r   r   __len__J      
z"GoogleSecretManagerMapping.__len__Iterator[str]c                 C  rB   r"   )iterr3   r'   r   r   r   __iter__M   rE   z#GoogleSecretManagerMapping.__iter__N)r   r   r    r!   r   r   r   r!   )r   r)   )r4   )r5   r!   r6   r!   r   r!   )r5   r!   r   r9   )r   rA   )r   rF   )__name__
__module____qualname____annotations__r%   propertyr(   r   r3   r8   r@   rD   rH   r   r   r   r   r   $   s   
 


r   c                      sZ   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#   Nsettings_clstype[BaseSettings]credentialsCredentials | Noner    r9   
env_prefixenv_parse_none_strenv_parse_enumsbool | Noner   !SecretManagerServiceClient | Noner   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 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)rS   TF)case_sensitiverU   env_ignore_emptyrV   rW   )r   r   r   r   
isinstancer!   AttributeErrorrP   r#   r   superr%   )
r$   rQ   rS   r    rU   rV   rW   r   _credsr#   	__class__r   r   r%   V   s2   


z*GoogleSecretManagerSettingsSource.__init__Mapping[str, Optional[str]]c                 C  s   t | j| jdS )N)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=))ra   rJ   r#   env_nested_delimiterr'   r   r   r   __repr__   s   z*GoogleSecretManagerSettingsSource.__repr__)NNNNNN)rQ   rR   rS   rT   r    r9   rU   r9   rV   r9   rW   rX   r   rY   r   r   )r   rb   rI   )rJ   rK   rL   rM   r%   rc   rf   __classcell__r   r   r`   r   rO   Q   s   
 
0rO   )r   r   )
__future__r   _annotationscollections.abcr   r   	functoolsr   typingr   r   envr	   r   r   r   r   r   r   r   pydantic_settings.mainr   r   r!   r   rO   __all__r   r   r   r   <module>   s"    
-<