HEX
Server: LiteSpeed
System: Linux node612.namehero.net 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: dfwparty (1186)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/sos/report/plugins/__pycache__/gcp.cpython-36.pyc
3

ܓ�i6�@sVddlZddlmZddlmZddlmZddlmZm	Z	m
Z
Gdd�dee	�ZdS)�N)�Any)�request)�URLError)�Plugin�IndependentPlugin�	PluginOptc@s�eZdZdZdZdZedddd�gZdZd	Z	d
Z
dZdd
�Zdd�Z
dd�Zed�dd�Zeed�dd�Zdd�Zeeed�dd��ZdS)�GCPzGoogle Cloud Platform�gcp�virtzkeep-piiFzyStop the plugin from removing PIIs like project name or organization ID from the metadata retrieved from Metadata server.)�defaultZdescz(/sys/devices/virtual/dmi/id/product_namezBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]NcCs@y&t|jdd��}d|j�kSQRXWntk
r:dSXdS)zo
        Checks if this plugin should be executed based on the presence of
        GCE entry in sysfs.
        zutf-8)�encodingzGoogle Compute EngineNF)�open�PRODUCT_PATH�read�OSError)�selfZsys_file�r�/usr/lib/python3.6/gcp.py�
check_enabled$s
zGCP.check_enabledcCs$|jddgd�|jddgd�dS)z�
        Collect the following info:
         * `gcloud auth list` output
         * Any google services output from journal
        zgcloud auth listr	)�tagszgoogle*)ZunitsrN)Zadd_cmd_outputZadd_journal)rrrr�setup/sz	GCP.setupcCs�|jddgd��d}y,|j�|_|j�|jtj|jdd��Wn0tk
rn}z|jt|��WYdd}~XnXWdQRXd}|j	j
jd�}|r�|j|�dS)Nz
metadata.jsonr	)r�)�indentzAcurl -v --connect-timeout 10https://rhui.googlecloud.com/zone.txtzgoogle-rhui-client)
Zcollection_file�get_metadata�metadata�scrub_metadata�write�json�dumps�RuntimeError�strZpolicyZpackage_managerZall_pkgs_by_name_regexZcollect_cmd_output)rZmfile�errZcurl_commandZrhui_packagerrr�collect<s
*zGCP.collect)�returncCs|j|j�}tj|�S)zq
        Retrieves metadata from the Metadata Server and transforms it into a
        dictionary object.
        )�_query_address�METADATA_QUERYr�loads)rZ
response_bodyrrrrOszGCP.get_metadata)�urlr#cCs�y\tj|ddid�}tj|��6}|jdkrHtd|j�d�|j�j���|j�j�SQRXWn4tk
r�}ztdt|��|�WYdd}~XnXdS)	zf
        Query the given url address with headers required by Google Metadata
        Server.
        zMetadata-FlavorZGoogle)Zheaders��z2Failed to communicate with Metadata Server (code: z): Nz,Failed to communicate with Metadata Server: )	rZRequestZurlopen�coderr�decoderr )rr'ZreqZresponser!rrrr$Ws
zGCP._query_addresscs��jd�rdS�jdd��jdd�t���ttd������fdd����j��_�j�jdd	d
��j�jdd	d�dS)a"
        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.
        zkeep-piiNZprojectZ	projectIdZnumericProjectId)�datar#cs�t|t�r2d|kr�j|d<�fdd�|j�D�St|t�rN�fdd�|D�St|t�rp|j��j�j��j�St|t�r�|�kr��jS|S|S)N�tokencsi|]\}}�|��|��qSrr)�.0�k�v)�scrubrr�
<dictcomp>�sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<dictcomp>csg|]}�|��qSrr)r-�value)r0rr�
<listcomp>�sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<listcomp>)�
isinstance�dict�REDACTED�items�listr �replace�int)r+)�
project_id�project_number�project_number_intr0rrrr0zs





z!GCP.scrub_metadata.<locals>.scrubZ
attributeszssh-keysZsshKeys)Z
get_optionrr r�safe_redact_key)rr)r;r<r=r0rrrjs	
zGCP.scrub_metadata)�dict_obj�keycCs||kr|j||<dS)z
 Redact keys N)r6)�clsr?r@rrrr>�szGCP.safe_redact_key)r
)�__name__�
__module__�__qualname__Z
short_descZplugin_nameZprofilesrZoption_listrr%r6rrrr"r5rr r$r�classmethodr>rrrrrs"

'r)rZtypingrZurllibrZurllib.errorrZsos.report.pluginsrrrrrrrr�<module>s