File: //lib/python3.6/site-packages/sos/report/plugins/__pycache__/gcp.cpython-36.opt-1.pyc
3
ܓ�i6 � @ sV d dl Z d dlmZ d dlmZ d dlmZ d dlmZm Z m
Z
G dd� dee �ZdS )� N)�Any)�request)�URLError)�Plugin�IndependentPlugin� PluginOptc @ s� e Zd ZdZdZdZedddd�gZdZd Z d
Z
dZdd
� Zdd� Z
dd� Zed�dd�Zeed�dd�Zdd� Zeeed�dd��ZdS )�GCPzGoogle Cloud Platform�gcp�virtzkeep-piiFzyStop the plugin from removing PIIs like project name or organization ID from the metadata retrieved from Metadata server.)�defaultZdescz(/sys/devices/virtual/dmi/id/product_namezBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]Nc C s@ y&t | jdd��}d|j� kS Q R X W n tk
r: dS X dS )zo
Checks if this plugin should be executed based on the presence of
GCE entry in sysfs.
zutf-8)�encodingzGoogle Compute EngineNF)�open�PRODUCT_PATH�read�OSError)�selfZsys_file� r �/usr/lib/python3.6/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*)Zunitsr N)Zadd_cmd_outputZadd_journal)r r r r �setup/ s z GCP.setupc C s� | j ddgd��d}y,| j� | _| j� |jtj| jdd�� W n0 tk
rn } z|jt|�� W Y d d }~X nX W d Q R X d}| j j
jd�}|r�| j|� d S )Nz
metadata.jsonr )r � )�indentzAcurl -v --connect-timeout 10https://rhui.googlecloud.com/zone.txtzgoogle-rhui-client)
Zcollection_file�get_metadata�metadata�scrub_metadata�write�json�dumps�RuntimeError�strZpolicyZpackage_managerZall_pkgs_by_name_regexZcollect_cmd_output)r Zmfile�errZcurl_commandZrhui_packager r r �collect<