File: //proc/1233/cwd/lib/python3/dist-packages/sos/report/plugins/__pycache__/gcp.cpython-310.pyc
o
i��d� � @ sb d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl m
Z
mZmZ G dd� de
e�Z
dS ) � N)�HTTPResponse)�Any)�request)�URLError)�Plugin�IndependentPlugin� PluginOptc @ s� e Zd ZdZdZdZedddd�gZdZd Z d
Z
dZdd
� Zdd� Z
dd� 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--]zDDMI: Google Google Compute Engine/Google Compute Engine, BIOS Googlec C s( | � d�}|d dkr
dS | j|d v S )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�statusr F�output)�exec_cmd�
GOOGLE_DMI)�selfr � r �8/usr/lib/python3/dist-packages/sos/report/plugins/gcp.py�
check_enabled( s
zGCP.check_enabledc C s$ | j ddgd� | 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*)�unitsr N)�add_cmd_output�add_journal�r r r r �setup3 s z GCP.setupc C s� | j ddgd��A}z| �� | _| �� |�tj| jdd�� W n ty8 } z
|�t|�� W Y d }~n
d }~ww W d � d S W d � d S 1 sLw Y d S )Nz
metadata.jsonr
r � )�indent) �collection_file�get_metadata�metadata�scrub_metadata�write�json�dumps�RuntimeError�str)r �mfile�errr r r �collectA s
����"�zGCP.collect�returnc C s"