Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/sos/policies/distros/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/sos/policies/distros/__pycache__/__init__.cpython-36.pyc

3

�fl��@sddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZddlmZmZmZmZyddlZdZWnek
r�d
ZYnXyddlZdZWnek
r�d
ZYnXdZdZGdd�de�Z Gdd�de �Z!dS)�N)�getpass)�_sos)�Policy)�
InitSystem)�SystemdInit)�CrioContainerRuntime)�PodmanContainerRuntime)�DockerContainerRuntime)�LxdContainerRuntime)�	shell_out�
is_executable�bold�sos_get_command_outputTFZ	containerZHOSTcs@eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdZd	ZdZdZdZdZdZdZdZdZdZdZd
ZdZdZ dZ!dZ"dZ#dZ$dZ%dn�fdd�	Z&e'dd��Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-dd�Z.e'dd��Z/e'd d!��Z0e'd"d#��Z1d$d%�Z2d&d'�Z3d(d)�Z4d*d+�Z5d,d-�Z6d.d/�Z7d0d1�Z8d2d3�Z9d4d5�Z:d6d7�Z;d8d9�Z<d:d;�Z=d<d=�Z>dod>d?�Z?d@dA�Z@dBdC�ZAdDdE�ZBdFdG�ZCdHdI�ZDdJdK�ZEdLdM�ZFdNdO�ZGdPdQ�ZHdRdS�ZIdpdTdU�ZJdVdW�ZKdqdXdY�ZLdZd[�ZMdrd\d]�ZNd^d_�ZOdsd`da�ZPdtdbdc�ZQddde�ZRdfdg�ZSdudhdi�ZTdjdk�ZUdldm�ZV�ZWS)v�LinuxPolicyzfThis policy is meant to be an abc class that provides common
    implementations used in Linux distrosZLinux�Nonez/bin:/sbin:/usr/bin:/usr/sbinN�/zhttps://s3.amazonaws.com��dockerFz/usr/binzsos-collector-tmpTcs,tt|�j|||d�|r"||_n|j�p,d|_|j�|dk	rH||_n$tjj	d�rdt
|jd�|_nt�|_i|_|j
�r(t|d�t|d�t|d�t|d�g}xN|D]F}|j�r�||j|j<|j|jkr�|j|j|jd<|j|jj�q�W|j�r(d|jj�k�r(t|jj��}|j|d|jd<dS)N)�sysroot�
probe_runtime�remote_execrz/run/systemd/system/)�chroot)Zpolicy�defaultr)�superr�__init__r�_container_init�init_kernel_modulesZinit_system�os�path�isdirrrZruntimesrrr	rr
Zcheck_is_active�name�default_container_runtimeZload_container_info�keys�list)�selfr�initrrZ_crunZruntime�idx)�	__class__��/usr/lib/python3.6/__init__.pyr\s6
zLinuxPolicy.__init__cCsddgS)Nz/etc/passwdz/etc/shadowr()�clsr(r(r)�set_forbidden_paths�szLinuxPolicy.set_forbidden_pathscCs|jS)N)�release)r$r(r(r)�kernel_version�szLinuxPolicy.kernel_versioncCs|jS)N)Zhostname)r$r(r(r)�	host_name�szLinuxPolicy.host_namecCs|jS)N)Zsmp)r$r(r(r)�
is_kernel_smp�szLinuxPolicy.is_kernel_smpcCs|jS)N)�machine)r$r(r(r)�get_arch�szLinuxPolicy.get_archcCs|j�S)z)Returns the name usd in the pre_work step)r.)r$r(r(r)�get_local_name�szLinuxPolicy.get_local_namecCstjdd|�S)Nz[^-a-z,A-Z.0-9]r)�re�sub)r$r r(r(r)�sanitize_filename�szLinuxPolicy.sanitize_filenamecCs2|tkr|j|�n|jd|j�|j|�dS)Nz%s Distribution Policy)r�display_self_help�	set_title�distro�display_distro_help)r*�sectionr(r(r)�display_help�szLinuxPolicy.display_helpcCs|jd�|jd�dS)NzSoS Distribution Policiesz�Distributions supported by SoS will each have a specific policy defined for them, to ensure proper operation of SoS on those systems.)r7�add_text)r*r:r(r(r)r6�s
zLinuxPolicy.display_self_helpc	Cs:|jr |jtjk	r |j|j�n
|jd�|ddd�}|jd|j�|jd|jdd�|jd|jdd�|jd�}x6|jD],}|jdd	�|d
d�|dd
��dd�q�W|jd�}|jtdd	�dd�dd�dd���dd�xP|j	D]F}|j	|}dj
|jj��}|jdd	�|d�|j
d�|d��dd�q�WdS)Nz;
Detailed help information for this policy is not availableFzDefault --upload location: %szDefault container runtime: %s)�newlinez"$PATH used when running report: %szReference URLs� z>8rz<30�z<40z#Presets Available With This Policy
zPreset Namez<20ZDescriptionz<45zEnabled Options)�__doc__rr<�_upload_urlr!�PATHZadd_section�vendor_urlsr
Zpresets�joinZoptsZto_argsZdesc)	r*r:Z_polZrefsec�urlZpresecZpresetZ_presetZ_optsr(r(r)r9�s6
,

zLinuxPolicy.display_distro_helpcCs^ttjkrZtjtdkrZd|_ttjkrZtjts6dStjjtjt|j�|_tjtSdS)z�Check if sos is running in a container and perform container
        specific initialisation based on ENV_HOST_SYSROOT.
        r�oci�podmanTN)rrFrG)�
ENV_CONTAINERr�environZ
_in_container�ENV_HOST_SYSROOTr�abspathZ_tmp_dir)r$r(r(r)r�s



zLinuxPolicy._container_initc
Cs�g|_tj�j}tdd|jd�j�}|jjdd�|dd�D��|jd|�}yLt	|d	��8}x0|D](}|j
d
�dj
d�d}|jj|�qdWWdQRXWn4tk
r�}z|j
jd|���WYdd}~XnXd
dd�}|jd|�}	g}
yHt	|	d	��4}x,|D]$}d|k�r|
j|j
d�d��qWWdQRXWn6tk
�rl}z|j
jd|���WYdd}~XnXx(|D] }|||
k�rt|jj|��qtWdS)zxObtain a list of loaded kernel modules to reference later for plugin
        enablement and SoSPredicate checks
        Zlsmodr)�timeoutrcSsg|]}|j�dj��qS)r)�split�strip)�.0�liner(r(r)�
<listcomp>�sz3LinuxPolicy.init_kernel_modules.<locals>.<listcomp>r?Nz#/usr/lib/modules/%s/modules.builtin�rrz.koz Unable to read kernel builtins: ZCONFIG_NET_DEVLINKZCONFIG_BLK_DEV_DM)ZdevlinkZdm_modz/boot/config-%sz=yz%Unable to read booted kernel config: ���)Zkernel_modsr�unamer,rr�
splitlines�extend�join_sysroot�openrM�append�IOError�soslog�warning)
r$r,�lines�builtinsZmfilerPZkmod�errZconfig_stringsZ
booted_configZkconfigsZkfileZbuiltinr(r(r)r�s8


$

($
zLinuxPolicy.init_kernel_modulescCs*|jr&|jdkr&tjj|j|jd��}|S)Nr)rrrrD�lstrip)r$rr(r(r)rWszLinuxPolicy.join_sysrootcCs�|jd}|jr|jnd}|jr(|j�|j|_|j|_|j|_|j|_d|_	|j
|_
|j|_|j|_|j
|_
|j|_|j|_|jr�|jr�y.|r�||jd_nttd�|�|jd_Wntk
r��YnX|jr�|j|_|jo�|j�r|yn|j�r(|j��r(|jdk�r(|j�|j�n,|jdk�rT|j�|j�|j�|j�|jjd�Wntk
�rz�YnXdS)N�cmdlineoptsrzSOptionally, please enter the case id that you are generating this report for [%s]: �s3) �commonsZcase_idZlow_priority�_configure_low_priority�
upload_url�upload_user�upload_directoryZupload_pass�upload_password�upload_archive_name�upload_s3_endpoint�upload_s3_region�upload_s3_access_key�upload_s3_bucket�upload_s3_object_prefix�upload_s3_secret_keyZbatch�quiet�input�_�KeyboardInterruptZupload�get_upload_url�upload_protocol�prompt_for_upload_user�prompt_for_upload_password�prompt_for_upload_s3_bucket�prompt_for_upload_s3_endpoint�prompt_for_upload_s3_access_key�prompt_for_upload_s3_secret_key�ui_log�info)r$Zcmdline_optsZcaseidr(r(r)�pre_work!sV


zLinuxPolicy.pre_workcCs�tj�}td�rdtd|��dd�}|ddkr<|jjd�qpd|d	�d
|d�d�}|jj|�n|jjd�ytj	d
�|jjd�Wn4t
k
r�}z|jjd|���WYdd}~XnXdS)ayUsed to constrain sos to a 'low priority' execution, potentially
        letting individual policies set their own definition of what that is.

        By default, this will attempt to assign sos to an idle io class via
        ionice if available. We will also renice our own pid to 19 in order to
        not cause competition with other host processes for CPU time.
        Zionicezionice -c3 -p �)rLZstatusrzSet IO class to idlez Error setting IO class to idle: �outputz (exit code �)zNWarning: unable to constrain report to idle IO class: ionice is not available.�zSet niceness of report to 19z%Error setting report niceness to 19: N)r�getpidrrr[r}�errorr|r\�nice�	Exception)r$Z_pid�ret�msgr_r(r(r)rd_s
z#LinuxPolicy._configure_low_prioritycCs4|j�s0d|j��d|j��d�}tt|��|_dS)zvShould be overridden by policies to determine if an access key needs
        to be provided for upload or not
        z0Please provide the upload access key for bucket z via endpoint z: N)�get_upload_s3_access_key�get_upload_s3_bucket�get_upload_s3_endpointrqrrrl)r$r�r(r(r)rz~sz+LinuxPolicy.prompt_for_upload_s3_access_keycCs0|j�s,d|j��d|j��d�}t|�|_dS)zuShould be overridden by policies to determine if a secret key needs
        to be provided for upload or not
        z0Please provide the upload secret key for bucket z via endpoint z: N)�get_upload_s3_secret_keyr�r�rro)r$r�r(r(r)r{�sz+LinuxPolicy.prompt_for_upload_s3_secret_keycCsH|jsB|jr*|jjd�r*|jdd�|_nttd��}|jd�|_|jS)zqShould be overridden by policies to determine if a bucket needs to
        be provided for upload or not
        zs3://rNz"Please provide the upload bucket: r)rmre�
startswithrqrrrN)r$�
user_inputr(r(r)rx�sz'LinuxPolicy.prompt_for_upload_s3_bucketcCs>|j}|js8d|j��d|�d�}tt|��}|p4||_|jS)ztShould be overridden by policies to determine if an endpoint needs
        to be provided for upload or not
        z.Please provide the upload endpoint for bucket z (default: z): )�_upload_s3_endpointrjr�rqrr)r$Zdefault_endpointr�r�r(r(r)ry�s
z)LinuxPolicy.prompt_for_upload_s3_endpointcCs&|j�s"d|j�}tt|��|_dS)zdShould be overridden by policies to determine if a user needs to
        be provided or not
        z#Please provide upload user for %s: N)�get_upload_userrtrqrrrf)r$r�r(r(r)rv�sz"LinuxPolicy.prompt_for_upload_usercCs2|j�r.|j�|jkr.d|j�}t|�|_dS)zsShould be overridden by policies to determine if a password needs to
        be provided for upload or not
        z+Please provide the upload password for %s: N)�get_upload_passwordr��_upload_userrrh)r$r�r(r(r)rw�s

z&LinuxPolicy.prompt_for_upload_passwordcCsL||_|js|j�|_|js$td��|j�}|jjtd|j�����|�S)a

        Entry point for sos attempts to upload the generated archive to a
        policy or user specified location.

        Currently there is support for HTTPS, SFTP, and FTP. HTTPS uploads are
        preferred for policy-defined defaults.

        Policies that need to override uploading methods should override the
        respective upload_https(), upload_sftp(), and/or upload_ftp() methods
        and should NOT override this method.

        :param archive: The archive filepath to use for upload
        :type archive: ``str``

        In order to enable this for a policy, that policy needs to implement
        the following:

        Required Class Attrs

        :_upload_url:     The default location to use. Note these MUST include
                          protocol header
        :_upload_user:    Default username, if any else None
        :_upload_password: Default password, if any else None

        The following Class Attrs may optionally be overidden by the Policy

        :_upload_directory:     Default FTP server directory, if any


        The following methods may be overridden by ``Policy`` as needed

        `prompt_for_upload_user()`
            Determines if sos should prompt for a username or not.

        `get_upload_user()`
            Determines if the default or a different username should be used

        `get_upload_https_auth()`
            Format authentication data for HTTPS uploads

        `get_upload_url_string()`
            Print a more human-friendly string than vendor URLs
        z;No upload destination provided by policy or by --upload-urlzAttempting upload to )	rirertr��_determine_upload_typer|r}rr�get_upload_url_string)r$�archiveZupload_funcr(r(r)�upload_archive�s,
zLinuxPolicy.upload_archivecCs||j|j|j|jd�}|jdj|j�kr:||jdjSd|jkrLtd��|jj	d�\}}||j�krttd|��||S)aBased on the url provided, determine what type of upload to attempt.

        Note that this requires users to provide a FQDN address, such as
        https://myvendor.com/api or ftp://myvendor.com instead of
        myvendor.com/api or myvendor.com
        )Zftp�sftpZhttpsrbraz://z#Must provide protocol in upload URLz(Unsupported or unrecognized protocol: %s)
