Ë
    rPê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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„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Ú_parse_env_none_strÚ_validate_by_name_enabledé   )Ú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    úl/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/pydantic_settings/sources/providers/gcp.pyÚimport_gcp_secret_managerr(      si   € ð

Ý>Ý7ä×$Ñ$Ó&ñ 	NÜ×#Ñ# H´}ÕEÝM÷	N÷ 	Nñ 	Nûô ò ÜØ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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_clientNc                óJ   — i | _         || _        || _        || _        || _        y ©N)r1   r2   Ú_project_idÚ_case_sensitiveÚ_env_parse_none_str)ÚselfÚsecret_clientÚ
project_idÚcase_sensitiveÚenv_parse_none_strs        r'   Ú__init__z#GoogleSecretManagerMapping.__init__:   s,   € ð  "ˆÔØ+ˆÔØ%ˆÔØ-ˆÔØ#5ˆÕ ó    c                óL   — | j                   j                  | j                  «      S r4   )r2   Úcommon_project_pathr5   ©r8   s    r'   Ú_gcp_project_pathz,GoogleSecretManagerMapping._gcp_project_pathG   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)r8   Ú
lower_nameÚ
candidatesÚwinners       r'   Ú_select_case_insensitive_secretz:GoogleSecretManagerMapping._select_case_insensitive_secretK   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Ú )r2   Úlist_secretsrB   Úparse_secret_pathÚnameÚgetr6   ÚlowerÚappendÚitemsrM   )r8   ÚmappingÚnormalized_groupsÚsecretsrP   rT   rJ   rK   s           r'   Ú_secret_name_mapz+GoogleSecretManagerMapping._secret_name_mapZ   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ò cÑ&�
˜JØ&*×&JÑ&JÈ:ÐWaÓ&b�˜
Ò#ðcð ˆr>   c                óH   — t        | j                  j                  «       «      S r4   )Úlistr\   ÚkeysrA   s    r'   Ú_secret_namesz(GoogleSecretManagerMapping._secret_namesq   s   € ä�D×)Ñ)×.Ñ.Ó0Ó1Ð1r>   c                óP   — | j                   j                  | j                  ||«      S r4   )r2   Úsecret_version_pathr5   )r8   ÚkeyÚversions      r'   Ú_secret_version_pathz/GoogleSecretManagerMapping._secret_version_pathu   s#   € Ø×"Ñ"×6Ñ6°t×7GÑ7GÈÈgÓVÐVr>   c                óì   — 	 | j                   j                  | j                  ||«      ¬«      j                  j                  j                  d«      }t        || j                  «      S # t        $ r Y y w xY w©N)rT   zUTF-8)	r2   Úaccess_secret_versionre   ÚpayloadÚdataÚdecodeÚ	Exceptionr   r7   )r8   Úgcp_secret_namerd   Úvalues       r'   Ú_get_secret_valuez,GoogleSecretManagerMapping._get_secret_valuex   so   € ð	Ø×'Ñ'×=Ñ=Ø×.Ñ.¨ÀÓHð >ó ç‰g—d‘dŸ6™6 '›?ð ô
 # 5¨$×*BÑ*BÓCÐCøô ò 	Ùð	ús   ‚AA' Á'	A3Á2A3c                ó&  — 	 | j                   j                  | j                  |«      ¬«      j                  j                  j                  d«      }t        || j                  «      S # t        $ r!}t        |«      rt        |«      |‚Y d }~y d }~ww xY wrg   )r2   rh   re   ri   rj   rk   rl   r.   ÚKeyErrorr   r7   )r8   rm   rn   r&   s       r'   Ú_get_secret_value_or_raisez5GoogleSecretManagerMapping._get_secret_value_or_raise�   sƒ   € ð	Ø×'Ñ'×=Ñ=Ø×.Ñ.¨Ó?ð >ó ç‰g—d‘dŸ6™6 '›?ð ô # 5¨$×*BÑ*BÓCÐCøô	 ò 	Ü" 1Ô%Ü˜Ó/°QÐ6Üûð	ús   ‚AA& Á&	BÁ/BÂBc                ó°  — || j                   v r| j                   |   S | j                  r-| j                  |«      | j                   |<   | j                   |   S | j                  j	                  |«      }|€)| j                  j	                  |j                  «       «      }|r| j                  |«      | j                   |<   nt        |«      ‚| j                   |   S r4   )r1   r6   rr   r\   rU   rV   ro   rq   )r8   rc   rm   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 r4   )rF   r`   rA   s    r'   Ú__len__z"GoogleSecretManagerMapping.__len__Ÿ   s   € Ü�4×%Ñ%Ó&Ð&r>   c                ó,   — t        | j                  «      S r4   )Úiterr`   rA   s    r'   Ú__iter__z#GoogleSecretManagerMapping.__iter__¢   s   € Ü�D×&Ñ&Ó'Ð'r>   r4   )
