HEX
Server: Apache
System: Linux dinesh8189 5.15.98-grsec-sharedvalley-2.lc.el8.x86_64 #1 SMP Thu Mar 9 09:07:30 -03 2023 x86_64
User: cgmgerenciamento1 (814285)
PHP: 8.1.26
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //usr/lib/python3.6/site-packages/sos/report/plugins/__pycache__/gcp.cpython-36.pyc
3

3��d��@sbddlZddlmZddlmZddlmZddlmZddl	m
Z
mZmZGdd�de
e�Z
dS)	�N)�HTTPResponse)�Any)�request)�URLError)�Plugin�IndependentPlugin�	PluginOptc@s�eZdZdZdZdZedddd�gZdZd	Z	d
Z
dZdd
�Zdd�Z
dd�Zed�dd�Zeeed�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.)�defaultZdescz3http://metadata.google.internal/computeMetadata/v1/zBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]zDDMI: Google Google Compute Engine/Google Compute Engine, BIOS GooglecCs(|jd�}|ddkrdS|j|dkS)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.
        �dmesgZstatusrF�output)Zexec_cmd�
GOOGLE_DMI)�selfr
�r�/usr/lib/python3.6/gcp.py�
check_enabled(s
zGCP.check_enabledcCs$|jddgd�|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*)ZunitsrN)Zadd_cmd_outputZadd_journal)rrrr�setup3s	z	GCP.setupcCs~|jddgd��d}y,|j�|_|j�|jtj|jdd��Wn0tk
rn}z|jt|��WYdd}~XnXWdQRXdS)Nz
metadata.jsonr
)r�)�indent)	Zcollection_file�get_metadata�metadata�scrub_metadata�write�json�dumps�RuntimeError�str)rZmfile�errrrr�collectAs
zGCP.collect)�returncCs"|j|j�}|j�j�}tj|�S)zq
        Retrieves metadata from the Metadata Server and transforms it into a
        dictionary object.
        )�_query_address�METADATA_QUERY�read�decoder�loads)r�responseZ
response_bodyrrrrKszGCP.get_metadata)�urlr"cCs�y tj|ddid�}tj|�}Wn2tk
rR}ztdt|���WYdd}~XnX|jdkr|td|j�d�|j�j���|S)	zf
        Query the given url address with headers required by Google Metadata
        Server.
        zMetadata-FlavorZGoogle)Zheadersz,Failed to communicate with Metadata Server: N��z2Failed to communicate with Metadata Server (code: z): )	rZRequestZurlopenrrr�coder%r&)r)Zreqr(r rrrr#Ts 
zGCP._query_addresscs��jd�rdS�jdd��jdd�t���ttd������fdd����j��_�j�jdd	d
��j�jdd	d�dS)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.
        zkeep-piiNZprojectZ	projectIdZnumericProjectId)�datar"cs�t|t�r2d|kr�j|d<�fdd�|j�D�St|t�rN�fdd�|D�St|t�rp|j��j�j��j�St|t�r�|�kr��jS|S|S)N�tokencsi|]\}}�|��|��qSrr)�.0�k�v)�scrubrr�
<dictcomp>|sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<dictcomp>csg|]}�|��qSrr)r.�value)r1rr�
<listcomp>~sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<listcomp>)�
isinstance�dict�REDACTED�items�listr�replace�int)r,)�
project_id�project_number�project_number_intr1rrrr1vs





z!GCP.scrub_metadata.<locals>.scrubZ
attributeszssh-keysZsshKeys)Z
get_optionrrr�safe_redact_key)rr)r<r=r>r1rrrfs	
zGCP.scrub_metadata)�dict_obj�keycCs||kr|j||<dS)N)r7)�clsr@rArrrr?�szGCP.safe_redact_keyN)r)�__name__�
__module__�__qualname__Z
short_descZplugin_nameZprofilesrZoption_listZ
METADATA_ROOTr$r7rrrr!r6r�staticmethodrrr#r�classmethodr?rrrrr	s$

	'r	)rZhttp.clientrZtypingrZurllibrZurllib.errorrZsos.report.pluginsrrrr	rrrr�<module>s