📂 FileMgr
📍
/
usr
/
lib
/
python3
/
dist-packages
/
sos
/
report
/
plugins
/
__pycache__
✏️ /usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/gcp.cpython-312.pyc
✕ Tutup
� G%@i� � �\ � d dl Z d dlmZ d dlmZ d dlmZ d dlmZm Z m Z G d� dee � Zy)� N)�Any)�request)�URLError)�Plugin�IndependentPlugin� PluginOptc � � e Zd ZdZdZdZ eddd�� gZdZd Z d Z dZd� Zd � Z d� Zdefd�Zdedefd�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�descz(/sys/devices/virtual/dmi/id/product_namezBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]Nc � � t | j d�� 5 }d|j � v cddd� S # 1 sw Y yxY w)zo Checks if this plugin should be executed based on the presence of GCE entry in sysfs. zutf-8)�encodingzGoogle Compute EngineN)�open�PRODUCT_PATH�read)�self�sys_files �8/usr/lib/python3/dist-packages/sos/report/plugins/gcp.py� check_enabledzGCP.check_enabled$ s9 � � �$�#�#�g� 6� >�(�*�h�m�m�o�=� >� >� >�s �4�=c �T � | j ddg�� | j ddg�� y)z� Collect the following info: * `gcloud auth list` output * Any google services output from journal zgcloud auth listr ��tagszgoogle*)�unitsr N)�add_cmd_output�add_journal)r s r �setupz GCP.setup, s1 � � ���.�e�W��=� ���y��w��7� c �b � | j ddg�� 5 } | j � | _ | j � |j t j | j d�� � d d d � y # t $ r$}|j t |� � Y d }~�1d }~ww xY w# 1 sw Y y xY w)Nz metadata.jsonr r � )�indent) �collection_file�get_metadata�metadata�scrub_metadata�write�json�dumps�RuntimeError�str)r �mfile�errs r �collectzGCP.collect9 s� � � � !� !�/��� !� @� &�E� &� $� 1� 1� 3�� ��#�#�%����D�J�J�t�}�}�Q�?�@� &� &�� � &����C��H�%�%�� &�� &� &�s/ �B%�AA5�5 B"�>B�B%�B"�"B%�%B.�returnc �b � | j | j � }t j |� S )zq Retrieves metadata from the Metadata Server and transforms it into a dictionary object. )�_query_address�METADATA_QUERYr) �loads)r � response_bodys r r% zGCP.get_metadataC s) � � �+�+�D�,?�,?�@� ��z�z�-�(�(r �urlc � � t j |ddi�� }t j |� 5 }|j dk7 r8t d|j � d�|j � j � z � �|j � j � cddd� S # 1 sw Y yxY w# t $ r}t dt |� z � |�d}~ww xY w) 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+ r �decoder r, )r r6 �req�responser. s r r2 zGCP._query_addressK s� � � ��/�/�#�0A�8�/L�M�C�����%� 0���=�=�C�'�&�"�"*�-�-���5� � � ��.�.�0�1�2� 2� �}�}��-�-�/� 0� 0� 0�� � ��>��S��I�K�� �� �s5 �.B+ �A%B� B+ �B(�$B+ �(B+ �+ C�4C�Cc �r � ����� � j d� ry� j d d �� j d d �t �� �dt dt f����� fd�� �� j � � _ � j � j d d d � � j � j d d 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. r N�project� projectId�numericProjectId�datar0 c �� �� t | t � rCd| v r�j | d<