
    ghd                     n   S SK r S SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  \	(       a  S SKJ
r
  SrSrS	rS
R                  \5      rSR                  \5      rSrSR                  \5      r " S S5      r " S S5      r " S S\5      r\R,                  \R.                  \R0                  \R2                  0rg)    N)Integration)set_context)logger)TYPE_CHECKING)Dictcloud_resourceg       @z169.254.169.254zhttp://{}/latest/api/tokenz3http://{}/latest/dynamic/instance-identity/documentzmetadata.google.internalz,http://{}/computeMetadata/v1/?recursive=truec                   0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)CLOUD_PROVIDER   z|
Name of the cloud provider.
see https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/cloud/
alibaba_cloudawsazuregcp	ibm_cloudtencent_cloud N)__name__
__module____qualname____firstlineno____doc__ALIBABAAWSAZUREGCPIBMTENCENT__static_attributes__r       q/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/integrations/cloud_resource_context.pyr
   r
      s'    
 G
CE
C
CGr   r
   c                        \ rS rSrSrSrSrSrg)CLOUD_PLATFORM,   zt
The cloud platform.
see https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/cloud/
aws_ec2gcp_compute_enginer   N)r   r   r   r   r   AWS_EC2GCP_COMPUTE_ENGINEr   r   r   r    r"   r"   ,   s    
 G-r   r"   c                       \ rS rSrSrSrSrSr\R                  " \
S9rSrSS jr\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)CloudResourceContextIntegration6   z0
Adds cloud resource context to the Senty scope
cloudresourcecontext )timeoutNc                     U[         l        g )N)r)   cloud_provider)selfr/   s     r    __init__(CloudResourceContextIntegration.__init__D   s    9G'6r   c                     U R                   R                  S[        SS0S9nUR                  S:w  a  gUR                  R                  5       U l        g! [        R                  R                   a    [        R                  " S[        5         g[         a*  n[        R                  " S	[        U5      5         S nAgS nAff = f)
NPUTz$X-aws-ec2-metadata-token-ttl-seconds60headers   FT/AWS metadata service timed out after %s secondsz'Error checking AWS metadata service: %s)httprequestAWS_TOKEN_URLstatusdatadecode	aws_tokenurllib3
exceptionsTimeoutErrorr   debugHTTP_TIMEOUT	Exceptionstrclsres      r    _is_aws'CloudResourceContextIntegration._is_awsH   s    	  ?F ! A xx3FFMMOCM!!.. 	LLA<  	LLBCFK	s"   1A A 9C	C B==Cc                    [         R                  [        R                  S.n U R                  R                  S[        SU R                  0S9nUR                  S:w  a  U$ [        R                  " UR                  R                  S5      5      n US   US'    US	   US
'    US   US'    US   US'    US   US'   U$ ! [         a     N2f = f! [         a     N9f = f! [         a     N@f = f! [         a     NGf = f! [         a     U$ f = f! [        R                  R                    a    ["        R$                  " S[&        5         U$ [         a+  n["        R$                  " S[)        U5      5         S nAU$ S nAff = f)Nzcloud.providerzcloud.platformGETzX-aws-ec2-metadata-tokenr6   r8   utf-8	accountIdcloud.account.idavailabilityZonecloud.availability_zoneregioncloud.region
instanceIdhost.idinstanceTypez	host.typer9   zError fetching AWS metadata: %s)r
   r   r"   r&   r:   r;   AWS_METADATA_URLr@   r=   jsonloadsr>   r?   rF   rA   rB   rC   r   rD   rE   rG   )rI   ctxrJ   r>   rK   s        r    _get_aws_context0CloudResourceContextIntegration._get_aws_contexta   s    -00,44

*	D   3S]]C ! A xx3
::affmmG45D*.{*;&'156H1I-.&*8nN#!%l!3I#'#7K  
=  
  
  
  
   
 !!.. 	LLA< 
  	DLL:CFCC
	Ds   <D  /D B> C "C +C. 4C> >
CD 
CD 
CD CD 
C+(D *C++D .
C;8D :C;;D >
DD DD 9E?	E? E::E?c                     U R                   R                  S[        SS0S9nUR                  S:w  a  g[        R
                  " UR                  R                  S5      5      U l        g! [        R                  R                   a    [        R                  " S	[        5         g[         a*  n[        R                  " S
[!        U5      5         S nAgS nAff = f)NrP   Metadata-FlavorGoogler6   r8   FrQ   T/GCP metadata service timed out after %s secondsz'Error checking GCP metadata service: %s)r:   r;   GCP_METADATA_URLr=   r\   r]   r>   r?   gcp_metadatarA   rB   rC   r   rD   rE   rF   rG   rH   s      r    _is_gcp'CloudResourceContextIntegration._is_gcp   s    	   *H5 ! A xx3#zz!&&--*@AC!!.. 	LLA<  	LLBCFK	s"   1A) 4A) )9C$	C- CCc                    [         R                  [        R                  S.n U R                  cg  U R
                  R                  S[        SS0S9nUR                  S:w  a  U$ [        R                  " UR                  R                  S5      5      U l         U R                  S   S	   US
'    U R                  S   S   R                  S5      S   US'    U R                  S   S   R                  S5      S   US'    U R                  S   S   US'   U$ ! [         a     Ntf = f! [         a     N\f = f! [         a     NDf = f! [         a     U$ f = f! [        R                   R"                   a    [$        R&                  " S[(        5         U$ [         a+  n[$        R&                  " S[+        U5      5         S nAU$ S nAff = f)NrO   rP   rb   rc   r6   r8   rQ   project	projectIdrS   instancezone/rU   rV   rW   idrY   rd   zError fetching GCP metadata: %s)r
   r   r"   r'   rf   r:   r;   re   r=   r\   r]   r>   r?   rF   splitrA   rB   rC   r   rD   rE   rG   )rI   r^   rJ   rK   s       r    _get_gcp_context0CloudResourceContextIntegration._get_gcp_context   s    -00,??

+	D'HH$$$.9 %  88s?J#'::affmmG.D#E *-*:*:9*Ek*R&'141A1A*1M2%*R2!-.&)&6&6z&B8&L&R&RSV&W'N#!$!1!1*!=d!CI 
=      
   
 !!.. 	LLA< 
  	DLL:CFCC
	Ds   ?E #4E D .'D% 'D5 >E 
D"E !D""E %
D2/E 1D22E 5
E?E EE 
EE EE 9G	G GGc                     U R                  5       (       a  [        R                  $ U R                  5       (       a  [        R                  $ gNr,   )rL   r
   r   rg   r   )rI   s    r    _get_cloud_provider3CloudResourceContextIntegration._get_cloud_provider   s5     ;;==!%%%;;==!%%%r   c                     U R                   S:w  a  U R                   O[        R                  5       nU[        R	                  5       ;   a  [        U   " 5       $ 0 $ ru   )r/   r)   rv   context_getterskeys)rI   r/   s     r    _get_cloud_resource_context;CloudResourceContextIntegration._get_cloud_resource_context   sT    
 !!R' 0DDF 	
 _1133">244	r   c                  P   [         R                  n U S:g  =(       a    U [        R                  5       ;  nU(       aA  [        R
                  " S[         R                  [        [        R                  5       5      5        [         R                  5       nU0 :w  a  [        [        U5        g g )Nr,   zVInvalid value for cloud_provider: %s (must be in %s). Falling back to autodetection...)
r)   r/   ry   rz   r   warninglistr{   r   CONTEXT_TYPE)r/   unsupported_cloud_providercontexts      r    
setup_once*CloudResourceContextIntegration.setup_once   s     9GGb Q^?;O;O;Q%Q 	# &NNh/>>_))+, 2MMOb=g. r   r   )r,   )r   r   r   r   r   
identifierr/   r@   rA   PoolManagerrE   r:   rf   r1   classmethodrL   r_   rg   rr   rv   r{   staticmethodr   r   r   r   r    r)   r)   6   s     (JNI|4DLH  0 3 3j  0 4 4l   
 
 / /r   r)   )r\   rA   sentry_sdk.integrationsr   sentry_sdk.apir   sentry_sdk.utilsr   typingr   r   r   rE   AWS_METADATA_HOSTformatr<   r[   GCP_METADATA_HOSTre   r
   r"   r)   r   r_   r   rr   ry   r   r   r    <module>r      s      / & #    % ,334EFHOO  / AHH 
 . .Z/k Z/@ 7HH7HHr   