
    xi                        d dl mZ d dlmZmZ d dlmZ d dl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Z G d deeedz  f                   Z G d de          ZddgZdS )    )annotations)IteratorMapping)cached_property)TYPE_CHECKING   )EnvSettingsSourcedefaultCredentialsSecretManagerServiceClient)BaseSettingsNreturnNonec                 p    	 ddl ma ddlma ddlma d S # t          $ r} t          d          | d } ~ ww xY 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)es    /var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pydantic_settings/sources/providers/gcp.pyimport_gcp_secret_managerr      sz    
>>>>>>777777IIIIIIII   x
 
	s    
505c                  ~    e Zd ZU ded<   ded<   ddZedd            Zedd            ZdddZ	d dZ
d!dZd"dZdS )#GoogleSecretManagerMappingzdict[str, str | None]_loaded_secretsr   _secret_clientsecret_client
project_idstrcase_sensitiveboolr   r   c                >    i | _         || _        || _        || _        d S N)r   r   _project_id_case_sensitive)selfr    r!   r#   s       r   __init__z#GoogleSecretManagerMapping.__init__(   s(    !+%-    c                @    | j                             | j                  S r&   )r   common_project_pathr'   r)   s    r   _gcp_project_pathz,GoogleSecretManagerMapping._gcp_project_path.   s    "66t7GHHHr+   	list[str]c                   g }| j                             | j                  }|D ]e}| j                             |j                                      dd          }| j        s|                                }|                    |           f|S )N)parentsecret )	r   list_secretsr/   parse_secret_pathnamegetr(   lowerappend)r)   rvsecretsr3   r7   s        r   _secret_namesz(GoogleSecretManagerMapping._secret_names2   s    %22$:P2QQ 	 	F&88EEII(TVWWD' $zz||IIdOOOO	r+   latestkeyversionc                D    | j                             | j        ||          S r&   )r   secret_version_pathr'   )r)   r?   r@   s      r   _secret_version_pathz/GoogleSecretManagerMapping._secret_version_path>   s     "66t7GgVVVr+   
str | Nonec                x   | j         s|                                }|| j        vr|| j        vrt	          |          	 | j                            |                     |                    j        j	        
                    d          | j        |<   n# t          $ r t	          |          w xY w| j        |         S )N)r7   zUTF-8)r(   r9   r   r=   KeyErrorr   access_secret_versionrC   payloaddatadecode	Exception)r)   r?   s     r   __getitem__z&GoogleSecretManagerMapping.__getitem__A   s    # 	))++Cd***$,,,smm#$,0,?,U,U22377 -V - -$vvg $S))  $ $ $smm#$ #C((s   AB B,intc                *    t          | j                  S r&   )lenr=   r.   s    r   __len__z"GoogleSecretManagerMapping.__len__R   s    4%&&&r+   Iterator[str]c                *    t          | j                  S r&   )iterr=   r.   s    r   __iter__z#GoogleSecretManagerMapping.__iter__U   s    D&'''r+   N)r    r   r!   r"   r#   r$   r   r   r   r"   )r   r0   )r>   )r?   r"   r@   r"   r   r"   )r?   r"   r   rD   )r   rM   )r   rQ   )__name__
__module____qualname____annotations__r*   propertyr/   r   r=   rC   rL   rP   rT    r+   r   r   r   $   s         ****..... . . . I I I XI 	 	 	 _	W W W W W) ) ) )"' ' ' '( ( ( ( ( (r+   r   c                  `     e Zd ZU ded<   ded<   ded<   	 	 	 	 	 	 	 dd fdZddZddZ xZS ) !GoogleSecretManagerSettingsSourcer   _credentialsr   r   r"   r'   NTsettings_clstype[BaseSettings]credentialsCredentials | Noner!   rD   
env_prefixenv_parse_none_strenv_parse_enumsbool | Noner    !SecretManagerServiceClient | Noner#   r   r   c	                   t           t          t          t                       |r|st                      \  }	}
||	}|'t	          |
t
                    r|
}nt          d          || _        || _        |r|| _	        nt          | j                  | _	        t                                          |||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)ra   F)r#   rc   env_ignore_emptyrd   re   )r   r   r   r   
isinstancer"   AttributeErrorr^   r'   r   superr*   )r)   r_   ra   r!   rc   rd   re   r    r#   _credsr'   	__class__s              r   r*   z*GoogleSecretManagerSettingsSource.__init__^   s     &-1DH[Hc%'''  	8* 	8"5"7"7FK  K+s++ (

$ T   *5 * 	\"/D"<IZ"["["[D)!"1+ 	 	
 	
 	
 	
 	
r+   Mapping[str, str | None]c                D    t          | j        | j        | j                  S )N)r!   r#   )r   r   r'   r#   r.   s    r   _load_env_varsz0GoogleSecretManagerSettingsSource._load_env_vars   s)    )D,<TM`
 
 
 	
r+   c                @    | j         j         d| j        d| j        dS )Nz(project_id=z, env_nested_delimiter=))rn   rV   r'   env_nested_delimiterr.   s    r   __repr__z*GoogleSecretManagerSettingsSource.__repr__   sE    .)  A  At7G  A  Abfb{  A  A  A  	Ar+   )NNNNNNT)r_   r`   ra   rb   r!   rD   rc   rD   rd   rD   re   rf   r    rg   r#   rf   r   r   )r   ro   rU   )rV   rW   rX   rY   r*   rq   ru   __classcell__)rn   s   @r   r]   r]   Y   s         ....
 +/!%!%)-'+;?&*/
 /
 /
 /
 /
 /
 /
b
 
 
 

A A A A A A A Ar+   r]   )r   r   )
__future__r   _annotationscollections.abcr   r   	functoolsr   typingr   envr	   r   r   r   r   r   r   r   pydantic_settings.mainr   r   r"   r   r]   __all__r[   r+   r   <module>r      sZ   2 2 2 2 2 2 - - - - - - - - % % % % % %             " " " " " " 	::::::333333EEEEEE3333333K!%   2( 2( 2( 2( 2(cDj!9 2( 2( 2(j<A <A <A <A <A(9 <A <A <A~ /0L
Mr+   