+
    G%@i                     ^    ^ 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# )    NAny)request)URLError)PluginIndependentPlugin	PluginOptc                      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.)defaultdescz(/sys/devices/virtual/dmi/id/product_namezBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]Nc                    \        V P                  RR7      ;_uu_ 4       pRVP                  4       9   uuRRR4       #   + '       g   i     R# ; i)zW
Checks if this plugin should be executed based on the presence of
GCE entry in sysfs.
zutf-8)encodingzGoogle Compute EngineN)openPRODUCT_PATHread)selfsys_files   & 8/usr/lib/python3/dist-packages/sos/report/plugins/gcp.pycheck_enabledGCP.check_enabled$   s6    
 $##g66(*hmmo= 7666s	   >A	c                V    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*)unitsr   N)add_cmd_outputadd_journal)r   s   &r   setup	GCP.setup,   s1     	.eW= 	yw7    c           	        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#   \         d%   pTP	                  \        T4      4        Rp?L4Rp?ii ; i  + '       g   i     R# ; i)zmetadata.jsonr   r   )indentN)	collection_fileget_metadatametadatascrub_metadatawritejsondumpsRuntimeErrorstr)r   mfileerrs   &  r   collectGCP.collect9   s    !!/!@@E& $ 1 1 3##%DJJt}}Q?@	 A@
   &CH%%& A@@s/   B1AA??B.
B)$B1)B..B11C	c                    < V ^8  d   QhRS[ /# )   return)dict)format__classdict__s   "r   __annotate__GCP.__annotate__C   s     ) )d )r"   c                d    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*   loads)r   response_bodys   & r   r&   GCP.get_metadataC   s)    
 ++D,?,?@zz-((r"   c                &   < V ^8  d   QhRS[ RS[ /# )r3   urlr4   )r-   )r6   r7   s   "r   r8   r9   K   s      # # r"   c                    \         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-FlavorGoogle)headersz2Failed to communicate with Metadata Server (code: z): Nz,Failed to communicate with Metadata Server: )	r   Requesturlopencoder,   r   decoder   r-   )r   rA   reqresponser/   s   &&   r   r;   GCP._query_addressK   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                  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   Nproject	projectIdnumericProjectIdc                0    V ^8  d   QhR\         R\         /# )r3   datar4   r   )r6   s   "r   r8   (GCP.scrub_metadata.<locals>.__annotate__n   s     	 	 	 	r"   c                 "  < \        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 )token)
isinstancer5   REDACTEDitemslistr-   replaceint)	rQ   kvvalue
project_idproject_numberproject_number_intscrubr   s	   &   r   ra   !GCP.scrub_metadata.<locals>.scrubn   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
attributeszssh-keyssshKeys)
get_optionr'   r-   safe_redact_key)r   r^   r_   r`   ra   s   f@@@@r   r(   GCP.scrub_metadata^   s     ??:&&]]9-k:
!]]956HI/0	 	  dmm,T]]95lC'	)T]]95lC&	(r"   c                &   < V ^8  d   QhRS[ RS[/# )r3   dict_objkey)r5   r-   )r6   r7   s   "r   r8   r9      s     ) )t )# )r"   c                2    W!9   d   V P                   W&   R# R# )zRedact keys N)rV   )clsri   rj   s   &&&r   rf   GCP.safe_redact_key   s     ?LLHM r"   )r'   )virt)__name__
__module____qualname____firstlineno__
short_descplugin_nameprofilesr	   option_listr   r<   rV   r'   r   r    r0   r&   r;   r(   classmethodrf   __static_attributes____classdictcell__)r7   s   @r   r   r      s     (JKH 	*e*	+K >L'NHH>8&) ) &%(N ) )r"   r   )r*   typingr   urllibr   urllib.errorr   sos.report.pluginsr   r   r	   r    r"   r   <module>r      s*       ! C Cy)&# y)r"   