%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/sos/report/plugins/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/sos/report/plugins/__pycache__/gcp.cpython-312.pyc

�

i��d���h�ddlZddlmZddlmZddlmZddlmZddl	m
Z
mZmZGd�de
e�Z
y)	�N)�HTTPResponse)�Any)�request)�URLError)�Plugin�IndependentPlugin�	PluginOptc��eZdZdZdZdZeddd��gZdZd	Z	d
Z
dZd�Zd
�Z
d�Zdefd�Zededefd��Zd�Zededefd��Zy)�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--]zDDMI: Google Google Compute Engine/Google Compute Engine, BIOS Googlec�X�|jd�}|ddk7ry|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)�selfrs  �8/usr/lib/python3/dist-packages/sos/report/plugins/gcp.py�
check_enabledzGCP.check_enabled(s4���
�
�g�&����?�a������%��/�1�1�c�T�|jddg��|jddg��y)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)rs r�setupz	GCP.setup3s1��	
���.�e�W��=�	
���y��w��7rc�b�|jddg��5}	|j�|_|j�|j	tj|jd���ddd�y#t$r$}|j	t|��Yd}~�1d}~wwxYw#1swYyxYw)Nz
metadata.jsonrr�)�indent)	�collection_file�get_metadata�metadata�scrub_metadata�write�json�dumps�RuntimeError�str)r�mfile�errs   r�collectzGCP.collectAs���
�
!�
!�/���
!�
@�	&�E�
&� $� 1� 1� 3��
��#�#�%����D�J�J�t�}�}�Q�?�@�		&�	&��
 �
&����C��H�%�%��
&��	&�	&�s/�B%�AA5�5	B"�>B�B%�B"�"B%�%B.�returnc��|j|j�}|j�j�}t	j
|�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_bodys   rr&zGCP.get_metadataKs=��
�&�&�t�':�':�;�� �
�
��.�.�0�
��z�z�-�(�(r�urlc�B�	tj|ddi��}tj|�}|jdk7r8t	d|j�d�|j�j�z��|S#t$r}t	dt|�z��d}~wwxYw)	zf
        Query the given url address with headers required by Google Metadata
        Server.
        zMetadata-Flavor�Google)�headersz,Failed to communicate with Metadata Server: N��z2Failed to communicate with Metadata Server (code: z): )	r�Request�urlopenrr,r-�coder5r6)r:�reqr8r/s    rr3zGCP._query_addressTs���	K��/�/�#�0A�8�/L�M�C����s�+�H��=�=�C����"�-�-���-�/7�}�}��/E�/E�/G�H�I�
I�����	K��>��S��I�K�
K��	K�s�.A9�9	B�B�Bc�r�������jd�ry�jdd��jdd�t���dtdtf�����fd����j��_�j	�jdd	d
��j	�jdd	d�y)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.
        rN�project�	projectId�numericProjectId�datar1c����t|t�rCd|vr�j|d<|j�D��cic]\}}�|��|���c}}St|t�r|D�cgc]
}�|���c}St|t
�r6|j
��j�j
��j�St|t�r|�k(r�jS|S|Scc}}wcc}w)N�token)�
isinstance�dict�REDACTED�items�listr-�replace�int)	rG�k�v�value�
project_id�project_number�project_number_int�scrubrs	    �����rrWz!GCP.scrub_metadata.<locals>.scrubvs�����$��%��d�?�%)�M�M�D��M�7;�z�z�|�D�t�q�!��a��%��(�*�D�D��D�$�'�26�7���e��7�7��D�#�&��|�|�N�D�M�M�B�#�G�J��
�
�>�?��D�#�&�(,�0B�(B�t�}�}�L��L��K��E��7s�C&�)C,�
attributeszssh-keys�sshKeys)�
get_optionr'r-r�safe_redact_key)rrTrUrVrWs`@@@@rr(zGCP.scrub_metadatafs�����?�?�:�&���]�]�9�-�k�:�
�!�]�]�9�5�6H�I���/�0��	��	��	�	� �d�m�m�,��
����T�]�]�9�5�l�C�'�	)����T�]�]�9�5�l�C�&�	(r�dict_obj�keyc�,�||vr|j||<yy)N)rL)�clsr\r]s   rr[zGCP.safe_redact_key�s���(�?��L�L�H�S�M�rN)�__name__�
__module__�__qualname__�
short_desc�plugin_name�profilesr	�option_list�
METADATA_ROOTr4rLrrr!r0rKr&�staticmethodr-rr3r(�classmethodr[�rrrrs���(�J��K��H�	�*�e�*�	+��K�J�M�'�N��H�/�J�	2�8�&�)�d�)���C��L����"%(�N�)�t�)�#�)��)rr)r*�http.clientr�typingr�urllibr�urllib.errorr�sos.report.pluginsrrr	rrjrr�<module>rps-���$���!�C�C�)�&�#�)r

Zerion Mini Shell 1.0