o
G%@i @ sV d dl Z d dlmZ d dlmZ d dlmZ d dlmZm Z m
Z
G dd dee ZdS ) N)Any)request)URLError)PluginIndependentPlugin PluginOptc @ s e Zd ZdZdZdZeddddgZdZd Z d
Z
dZdd
Zdd Z
dd ZdefddZdedefddZdd ZededefddZdS )GCPzGoogle Cloud Platformgcp)virtkeep-piiFzyStop the plugin from removing PIIs like project name or organization ID from the metadata retrieved from Metadata server.)defaultdescz(/sys/devices/virtual/dmi/id/product_namezBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]Nc C s> t | jdd}d| v W d S 1 sw Y dS )zo
Checks if this plugin should be executed based on the presence of
GCE entry in sysfs.
zutf-8)encodingzGoogle Compute EngineN)openPRODUCT_PATHread)selfsys_file 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:
* `gcloud auth list` output
* Any google services output from journal
zgcloud auth listr tagszgoogle*)unitsr N)add_cmd_outputadd_journalr r r r setup, s z GCP.setupc C s | j ddgdA}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_fileget_metadatametadatascrub_metadatawritejsondumpsRuntimeErrorstr)r mfileerrr r r collect9 s
"zGCP.collectreturnc C s | | j}t|S )zq
Retrieves metadata from the Metadata Server and transforms it into a
dictionary object.
)_query_addressMETADATA_QUERYr% loads)r
response_bodyr r r r! C s
zGCP.get_metadataurlc
C s z