Ë
    ïÏj†;  ã                  ó  — d dl mZ d dl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 ddl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dd„Z  G d„ dee!e!dz  f   «      Z" G d„ de«      Z#ddgZ$y)é    )ÚannotationsN)ÚIteratorÚMapping)Úcached_property)ÚTYPE_CHECKINGÚAny)Ú	FieldInfoé   )ÚSettingsErroré   )ÚSecretVersion)Ú	InitStateé   )ÚEnvSettingsSource©Údefault©ÚCredentials©ÚSecretManagerServiceClient)ÚBaseSettingsc                 óì   — 	 ddl ma ddlma t        j                  «       5  t        j                  dt        ¬«       ddl	m
a
 d d d «       y # 1 sw Y   y xY w# t        $ r} t        d«      | ‚d } ~ ww xY w)Nr   r   r   Úignore)Úcategoryr   zjGCP Secret Manager dependencies are not installed, run `pip install pydantic-settings[gcp-secret-manager]`)Úgoogle.authr   Úgoogle_auth_defaultÚgoogle.auth.credentialsr   ÚwarningsÚcatch_warningsÚfilterwarningsÚFutureWarningÚgoogle.cloud.secretmanagerr   ÚImportError)Úes    úd/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/pydantic_settings/sources/providers/gcp.pyÚimport_gcp_secret_managerr&      s\   € ð

Ý>Ý7ä×$Ñ$Õ&Ü×#Ñ# H´}ÕEÝM÷ '×&Ñ&ûô ò ÜØxó
àð	ûðús4   ‚ A ¢"AÁA ÁAÁA ÁA Á	A3Á"A.Á.A3c                óF   — 	 ddl m} t        | |«      S # t        $ r Y yw xY w)Nr   )ÚNotFoundF)Úgoogle.api_core.exceptionsr(   Ú
isinstancer#   )Úexcr(   s     r%   Ú_is_not_found_errorr,   -   s)   € ðÝ7ä˜#˜xÓ(Ð(øÜò Ùðús   ‚ ”	 Ÿ c                  óœ   — e Zd ZU ded<   ded<   dd„Zedd„«       Zdd„Zedd„«       Z	edd	„«       Z
ddd
„Zddd„Zdd„Zdd„Zdd„Zdd„Zy)ÚGoogleSecretManagerMappingzdict[str, str | None]Ú_loaded_secretsr   Ú_secret_clientc                ó<   — i | _         || _        || _        || _        y ©N)r/   r0   Ú_project_idÚ_case_sensitive)ÚselfÚsecret_clientÚ
project_idÚcase_sensitives       r%   Ú__init__z#GoogleSecretManagerMapping.__init__:   s"   € Ø!ˆÔØ+ˆÔØ%ˆÔØ-ˆÕó    c                óL   — | j                   j                  | j                  «      S r2   )r0   Úcommon_project_pathr3   ©r5   s    r%   Ú_gcp_project_pathz,GoogleSecretManagerMapping._gcp_project_path@   s   € à×"Ñ"×6Ñ6°t×7GÑ7GÓHÐHr:   c           	     ó¢   — t        |«      dk(  r|d   S |j                  «        |d   }t        j                  d|› d|› d|› d�t        d¬	«       |S )
Nr   r   éÿÿÿÿz)Secret collision: Found multiple secrets z normalizing to 'z
'. Using 'z' for case-insensitive lookup.r   )Ú
stacklevel)ÚlenÚsortr   ÚwarnÚUserWarning)r5   Ú
lower_nameÚ
candidatesÚwinners       r%   Ú_select_case_insensitive_secretz:GoogleSecretManagerMapping._select_case_insensitive_secretD   si   € Üˆz‹?˜aÒØ˜a‘=Ð ð 	�‰ÔØ˜B‘ˆÜ�‰Ø7¸
°|ÐCTÐU_ÐT`ð aØ�XÐ;ð=äØõ		
ð ˆr:   c                óÂ  — i }i }| j                   j                  | j                  ¬«      }|D ]v  }| j                   j                  |j                  «      j                  dd«      }|||<   | j                  rŒJ|j                  «       }||vrg ||<   ||   j                  |«       Œx | j                  s-|j                  «       D ]  \  }}| j                  ||«      ||<   Œ |S )N)ÚparentÚsecretÚ )r0   Úlist_secretsr>   Úparse_secret_pathÚnameÚgetr4   ÚlowerÚappendÚitemsrI   )r5   ÚmappingÚnormalized_groupsÚsecretsrL   rP   rF   rG   s           r%   Ú_secret_name_mapz+GoogleSecretManagerMapping._secret_name_mapS   så   € à"$ˆà24Ðà×%Ñ%×2Ñ2¸$×:PÑ:PÐ2ÓQˆÛˆFØ×&Ñ&×8Ñ8¸¿¹ÓE×IÑIÈ(ÐTVÓWˆDØ ˆG�D‰Mà×'Ó'Ø!ŸZ™Z›\�
ØÐ%6Ñ6Ø46Ð% jÑ1Ø! *Ñ-×4Ñ4°TÕ:ð ð ×#Ò#Ø*;×*AÑ*AÖ*CÑ&�
˜JØ&*×&JÑ&JÈ:ÐWaÓ&b�˜
Ò#ð +Dð ˆr:   c                óH   — t        | j                  j                  «       «      S r2   )ÚlistrX   Úkeysr=   s    r%   Ú_secret_namesz(GoogleSecretManagerMapping._secret_namesj   s   € ä�D×)Ñ)×.Ñ.Ó0Ó1Ð1r:   c                óP   — | j                   j                  | j                  ||«      S r2   )r0   Úsecret_version_pathr3   )r5   ÚkeyÚversions      r%   Ú_secret_version_pathz/GoogleSecretManagerMapping._secret_version_pathn   s#   € Ø×"Ñ"×6Ñ6°t×7GÑ7GÈÈgÓVÐVr:   c                óÀ   — 	 | j                   j                  | j                  ||«      ¬«      j                  j                  j                  d«      S # t        $ r Y y w xY w©N)rP   zUTF-8)r0   Úaccess_secret_versionra   ÚpayloadÚdataÚdecodeÚ	Exception)r5   Úgcp_secret_namer`   s      r%   Ú_get_secret_valuez,GoogleSecretManagerMapping._get_secret_valueq   sZ   € ð	Ø×&Ñ&×<Ñ<Ø×.Ñ.¨ÀÓHð =ó ç‰g—d‘dŸ6™6 '›?ð+øô ò 	Ùð	ús   ‚AA Á	AÁAc                óú   — 	 | j                   j                  | j                  |«      ¬«      j                  j                  j                  d«      S # t        $ r!}t        |«      rt        |«      |‚Y d }~y d }~ww xY wrc   )	r0   rd   ra   re   rf   rg   rh   r,   ÚKeyError)r5   ri   r$   s      r%   Ú_get_secret_value_or_raisez5GoogleSecretManagerMapping._get_secret_value_or_raisey   sn   € ð	Ø×&Ñ&×<Ñ<Ø×.Ñ.¨Ó?ð =ó ç‰g—d‘dŸ6™6 '›?ð+øô ò 	Ü" 1Ô%Ü˜Ó/°QÐ6Üûð	ús   ‚AA Á	A:ÁA5Á5A:c                ó°  — || j                   v r| j                   |   S | j                  r-| j                  |«      | j                   |<   | j                   |   S | j                  j	                  |«      }|€)| j                  j	                  |j                  «       «      }|r| j                  |«      | j                   |<   nt        |«      ‚| j                   |   S r2   )r/   r4   rm   rX   rQ   rR   rj   rl   )r5   r_   ri   s      r%   Ú__getitem__z&GoogleSecretManagerMapping.__getitem__ƒ   sÇ   € Ø�$×&Ñ&Ñ&Ø×'Ñ'¨Ñ,Ð,à×ÒØ(,×(GÑ(GÈÓ(LˆD× Ñ  Ñ%Ø×'Ñ'¨Ñ,Ð,à×/Ñ/×3Ñ3°CÓ8ˆØÐ"Ø"×3Ñ3×7Ñ7¸¿	¹	»ÓDˆOáØ(,×(>Ñ(>¸Ó(OˆD× Ñ  Ò%ä˜3“-Ðà×#Ñ# CÑ(Ð(r:   c                ó,   — t        | j                  «      S r2   )rB   r\   r=   s    r%   Ú__len__z"GoogleSecretManagerMapping.__len__–   s   € Ü�4×%Ñ%Ó&Ð&r:   c                ó,   — t        | j                  «      S r2   )Úiterr\   r=   s    r%   Ú__iter__z#GoogleSecretManagerMapping.__iter__™   s   € Ü�D×&Ñ&Ó'Ð'r:   N)r6   r   r7   Ústrr8   ÚboolÚreturnÚNone©rw   ru   )rF   ru   rG   ú	list[str]rw   ru   )rw   zdict[str, str])rw   rz   )Úlatest)r_   ru   r`   ru   rw   ru   )ri   ru   r`   ru   rw   ú
str | None)ri   ru   rw   r|   )r_   ru   rw   r|   )rw   Úint)rw   zIterator[str])Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r9   Úpropertyr>   rI   r   rX   r\   ra   rj   rm   ro   rq   rt   © r:   r%   r.   r.   6   su   … Ø*Ó*Ø.Ó.ó.ð òIó ðIóð òó ðð, ò2ó ð2ôWôóó)ó&'ô(r:   r.   c                  ó¸   ‡ — e Zd ZU ded<   ded<   ded<   ded<   	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdˆ fd	„Zdd
„Zdd„Zdˆ fd„Zdd„Z	ˆ xZ
S )Ú!GoogleSecretManagerSettingsSourceúCredentials | NoneÚ_credentialsú!SecretManagerServiceClient | Noner0   r|   r3   Ú_explicit_project_idc           	     óÌ   •— t         �t        �t        €
t        «        || _        d| _        || _        || _        |	| _        d| _	        t        ‰| �-  |||d|||
¬«       d| _	        y)a¹  Settings source that reads secrets from Google Cloud Secret Manager.

        Args:
            project_id: The GCP project to read secrets from. If not provided, it is
                resolved lazily (see below).
            project_id_field: The key, populated by a previous (higher priority)
                settings source, to use as the ``project_id`` when one is not passed
                explicitly. This must match the key used in ``current_state`` by the
                previous source (typically the field name or its preferred alias).
                For example, with ``some_field: str = Field(alias='GCP_PROJECT')``,
                previous env sources will expose the value under ``'GCP_PROJECT'``.
                Defaults to ``'project_id'``.

        The ``project_id`` is resolved lazily in :meth:`__call__` rather than at
        construction time so that it can be sourced from settings resolved by previous
        sources (only available via ``current_state`` once the source is called).
        Resolution order is:

        1. the explicit ``project_id`` argument
        2. the ``project_id_field`` value from previous settings sources
        3. ``google.auth.default()``
        NF)r8   Ú
env_prefixÚenv_ignore_emptyÚenv_parse_none_strÚenv_parse_enumsÚ_init_stateT)r   r   r   r&   r‰   r3   r‡   r0   Ú_project_id_fieldÚ_env_vars_loadedÚsuperr9   )r5   Úsettings_clsÚcredentialsr7   r‹   r�   rŽ   r6   r8   Úproject_id_fieldr�   Ú	__class__s              €r%   r9   z*GoogleSecretManagerSettingsSource.__init__£   s€   ø€ ôH &Ð-´Ð1DÔH[ÐHcÜ%Ô'ð
 %/ˆÔ!ØˆÔØ'ˆÔØ+ˆÔØ!1ˆÔØ %ˆÔä‰ÑØØ)Ø!Ø"Ø1Ø+Ø#ð 	ô 	
ð !%ˆÕr:   c                óº  •— t        d„ |j                  D «       d«      }|r÷t        | j                  t        «      rÝ| j                  ||«      D ]Ã  \  }}}| j                  r|}nZ| j                  j                  j                  |«      }|€3| j                  j                  j                  |j                  «       «      }|sŒs| j                  j                  ||«      }|€Œ’| j                  j                  j                  d«      r|||fc S |||fc S  d|dfS t        ‰| �9  ||«      \  }	}
}| j                  j                  j                  d«      r|	�|	||fS |	|
|fS )aü  Override get_field_value to get the secret value from GCP Secret Manager.
        Look for a SecretVersion metadata field to specify a particular SecretVersion.

        Args:
            field: The field to get the value for
            field_name: The declared name of the field

        Returns:
            A tuple of (value, key, value_is_complex), where `key` is the identifier used
            to populate the model (either the field name or an alias, depending on
            configuration).
        c              3  óV   K  — | ]!  }t        |t        «      sŒ|j                  –— Œ# y ­wr2   )r*   r   r`   )Ú.0Úms     r%   Ú	<genexpr>zDGoogleSecretManagerSettingsSource.get_field_value.<locals>.<genexpr>î   s   è ø€ Ða±.¨QÄJÈqÔR_ÕD`˜qŸy�y±.ùs   ‚)˜)NÚpopulate_by_nameF)ÚnextÚmetadatar*   Úenv_varsr.   Ú_extract_field_infor8   rX   rQ   rR   rj   r“   Úmodel_configr’   Úget_field_value)r5   ÚfieldÚ
field_nameÚsecret_versionÚ	field_keyÚenv_nameÚvalue_is_complexri   Úenv_valÚvalr_   Ú
is_complexr–   s               €r%   r¢   z1GoogleSecretManagerSettingsSource.get_field_valueà   sZ  ø€ ô Ña°%·.².ÓaÐcgÓhˆñ
 œj¨¯©Ô8RÔSØ9=×9QÑ9QÐRWÐYcÖ9dÑ5�	˜8Ð%5Ø×&Ò&Ø2:‘Oà&*§m¡m×&DÑ&D×&HÑ&HÈÓ&R�OØ&Ð.Ø*.¯-©-×*HÑ*H×*LÑ*LÈXÏ^É^ÓM]Ó*^˜â"Ø"Ÿm™m×=Ñ=¸oÈ~Ó^�GØÑ*ð  ×,Ñ,×9Ñ9×=Ñ=Ð>PÔQØ#*¨JÐ8HÐ#HÒHØ&¨	Ð3CÐCÒCð :eð& ˜ UÐ*Ð*ä$™wÑ6°u¸jÓIÑˆˆS�*ð ×Ñ×)Ñ)×-Ñ-Ð.@ÔAÀcÀoØ˜
 JÐ.Ð.Ø�C˜Ð#Ð#r:   c                óÈ  — | j                   �y| j                  }| j                  }|€7| j                  j	                  | j
                  «      }t        |t        «      r|}| j                  du xr |du }|du }|s|r%t        «       \  }}|r|}|rt        |t        «      r|}|€t        d«      ‚|| _        || _         | j                  €t        | j                  ¬«      | _        yy)a:  Resolve the credentials, project_id and Secret Manager client.

        ``project_id`` is resolved, in order of precedence, from: the explicit
        ``project_id`` argument, the ``project_id_field`` value from previous settings
        sources (``current_state``), and finally ``google.auth.default()``.
        NzÚproject_id is required to be specified either as an argument, via a previous settings source, or from google.auth.default. See https://google-auth.readthedocs.io/en/master/reference/google.auth.html#google.auth.default)r”   )r3   r‰   r‡   Úcurrent_staterQ   r�   r*   ru   r0   r   ÚAttributeErrorr   )r5   r7   r”   Ústate_project_idÚneed_credentialsÚneed_projectÚ_credsr3   s           r%   Ú_resolve_gcp_projectz6GoogleSecretManagerSettingsSource._resolve_gcp_project  sÿ   € ð ×ÑÐ'Øà×.Ñ.ˆ
Ø×'Ñ'ˆð ÐØ#×1Ñ1×5Ñ5°d×6LÑ6LÓMÐÜÐ*¬CÔ0Ø-�
ð  ×.Ñ.°$Ð6ÒN¸;È$Ð;NÐØ! TÐ)ˆÙ™|Ü"5Ó"7ÑˆF�KÙØ$�Ù¤
¨;¼Ô <Ø(�
àÐÜ ðnóð ð (ˆÔØ%ˆÔØ×ÑÐ&Ü"<È×IZÑIZÔ"[ˆDÕð 'r:   c                óÜ   — | j                   si S | j                  «        | j                  �| j                  €t	        d«      ‚t        | j                  | j                  | j                  ¬«      S )NzæGoogleSecretManagerSettingsSource: could not determine GCP project_id or initialize the Secret Manager client. Pass project_id explicitly or ensure it is available via application default credentials or a previous settings source.)r7   r8   )r‘   r³   r3   r0   r   r.   r8   r=   s    r%   Ú_load_env_varsz0GoogleSecretManagerSettingsSource._load_env_vars=  sp   € ð ×$Ò$ØˆIà×!Ñ!Ô#Ø×ÑÐ# t×':Ñ':Ð'BÜðJóð ô *Ø×Ñ¨D×,<Ñ,<ÈT×M`ÑM`ô
ð 	
r:   c                óX   •— d| _         | j                  «       | _        t        ‰| �  «       S )NT)r‘   rµ   rŸ   r’   Ú__call__)r5   r–   s    €r%   r·   z*GoogleSecretManagerSettingsSource.__call__M  s+   ø€ ð !%ˆÔØ×+Ñ+Ó-ˆŒÜ‰wÑÓ!Ð!r:   c                óœ   — | j                   �| j                   n| j                  }| j                  j                  › d|›d| j                  ›d�S )Nz(project_id=z, env_nested_delimiter=Ú))r3   r‰   r–   r~   Úenv_nested_delimiter)r5   r7   s     r%   Ú__repr__z*GoogleSecretManagerSettingsSource.__repr__T  sR   € ð *.×)9Ñ)9Ð)E�T×%Ò%È4×KdÑKdˆ
à�~‰~×&Ñ&Ð' |°J°>ÐAXÐY]×YrÑYrÐXuÐuvÐwð	
r:   )	NNNNNNTr7   N)r“   ztype[BaseSettings]r”   r†   r7   r|   r‹   r|   r�   r|   rŽ   úbool | Noner6   rˆ   r8   r¼   r•   ru   r�   zInitState | Nonerw   rx   )r£   r	   r¤   ru   rw   ztuple[Any, str, bool]©rw   rx   )rw   zMapping[str, str | None])rw   zdict[str, Any]ry   )r~   r   r€   r�   r9   r¢   r³   rµ   r·   r»   Ú__classcell__)r–   s   @r%   r…   r…   �   sÆ   ø… Ø$Ó$Ø5Ó5ØÓØ$Ó$ð
 +/Ø!%Ø!%Ø)-Ø'+Ø;?Ø&*Ø ,Ø(,ð;%à(ð;%ð (ð;%ð ð	;%ð
 ð;%ð 'ð;%ð %ð;%ð 9ð;%ð $ð;%ð ð;%ð &ð;%ð 
õ;%õz/$ób*\óX
õ "÷
r:   r…   r½   )r+   rh   rw   rv   )%Ú
__future__r   Ú_annotationsr   Úcollections.abcr   r   Ú	functoolsr   Útypingr   r   Úpydantic.fieldsr	   Ú
exceptionsr   Útypesr   Úutilsr   Úenvr   r   r   r   r   r   r"   r   Úpydantic_settings.mainr   r&   r,   ru   r.   r…   Ú__all__rƒ   r:   r%   Ú<module>rË      s†   ðÝ 2ã ß -Ý %ß %å %å 'Ý !Ý Ý "áÝ:Ý3ÝEæ3à€KØ!%ÐØÐóó$ôd( ¨¨c°D©j¨Ñ!9ô d(ôN}
Ð(9ô }
ð@ (Ð)LÐ
M�r:   