+
    i6  c                   s^    ^ RI t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
  ! R R]]	4      tR# )i    NAny)request)URLError)PluginIndependentPlugin	PluginOptc                   s   a  ] tR t^t o RtRtRt]! RRRR7      .tRt	Rt
R	tR
tR tR tR tV 3R lR ltV 3R lR ltR t]V 3R lR l4       tRtV tR
# )GCPzGoogle Cloud Platformgcpkeep-piiFzyStop the plugin from removing PIIs like project name or organization ID from the metadata retrieved from Metadata server.)ZdefaultZdescz(/sys/devices/virtual/dmi/id/product_namezBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]Nc                s     \        V P                  RR7      ;_uu_ 4       pRVP                  4       9   uuRRR4       #   + '       g   i     R# ; i  \         d     R# i ; i)zW
Checks if this plugin should be executed based on the presence of
GCE entry in sysfs.
zutf-8)ZencodingzGoogle Compute EngineNF)ZopenPRODUCT_PATHreadZOSError)selfZsys_file   & ;/usr/lib/python3.14/site-packages/sos/report/plugins/gcp.pycheck_enabledZGCP.check_enabled$   sJ    
	d'''::h.(--/A ;::: 		s+   A ?
A A	
A A A"!A"c                sV    V P                  RR.R7       V P                  RR.R7       R# )ze
Collect the following info:
 * `gcloud auth list` output
 * Any google services output from journal
zgcloud auth listr   tagszgoogle*)Zunitsr   N)Zadd_cmd_outputZadd_journal)r   s   &r   setupZ	GCP.setup/   s1     	.eW= 	yw7    c           	     s   V P                  R R.R7      ;_uu_ 4       p V P                  4       V n        V P                  4        VP	                  \
        P                  ! V P                  ^R7      4       RRR4       RpV P                  P                  P                  R4      pV'       d   V P                  V4       R# R#   \         d%   pTP	                  \        T4      4        Rp?LvRp?ii ; i  + '       g   i     L; i)zmetadata.jsonr   r   )ZindentNzAcurl -v --connect-timeout 10https://rhui.googlecloud.com/zone.txtzgoogle-rhui-client)Zcollection_fileget_metadatametadatascrub_metadataZwritejsonZdumpsRuntimeErrorstrZpolicyZpackage_managerZall_pkgs_by_name_regexZcollect_cmd_output)r   ZmfileerrZcurl_commandZrhui_packages   &    r   collectZGCP.collect<   s    !!/!@@E& $ 1 1 3##%DJJt}}Q?@	 A@ {{22II!###L1    &CH%%& A@s/   C3ACC0C+&C3+C00C33D	c                s    < V ^8  d   QhRS[ /# )   return)dictformat__classdict__   "r   __annotate__GCP.__annotate__O   s     ) )d )r   c                sd    V P                  V P                  4      p\        P                  ! V4      # )zY
Retrieves metadata from the Metadata Server and transforms it into a
dictionary object.
)_query_addressMETADATA_QUERYr   Zloads)r   Zresponse_bodyr   r   r   ZGCP.get_metadataO   s)    
 ++D,?,?@zz-((r   c                s&   < V ^8  d   QhRS[ RS[ /# )r   urlr   )r   r   r"   r   r#   r$   W   s      # # r   c                s    \         P                  ! VRR/R7      p\         P                  ! V4      ;_uu_ 4       pVP                  ^8w  d=   \	        RVP                   R2VP                  4       P                  4       ,           4      hVP                  4       P                  4       uuRRR4       #   + '       g   i     R# ; i  \         d"   p\	        R\        T4      ,           4      ThRp?ii ; i)zN
Query the given url address with headers required by Google Metadata
Server.
zMetadata-FlavorZGoogle)Zheadersz2Failed to communicate with Metadata Server (code: z): Nz,Failed to communicate with Metadata Server: )	r   ZRequestZurlopenZcoder   r   Zdecoder   r   )r   r'   ZreqZresponser   s   &&   r   r%   ZGCP._query_addressW   s    
	//#0A8/LMC%%==C'&""*--5 ..012 2  }}--/ &%%%  	>SIK	s5   8C A+B0%
C 0C	;C C C0C++C0c                s  a aaaa S P                  R4      '       d   R# S P                  R,          R,          oS P                  R,          R,          o\        S4      oR VVVVV 3R lloS! S P                  4      S n        S P                  S P                  R,          R,          R	4       S P                  S P                  R,          R,          R
4       R# )z
Remove all PII information from metadata, unless a keep-pii option
is specified.

Note: PII information collected by this plugin, like
project number, account names etc. might be required by Google
Cloud Support for faster issue resolution.
r	   NZprojectZ	projectIdZnumericProjectIdc                s0    V ^8  d   QhR\         R\         /# )r   datar   r    )r    s   "r   r#   Z(GCP.scrub_metadata.<locals>.__annotate__z   s     	 	 	 	r   c                 s"  < \        V \        4      '       dH   R V 9   d   SP                  V R &   V P                  4        UUu/ uF  w  rS! V4      S! V4      bK  	  upp# \        V \        4      '       d   V  Uu. uF  pS! V4      NK  	  up# \        V \
        4      '       d7   V P                  SSP                  4      P                  SSP                  4      # \        V \        4      '       d   V S8X  d   SP                  # T # V # u uppi u upi )Ztoken)Z
isinstancer   REDACTEDZitemsZlistr   ZreplaceZint)	r(   ZkZvZvalue
project_idproject_numberproject_number_intscrubr   s	   &   r   r-   Z!GCP.scrub_metadata.<locals>.scrubz   s    $%%d? %)MMDM7;zz|D|tqa%(*|DD$%%267$e$77$$$||NDMMB#GJ>?$$$(,0B(Bt}}LLK E7s   D9DZ
attributeszssh-keysZsshKeys)Z
get_optionr   r   safe_redact_key)r   r*   r+   r,   r-   s   f@@@@r   r   ZGCP.scrub_metadataj   s     ??:&&]]9-k:
!]]956HI/0	 	  dmm,T]]95lC'	)T]]95lC&	(r   c                s&   < V ^8  d   QhRS[ RS[/# )r   dict_objkey)r   r   r   r"   r   r#   r$      s     ) )t )# )r   c                s2    W!9   d   V P                   W&   R# R# )zRedact keys N)r)   )Zclsr/   r0   s   &&&r   r.   ZGCP.safe_redact_key   s     ?LLHM r   )r   )Zvirt)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z
short_descZplugin_nameZprofilesr   Zoption_listr
   r&   r)   r   r   r   r   r   r%   r   Zclassmethodr.   Z__static_attributes__Z__classdictcell__)r!   s   @r   r   r      s     (JKH 	*e*	+K >L'NHH	82&) ) &%(N ) )r   r   )r   Ztypingr   Zurllibr   Zurllib.errorr   Zsos.report.pluginsr   r   r   r   ) r   r   <module>r1      s*       ! C CE)&# E)r   