r9   r   r:   Ústrr;   Úboolr<   ú
str | NoneÚreturnÚNone©r}   rz   )rJ   rz   rK   ú	list[str]r}   rz   )r}   zdict[str, str])r}   r€   )Úlatest)rc   rz   rd   rz   r}   rz   )rm   rz   rd   rz   r}   r|   )rm   rz   r}   r|   )rc   rz   r}   r|   )r}   Úint)r}   zIterator[str])Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r=   ÚpropertyrB   rM   r   r\   r`   re   ro   rr   rt   rv   ry   © r>   r'   r0   r0   6   s¬   … Ø*Ó*Ø.Ó.ð *.ð6à1ð6ð ð6ð ð	6ð
 'ð6ð 
ó6ð òIó ðIóð òó ðð, ò2ó ð2ôWôDó	Dó)ó&'ô(r>   r0   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 | Noner2   r|   r5   Ú_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)r;   Ú
env_prefixÚenv_ignore_emptyr<   Úenv_parse_enumsÚ_init_stateT)r   r   r   r(   rŽ   r5   rŒ   r2   Ú_project_id_fieldÚ_env_vars_loadedÚsuperr=   )r8   Úsettings_clsÚcredentialsr:   r�   r<   r’   r9   r;   Úproject_id_fieldr“   Ú	__class__s              €r'   r=   z*GoogleSecretManagerSettingsSource.__init__¬   s€   ø€ ôH &Ð-´Ð1DÔH[ÐHcÜ%Ô'ð
 %/ˆÔ!ØˆÔØ'ˆÔØ+ˆÔØ!1ˆÔØ %ˆÔä‰ÑØØ)Ø!Ø"Ø1Ø+Ø#ð 	ô 	
ð !%ˆÕr>   c                óz  •— 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                  ||«      }|€Œ’t        | j                  «      r|||fc S |||fc S  d|dfS t        ‰| �9  ||«      \  }	}
}t        | j                  «      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r4   )r,   r   rd   )Ú.0Úms     r'   ú	<genexpr>zDGoogleSecretManagerSettingsSource.get_field_value.<locals>.<genexpr>÷   s   è ø€ Òa¨QÄJÈqÔR_ÕD`˜qŸy�yÑaùs   ‚)˜)NF)ÚnextÚmetadatar,   Úenv_varsr0   Ú_extract_field_infor;   r\   rU   rV   ro   r   Úconfigr–   Úget_field_value)r8   ÚfieldÚ
field_nameÚsecret_versionÚ	field_keyÚenv_nameÚvalue_is_complexrm   Úenv_valÚvalrc   Ú
is_complexrš   s               €r'   r¥   z1GoogleSecretManagerSettingsSource.get_field_valueé   sD  ø€ ô Ña°%·.±.ÔaÐcgÓhˆñ
 œj¨¯©Ô8RÔSØ9=×9QÑ9QÐRWÐYcÓ9dò DÑ5�	˜8Ð%5Ø×&Ò&Ø2:‘Oà&*§m¡m×&DÑ&D×&HÑ&HÈÓ&R�OØ&Ð.ð +/¯-©-×*HÑ*H×*LÑ*LÈXÏ^É^ÓM]Ó*^˜â"Ø"Ÿm™m×=Ñ=¸oÈ~Ó^�GØÑ*ô 5°T·[±[ÔAØ#*¨JÐ8HÐ#HÒHØ&¨	Ð3CÐCÒCð#Dð* ˜ UÐ*Ð*ä$™wÑ6°u¸jÓIÑˆˆS�*ô % T§[¡[Ô1°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˜   )r5   rŽ   rŒ   Úcurrent_staterU   r”   r,   rz   r2   r   ÚAttributeErrorr   )r8   r:   r˜   Ústate_project_idÚneed_credentialsÚneed_projectÚ_credsr5   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                  | 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.)r:   r;   r<   )r•   r¶   r5   r2   r   r0   r;   r<   rA   s    r'   Ú_load_env_varsz0GoogleSecretManagerSettingsSource._load_env_varsH  s}   € ð ×$Ò$ØˆIà×!Ñ!Ô#ð ×ÑÐ# t×':Ñ':Ð'BÜðJóð ô *Ø×ÑØ×'Ñ'Ø×.Ñ.Ø#×6Ñ6ô	
ð 	
r>   c                óX   •— d| _         | j                  «       | _        t        ‰| �  «       S )NT)r•   r¸   r¢   r–   Ú__call__)r8   rš   s    €r'   rº   z*GoogleSecretManagerSettingsSource.__call__]  s+   ø€ ð !%ˆÔØ×+Ñ+Ó-ˆŒÜ‰wÑÓ!Ð!r>   c                óœ   — | j                   �| j                   n| j                  }| j                  j                  › d|›d| j                  ›d�S )Nz(project_id=z, env_nested_delimiter=ú))r5   rŽ   rš   rƒ   Úenv_nested_delimiter)r8   r:   s     r'   Ú__repr__z*GoogleSecretManagerSettingsSource.__repr__d  sR   € ð *.×)9Ñ)9Ð)E�T×%Ò%È4×KdÑKdˆ
à�~‰~×&Ñ&Ð' |°J°>ÐAXÐY]×YrÑYrÐXuÐuvÐwð	
r>   )	NNNNNNTr:   N)r—   ztype[BaseSettings]r˜   r‹   r:   r|   r�   r|   r<   r|   r’   úbool | Noner9   r�   r;   r¿   r™   rz   r“   zInitState | Noner}   r~   )r¦   r	   r§   rz   r}   ztuple[Any, str, bool]©r}   r~   )r}   zMapping[str, str | None])r}   zdict[str, Any]r   )rƒ   r„   r…   r†   r=   r¥   r¶   r¸   rº   r¾   Ú__classcell__)rš   s   @r'   rŠ   rŠ   ¦   sÆ   ø… Ø$Ó$Ø5Ó5ØÓØ$Ó$ð
 +/Ø!%Ø!%Ø)-Ø'+Ø;?Ø&*Ø ,Ø(,ð;%à(ð;%ð (ð;%ð ð	;%ð
 ð;%ð 'ð;%ð %ð;%ð 9ð;%ð $ð;%ð ð;%ð &ð;%ð 
õ;%õz1$óf*\óX
õ*"÷
r>   rŠ   rÀ   )r-   rl   r}   r{   )'Ú
__future__r   Ú_annotationsr    Úcollections.abcr   r   Ú	functoolsr   Útypingr   r   Úpydantic.fieldsr	   Ú
exceptionsr   Útypesr   Úutilsr   r   r   Úenvr   r   r   r   r   r   r$   r   Úpydantic_settings.mainr   r(   r.   rz   r0   rŠ   Ú__all__rˆ   r>   r'   ú<module>rÎ      s‰   ðÝ 2ã ß -Ý %ß %å %å 'Ý !ß MÑ MÝ "áÝ:Ý3ÝEæ3à€KØ!%ÐØÐóó$ôm( ¨¨c°D©j¨Ñ!9ô m(ô`D
Ð(9ô D
ðN (Ð)LÐ
M�r>   