�
upload_ftp�upload_sftp�upload_https�	upload_s3rcrur"rer�rM)r$ZprotsZprotrEr(r(r)r��s

z"LinuxPolicy._determine_upload_typecCs&|s|j�}|s|j�}tjj||�S)ahFormats the user/password credentials using basic auth

        :param user: The username for upload
        :type user: ``str``

        :param password: Password for `user` to use for upload
        :type password: ``str``

        :returns: The user/password auth suitable for use in requests calls
        :rtype: ``requests.auth.HTTPBasicAuth()``
        )r�r��requests�authZ
HTTPBasicAuth)r$�user�passwordr(r(r)�get_upload_https_auths
z!LinuxPolicy.get_upload_https_authcCstjdd�p|jp|jS)z�Helper function to determine if we should use the policy default
        upload access key or one provided by the user

        :returns: The access_key to use for upload
        :rtype: ``str``
        ZSOSUPLOADS3ACCESSKEYN)r�getenvrl�_upload_s3_access_key)r$r(r(r)r�%sz$LinuxPolicy.get_upload_s3_access_keycCs|js|j�|jS)z�Helper function to determine if we should use the policy default
        upload endpoint or one provided by the user

        :returns: The S3 Endpoint to use for upload
        :rtype: ``str``
        )rjry)r$r(r(r)r�0sz"LinuxPolicy.get_upload_s3_endpointcCs|jp
|jS)z�Helper function to determine if we should use the policy default
        upload region or one provided by the user

        :returns: The S3 region to use for upload
        :rtype: ``str``
        )rk�_upload_s3_region)r$r(r(r)�get_upload_s3_region;sz LinuxPolicy.get_upload_s3_regioncCsb|jrH|jjd�rH|jdd�jdd�}|d|_t|�dkrH|d|_|jsV|j�|jp`|jS)z�Helper function to determine if we should use the policy default
        upload bucket or one provided by the user

        :returns: The S3 bucket to use for upload
        :rtype: ``str``
        zs3://rNrr?r)rer�rMrm�lenrnrx�_upload_s3_bucket)r$Zbucket_and_prefixr(r(r)r�Ds

z LinuxPolicy.get_upload_s3_bucketcCs|jp
|jS)z�Helper function to determine if we should use the policy default
        upload object prefix or one provided by the user

        :returns: The S3 object prefix to use for upload
        :rtype: ``str``
        )rn�_upload_s3_object_prefix)r$r(r(r)�get_upload_s3_object_prefixTsz'LinuxPolicy.get_upload_s3_object_prefixcCstjdd�p|jp|jS)z�Helper function to determine if we should use the policy default
        upload secret key or one provided by the user

        :returns: The S3 secret key to use for upload
        :rtype: ``str``
        ZSOSUPLOADS3SECRETKEYN)rr�ro�_upload_s3_secret_key)r$r(r(r)r�]sz$LinuxPolicy.get_upload_s3_secret_keycCsH|jr<|jr<|jr<|jr<|j�}|j�}d|�d|��|_|jpF|jS)z�Helper function to determine if we should use the policy default
        upload url or one provided by the user

        :returns: The URL to use for upload
        :rtype: ``str``
        zs3://r)rermrlror�r�rA)r$�bucket�prefixr(r(r)rthszLinuxPolicy.get_upload_urlcCs|j�S)z�Used by distro policies to potentially change the string used to
        report upload location from the URL to a more human-friendly string
        )rt)r$r(r(r)r�ysz!LinuxPolicy.get_upload_url_stringcCstjdd�p|jp|jS)z�Helper function to determine if we should use the policy default
        upload user or one provided by the user

        :returns: The username to use for upload
        :rtype: ``str``
        Z
SOSUPLOADUSERN)rr�rfr�)r$r(r(r)r�szLinuxPolicy.get_upload_usercCstjdd�p|jp|jS)a_Helper function to determine if we should use the policy default
        upload password or one provided by the user

        A user provided password, either via option or the 'SOSUPLOADPASSWORD'
        environment variable will have precendent over any policy value

        :returns: The password to use for upload
        :rtype: ``str``
        ZSOSUPLOADPASSWORDN)rr�rh�_upload_password)r$r(r(r)r��s
zLinuxPolicy.get_upload_passwordc
Cstd�std��yddl}Wntk
r8td��YnXd}|sJ|j�}|sV|j�}|j�jdd�}d	||f}|j|d
d�}dd
d|j	|j
g}|j|dd�}	|	dkr�d}n�|	dk�r|j|�dd|j	|j
g}
|j|
dd�dk}|�sT|j
�td|j���nP|	dk�r td|j���n4|	dk�r<td|j���n|	dk�rTtd|j��|�sr|j
�td|j���d|j|j�f}|j|�d|j	|j
dg}|j|d d�}
|
dk�r�|jd!�dS|
dk�r�td"��n<|
dk�r�td#|j��n"|
dk�rtd$��ntd%|j��dS)&a�Attempts to upload the archive to an SFTP location.

        Due to the lack of well maintained, secure, and generally widespread
        python libraries for SFTP, sos will shell-out to the system's local ssh
        installation in order to handle these uploads.

        Do not override this method with one that uses python-paramiko, as the
        upstream sos team will reject any PR that includes that dependency.
        r�zSFTP is not locally supportedrNzFSFTP upload requires python3-pexpect, which is not currently installedFzsftp://rz%sftp -oStrictHostKeyChecking=no %s@%szutf-8)�encodingzsftp>z	password:zConnection refused�)rLTr?zPermission denied�
z%Incorrect username or password for %s�z)Connection refused by %s. Incorrect port?�z#Timeout hit trying to connect to %s�z.Unexpected error trying to connect to sftp: %sz Unable to connect via SFTP to %sz	put %s %sz100%zNo such file or directory�ZbyezTimeout expired while uploadingzUnknown error during upload: %sz&Unable to write archive to destinationz#Unexpected response from server: %s)rr��pexpect�ImportErrorr�r�rt�replaceZspawnZTIMEOUTZEOF�expectZsendline�closer�Zbeforeri�_get_sftp_upload_name)r$r�r�r�Zsftp_connectedZsftp_urlZsftp_cmdr�Zsftp_expectsr&Zpass_expectsZput_cmdZput_expectsZput_successr(r(r)r��s�













zLinuxPolicy.upload_sftpcCs*|jjd�d}|jr&tjj|j|�}|S)aIf a specific file name pattern is required by the SFTP server,
        override this method in the relevant Policy. Otherwise the archive's
        name on disk will be used

        :returns:       Filename as it will exist on the SFTP server
        :rtype:         ``str``
        rr?rS)rirMrgrrrD)r$Zfnamer(r(r)r��sz!LinuxPolicy._get_sftp_upload_namecCstj|j�||j�|d�S)z�If upload_https() needs to use requests.put(), use this method.

        Policies should override this method instead of the base upload_https()

        :param archive:     The open archive file object
        )�datar��verify)r��putrtr�)r$r�r�r(r(r)�_upload_https_put	szLinuxPolicy._upload_https_putcCsiS)zJDefine any needed headers to be passed with the POST request here
        r()r$r(r(r)�_get_upload_headersszLinuxPolicy._get_upload_headerscCs8d|jjd�d||j�fi}tj|j�||j�|d�S)z�If upload_https() needs to use requests.post(), use this method.

        Policies should override this method instead of the base upload_https()

        :param archive:     The open archive file object
        �filerr?)�filesr�r�rS)r rMr�r�Zpostrtr�)r$r�r�r�r(r(r)�_upload_https_posts
zLinuxPolicy._upload_https_postcCs�tstd��t|jd���}|jdjdkr2|j}n|jdj}|jdjdk}|dkrd|j||�}n|j	||�}|j
dkr�|j
dkr�|j
d	kr�td
��td|j
|jf��dSQRXd
S)z�Attempts to upload the archive to an HTTPS location.

        :returns: ``True`` if upload is successful
        :rtype: ``bool``

        :raises: ``Exception`` if upload was unsuccessful
        z7Unable to upload due to missing python requests library�rbra�autoFr�����i�z/Authentication failed: invalid user credentialszPOST request returned %s: %sTN)�REQUESTS_LOADEDr�rXrircZ
upload_method�_upload_methodZupload_no_ssl_verifyr�r�Zstatus_code�reason)r$Zarc�methodr�rRr(r(r)r�(s"
zLinuxPolicy.upload_httpsc'Cs�yddl}ddl}Wntk
r0td��YnX|s>|j�}|dkrNtd��|jdd�}|sf|j�}|sr|j�}|s�|jp�|j	}y,|j
|||dd�}|s�td	��|j|�Wn�|jk
r�td
|��Yn�|j
k
r�td|��Yn�|jk
�rv}zht|�j�d}	|	dk�r*td
|��|	dk�r@td|��|	dk�rVtd|��tdt|���WYdd}~XnXy@t|jd��"}
|jd|jjd�d|
�WdQRX|j�dStk
�r�td��YnXdS)aTAttempts to upload the archive to either the policy defined or user
        provided FTP location.

        :param url: The URL to upload to
        :type url: ``str``

        :param directory: The directory on the FTP server to write to
        :type directory: ``str`` or ``None``

        :param user: The user to authenticate with
        :type user: ``str``

        :param password: The password to use for `user`
        :type password: ``str``

        :returns: ``True`` if upload is successful
        :rtype: ``bool``

        :raises: ``Exception`` if upload in unsuccessful
        rNzmissing python ftplib libraryzIno FTP server specified by policy, use --upload-url to specify a locationzftp://rr�)rLz3connection failed, did you set a user and password?z"timeout hit while connecting to %szunable to connect to %sZ503zcould not login as '%s'Z530zinvalid password for user '%s'Z550z$could not set upload directory to %sz%error trying to establish session: %sr�zSTOR %srr?Tzcould not open archive filerS)�ftplib�socketr�r�rtr�r�r�rg�_upload_directoryZFTP�cwdrLZgaierrorZ
error_perm�strrMrXriZ
storbinary�quitrZ)r$rEZ	directoryr�r�r�r�Zsessionr_�errnoZ_arcfiler(r(r)r�GsZ


zLinuxPolicy.upload_ftpc
Cststd��|s|j�}|s$|j�}|s6|j�jd�}|s�|j�}|dkr`|jd�r`|dd�}|dkr�|jd�r�|r�|�d�nd}|s�|j	�}|s�|j
�}tjd||||d�}y(||j
jd�d
}|j|j
||�dStk
�r}	ztd	t|	����|	�WYdd}	~	XnXdS)a�Attempts to upload the archive to an S3 bucket.

        :param endpoint: The S3 endpoint to upload to
        :type endpoint: str

        :param region: The S3 region to upload to
        :type region: str

        :param bucket: The name of the S3 bucket to upload to
        :type bucket: str

        :param prefix: The prefix for the S3 object/key
        :type prefix: str

        :param access_key: The access key for the S3 bucket
        :type access_key: str

        :param secret_key: The secret key for the S3 bucket
        :type secret_key: str

        :returns: True if upload is successful
        :rtype: bool

        :raises: Exception if upload is unsuccessful
        z4Unable to upload due to missing python boto3 libraryrrr?Nrb)Zendpoint_urlZregion_nameZaws_access_key_idZaws_secret_access_keyTzFailed to upload to S3: rS)�BOTO3_LOADEDr�r�r�r�rNr�r��endswithr�r��boto3ZclientrirMZupload_filer�)
r$ZendpointZregionr�r�Z
access_keyZ
secret_keyZ	s3_client�key�er(r(r)r��s:zLinuxPolicy.upload_s3cCsdS)z�If sosreport commands need to always be prefixed with something,
        for example running in a specific container image, then it should be
        defined here.

        If no prefix should be set, return an empty string instead of None.
        rr()r$r(r(r)�set_sos_prefix�szLinuxPolicy.set_sos_prefixcCsdS)zcIf a host requires additional cleanup, the command should be set and
        returned here
        rr()r$r(r(r)�set_cleanup_cmd�szLinuxPolicy.set_cleanup_cmdcCsdS)aIReturns the command that will create the container that will be
        used for running commands inside a container on hosts that require it.

        This will use the container runtime defined for the host type to
        launch a container. From there, we use the defined runtime to exec into
        the container's namespace.

        :param image:   The name of the image if not using the policy default
        :type image:    ``str`` or ``None``

        :param auth:    The auth string required by the runtime to pull an
                        image from the registry
        :type auth:     ``str`` or ``None``

        :param force_pull:  Should the runtime forcibly pull the image
        :type force_pull:   ``bool``

        :returns:   The command to execute to launch the temp container
        :rtype:     ``str``
        rr()r$Zimager�Z
force_pullr(r(r)�create_sos_container�sz LinuxPolicy.create_sos_containercCsd|j|jfS)a�Restarts the container created for sos collect if it has stopped.

        This is called immediately after create_sos_container() as the command
        to create the container will exit and the container will stop. For
        current container runtimes, subsequently starting the container will
        default to opening a bash shell in the container to keep it running,
        thus allowing us to exec into it again.
        z%s start %s)�container_runtime�sos_container_name)r$r(r(r)�restart_sos_container�s	z!LinuxPolicy.restart_sos_containercCs |jrd|j|j|fS|SdS)aReturns the command that allows us to exec into the created
        container for sos collect.

        :param cmd: The command to run in the sos container
        :type cmd: ``str``

        :returns: The command to execute to run `cmd` in the container
        :rtype: ``str``
        z
%s exec %s %sN)r�r�)r$�cmdr(r(r)�format_container_command	s

z$LinuxPolicy.format_container_command)NNTN)NN)NN)T)T)NNNN)NNNNNN)NNF)X�__name__�
__module__�__qualname__r@r8�vendorrBr%rAr�r�r�r�r�r�r�r�r�r�r!Z_preferred_hash_namererfrhrjrmrlrorkrnZ
containerizedZcontainer_imageZsos_path_stripZsos_pkg_nameZsos_bin_pathr�Zcontainer_version_commandZcontainer_authfiler�classmethodr+r-r.r/r1r2r5r;r6r9rrrWr~rdrzr{rxryrvrwr�r�r�r�r�r�r�r�r�rtr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__r(r()r'r)r.s�(	,/>

8
		
d


O
@	
rc@seZdZdZdgZdZdZdS)�GenericLinuxPolicyz�This Policy will be returned if no other policy can be loaded. This
    should allow for IndependentPlugins to be executed on any system�Upstream Project� https://github.com/sosreport/sosZSoSaSoS was unable to determine that the distribution of this system is supported, and has loaded a generic configuration. This may not provide desired behavior, and users are encouraged to request a new distribution-specifc policy at the GitHub project above.
N)r�r�)r�r�r�r@rCr�Zvendor_textr(r(r(r)r�sr�)"rr3rZsosrrrZsos.policiesrZsos.policies.init_systemsrZ!sos.policies.init_systems.systemdrZsos.policies.runtimes.criorZsos.policies.runtimes.podmanrZsos.policies.runtimes.dockerr	Zsos.policies.runtimes.lxdr
Z
sos.utilitiesrrr
rr�r�r�r�r�rHrJrr�r(r(r(r)�<module>s@

t

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists