Ë
    Û1j 3  ã                   óf   — d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ	 d dlm
Z
  G d„ de«      Zy)é    N)ÚSoSComponent)Ú_sos)Ú__version__c                   ó  ‡ — e Zd ZdZdZi dd“dd“dd“dd	“d
d	“dd	“dd	“dd“dd“dd“dd“dd	“dd	“dd	“dd	“dd	“dd	“Z	 	 d&ˆ fd„	Zed„ «       Zed„ «       Z	d„ Z
d„ Zd„ Zd„ Zd „ Zed!„ «       Zed"„ «       Zed#„ «       Zd$„ Zd%„ Zˆ xZS )'Ú	SoSUploadzÝ
    This class is designed to upload files to a distribution
    defined location. These files can be either sos reports,
    sos collections, or other kind of files like: vmcores,
    application cores, logs, etc.

    z9Upload a file to a user or policy defined remote locationÚupload_fileÚ Úcase_idÚlow_priorityFÚ
upload_urlNÚupload_directoryÚupload_userÚupload_passÚupload_methodÚautoÚupload_no_ssl_verifyÚupload_protocolÚupload_s3_endpointzhttps://s3.amazonaws.comÚupload_s3_regionÚupload_s3_bucketÚupload_s3_access_keyÚupload_s3_secret_keyÚupload_s3_object_prefixÚupload_targetc                 ó8  •— |st         ‰| �  |||«       d| _        nb|d   | _        |d   | _        |d   | _        || _        || _        || _        || _	        t        j                  d«      | _        d| _        || _        | j                  «       | _        d | _        y )NTÚoptionsÚpolicyÚmanifestÚsos_uiF)ÚsuperÚ__init__Úfrom_cmdlineÚoptsr   r   ÚparserÚcmdlineÚargsÚ_upload_fileÚloggingÚ	getLoggerÚui_logÚarchiveÚload_upload_targetsÚupload_targetsr   )Úselfr$   r&   r%   Úin_placeÚhook_commonsr+   Ú	__class__s          €ú5/usr/lib/python3/dist-packages/sos/upload/__init__.pyr!   zSoSUpload.__init__5   sœ   ø€ áä‰GÑ˜V T¨7Ô3Ø $ˆDÕð
 % YÑ/ˆDŒIØ& xÑ0ˆDŒKØ(¨Ñ4ˆDŒMØ ˆDŒKØ"ˆDŒLØˆDŒIØ 'ˆDÔä!×+Ñ+¨HÓ5ˆDŒKØ %ˆDÔØ"ˆDŒLØ"×6Ñ6Ó8ˆÔØ!ˆÕó    c                 óÎ  — d|_         |j                  dd«      }|j                  ddd¬«       |j                  dd	d
d¬«       |j                  dd d¬«       |j                  dd d¬«       |j                  dd d¬«       |j                  dd	dd¬«       |j                  dd d¬«       |j                  dd d¬«       |j                  dd d¬«       |j                  dd d¬«       |j                  dd d ¬«       |j                  d!d d"¬«       |j                  d#d$g d%¢d&¬'«       |j                  d(d$g d)¢d*¬'«       |j                  d+d,d-d.¬/«       |j                  d0d1g d2¢d3¬'«       y )4Nzsos upload FILE [options]zUpload Optionsz.These options control how upload manages filesr   ÚFILEzThe file or archive to upload)ÚmetavarÚhelpz	--case-idÚstorer
   zspecify case identifier)ÚactionÚdestr7   z--upload-urlz&Upload the archive to specified server)Údefaultr7   z--upload-userzUsername to authenticate withz--upload-passzPassword to authenticate withz--upload-directoryr   z$Specify upload directory for archivez--upload-s3-endpointz#Endpoint to upload to for S3 bucketz--upload-s3-regionz!Region to upload to for S3 bucketz--upload-s3-bucketz"Name of the S3 bucket to upload toz--upload-s3-access-keyzAccess key for the S3 bucketz--upload-s3-secret-keyzSecret key for the S3 bucketz--upload-s3-object-prefixzPrefix for the S3 object/keyz--upload-methodr   )r   ÚputÚpostz HTTP method to use for uploading)r;   Úchoicesr7   z--upload-protocol)r   ÚhttpsÚftpÚsftpÚs3z$Manually specify the upload protocolz--upload-no-ssl-verifyFÚ
store_truez'Disable SSL verification for upload url)r;   r9   r7   z--upload-targetÚlocal)ÚredhatÚ	canonicalÚgenericrD   zmManually specify vendor-specific target for uploads. Supported options are:
redhat, canonical, generic, local)ÚusageÚadd_argument_groupÚadd_argument)Úclsr$   Ú
upload_grps      r2   Úadd_parser_optionszSoSUpload.add_parser_optionsM   sø  € à2ˆŒØ×.Ñ.ØØ<óˆ
ð 	×Ñ °vØ%Dð 	 ô 	Fà×Ñ °GÀ)Ø%>ð 	 ô 	@à×Ñ ¸Ø%Mð 	 ô 	Oà×Ñ ¸Ø%Dð 	 ô 	Fà×Ñ ¸Ø%Dð 	 ô 	Fà×ÑÐ 4¸WØ%7Ø%Kð 	 ô 	Mð 	×ÑÐ 6ÀØ%Jð 	 ô 	Là×ÑÐ 4¸dØ%Hð 	 ô 	Jà×ÑÐ 4¸dØ%Ið 	 ô 	Kà×ÑÐ 8À$Ø%Cð 	 ô 	Eà×ÑÐ 8À$Ø%Cð 	 ô 	Eà×ÑÐ ;ÀTØ%Cð 	 ô 	Eà×ÑÐ 1¸6Ú(?Ø%Gð 	 ô 	Ið 	×ÑÐ 3¸VÚ(NØ%Kð 	 ô 	Mð 	×ÑÐ 8À%Ø'3Ø%Nð 	 ô 	Pð 	×ÑÐ 1¸7ò)-ð
'7ð 	 õ 
	9r3   c                 óH   — |j                  d«       |j                  d«       y )NzSoS Upload Detailed Helpz˜The upload command is designed to upload already existing sos reports, as well as other files like logs and vmcores to a distribution specific location.)Ú	set_titleÚadd_text)rK   Úsections     r2   Údisplay_helpzSoSUpload.display_help‚   s$   € à×ÑÐ4Ô5à×Ñð3õ	
r3   c                 ó®  — d}| j                   j                  dt        › d�«       | j                  |«      }| j                   j                  |«       d}| j                  j
                  s(	 t        |«       | j                   j                  d«       y	y	# t        $ r | j                  dd«       Y y	t        $ r}| j                  |d«       Y d	}~y	d	}~ww xY w)
zmPrint the intro message and prompts for a case ID if one is not
        provided on the command line
        a}  This utility is used to upload files to a target location based either on a command line option or detecting the local distribution.

The archive to be uploaded may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party.

No configuration changes will be made to the system running this utility.
z
sos upload (version ú)z,
Press ENTER to continue, or CTRL-C to quit
r	   úExiting on user cancelé‚   é   N)
r*   Úinfor   Ú_fmt_msgr#   ÚbatchÚinputÚKeyboardInterruptÚ_exitÚ	Exception)r.   Ú
disclaimerÚ	intro_msgÚpromptÚes        r2   ÚintrozSoSUpload.introŒ   s´   € ðˆ
ð 	�‰×ÑÐ1´+°¸aÐ@ÔAØ—M‘M *Ó-ˆ	Ø�‰×Ñ˜Ô#àAˆØ�y‰y�Šð!Ü�f”Ø—‘× Ñ  Õ$ð øô %ò :Ø—
‘
Ð3°SÖ9Üò !Ø—
‘
˜1˜a× Ñ ûð!ús   Á+&B ÂCÂ0CÂ8CÃCc                 óˆ   — | j                   | j                  | j                   j                  | j                   j                  dœS )N)Úcmdlineoptsr   r
   r   )r#   r   r
   r   )r.   s    r2   Úget_commonszSoSUpload.get_commonsª   s4   € àŸ9™9Ø—k‘kØ—y‘y×(Ñ(Ø $§	¡	× :Ñ :ñ	
ð 	
r3   c                 ó   — || _         y)zMSet common host data for the Upload targets
            to reference
        N)Úcommons)r.   rh   s     r2   Úset_commonszSoSUpload.set_commons²   s   € ð ˆ�r3   c                 ó<  — t        | j                  j                  «       «      }| j                  j                  «       D ]u  }|j                  |«       |j	                  «       sŒ%|j
                  j                  }| j                  j                  d|› d�«       || _	        |j                  «       | _        Œw | j                  s3| j                  d   | _	        | j                  j                  «       | _        | j                  j                  d| j                  › �«       y)a  This sets the upload target and loads that target's options.

        If no upload target is matched and no target is provided by
        the user, then we abort.

        If an upload target is provided in the command line,
        this will not run.
        zInstallation matches z, checking for upload targetsrG   zUpload target set to N)Úlistr-   ÚvaluesÚremoveÚcheck_distributionr1   Ú__name__r*   Údebugr   ÚnameÚupload_namerX   )r.   Úchecksr   Úcnames       r2   Údetermine_upload_targetz!SoSUpload.determine_upload_target¸   sú   € ô �d×)Ñ)×0Ñ0Ó2Ó3ˆØ!×0Ñ0×7Ñ7Ó9ò 	8ˆMØ�M‰M˜-Ô(Ø×/Ñ/Õ1Ø%×/Ñ/×8Ñ8�Ø—‘×!Ñ!Ð$9¸%¸ð A4ð #4ô 5à%2�Ô"Ø#0×#5Ñ#5Ó#7�Õ ð	8ð ×!Ò!Ø!%×!4Ñ!4°YÑ!?ˆDÔØ#×1Ñ1×6Ñ6Ó8ˆDÔØ�‰×ÑØ+¨D×,<Ñ,<Ð+=Ð>õ	@r3   c                 ó$  — ddl }i }| j                  |j                  j                  d«      D ]`  } |d   | j                  | j
                  | j                  ¬«      }|j                  | j                  «       «       |||j                  «       <   Œb |S )zELoads all upload targets supported by the local installation
        r   NÚtargetsrW   )r$   r&   r%   )
Úsos.upload.targetsÚ_load_modulesÚuploadrw   r$   r&   r%   ri   rf   Úget_target_id)r.   ÚsosÚsupported_upload_tgtsr   Útarget_classs        r2   r,   zSoSUpload.load_upload_targetsÐ   s�   € ó 	"Ø "ÐØ!×/Ñ/°·
±
×0BÑ0BÀIÓNò 	OˆMØ+˜=¨Ñ+Ø#'§;¡;Ø!%§¡Ø$(§L¡LôˆLð
 ×$Ñ$ T×%5Ñ%5Ó%7Ô8ØBNÐ! ,×"<Ñ"<Ó">Ò?ð	Oð %Ð$r3   c                 ó®   — g }|j                   D ]C  }t        j                  j                  |«      sŒ#|j	                  | j                  ||«      «       ŒE |S )zHelper to import upload targets)Ú__path__ÚosÚpathÚisdirÚextendÚ_find_modules_in_path)rK   ÚpackageÚsubmodÚmodulesr‚   s        r2   ry   zSoSUpload._load_modulesß   sP   € ð ˆØ×$Ñ$ò 	HˆDÜ�w‰w�}‰}˜TÕ"Ø—‘˜s×8Ñ8¸¸vÓFÕGð	Hð ˆr3   c                 óP  — g }t         j                  j                  |«      r„t        t        j                  |«      «      D ]c  }|j                  d«      sŒd|v rŒt         j                  j                  |«      \  }}d|› d|› �}|j                  | j                  |«      «       Œe |S )aU  Given a path and a module name, find everything that can be imported
        and then import it

            path - the filesystem path of the package
            modulename - the name of the module in the package

        E.G. a path of 'targets', and a modulename of 'redhat' equates to
        importing sos.upload.targets.redhat
        z.pyÚ__zsos.upload.ú.)	r�   r‚   ÚexistsÚsortedÚlistdirÚendswithÚsplitextr„   Ú_import_modules)rK   r‚   Ú
modulenamerˆ   ÚpyfileÚfnameÚ_Úmodnames           r2   r…   zSoSUpload._find_modules_in_pathè   s—   € ð ˆÜ�7‰7�>‰>˜$ÔÜ ¤§¡¨DÓ!1Ó2ò =�Ø—‘ uÔ-ØØ˜6‘>ØÜŸ7™7×+Ñ+¨FÓ3‘��qØ'¨
 |°1°U°GÐ<�Ø—‘˜s×2Ñ2°7Ó;Õ<ð=ð ˆr3   c                 óâ   — t        j                  |«      }t        j                  |t        j                  «      D �� cg c]$  \  }} | j
                  j                  d«      r|| f‘Œ& }}} |S c c} }w )z/Import and return all found classes in a modulezsos.upload.targets)Ú	importlibÚimport_moduleÚinspectÚ
getmembersÚisclassÚ
__module__Ú
startswith)rK   r–   Úmodulerq   rˆ   s        r2   r‘   zSoSUpload._import_modulesÿ   sk   € ô ×(Ñ(¨Ó1ˆô %×/Ñ/°¼¿¹ÓH÷
á��cØ�~‰~×(Ñ(Ð)=Ô>ð �3ŠKð
ˆñ 
ð
 ˆùó
s   ½)A+c                 óš   — | j                  «       | _        | j                  d   }|j                  r| j                  j	                  «        y y )Nre   )rf   rh   r   r   Ú_configure_low_priority)r.   Úcmdline_optss     r2   Úpre_workzSoSUpload.pre_work
  s>   € à×'Ñ'Ó)ˆŒØ—|‘| MÑ2ˆà×$Ò$Ø�K‰K×/Ñ/Õ1ð %r3   c           
      óà  — 	 | j                  «        | j                  rV| j                  «        | j                  j                  | _        | j                  j                  | j                  ¬«      | _        | j                  j                  }|r|dk7  r| j                  |   | _	        n| j                  «        | j                  s0| j                  j                  d«       t        j                  d«       | j                  j                  | j!                  «       «       	 t#        j$                  | j
                  «      j&                  dkD  r´t"        j(                  j+                  | j
                  «      rY	 | j                  j-                  | j
                  «       | j                  j/                  t1        d| j
                  › d�«      «       ng| j                  j                  t1        | j
                  › d	�«      «       n4| j                  j                  t1        d| j
                  › d
�«      «       y y y y # t2        $ rF}| j                  j                  t1        d|› �«      «       t        j                  d«       Y d }~ŒMd }~ww xY w# t2        $ r?}| j                  j                  t1        d| j
                  › d|› d�«      «       Y d }~y d }~ww xY w# t4        $ r | j7                  dd«       Y y w xY w)N)r¢   rD   z|No upload target set via command line options or autodetected.
Please specify one using the option --upload-target.
Exiting.rW   r   zFile z uploaded successfullyzUpload attempt failed: z is not a file.z
 is empty.zCannot upload z: ú rU   rV   )r£   r"   rc   r#   r   r+   r   Úprompt_for_case_idÚcaseidr   r-   ru   r*   ÚerrorÚsysÚexitrf   r�   ÚstatÚst_sizer‚   ÚisfileÚupload_archiverX   r•   r^   r\   r]   )r.   Úcmdline_targetÚerrrb   s       r2   ÚexecutezSoSUpload.execute  sK  € ð+	6Ø�M‰MŒOØ× Ò Ø—
‘
”Ø#Ÿy™y×4Ñ4�”Ø"Ÿk™k×<Ñ<Ø!%§¡ð =ó �”ð "ŸY™Y×4Ñ4ˆNÙ .°GÒ";Ø%)×%8Ñ%8¸Ñ%H�Õ"à×,Ñ,Ô.Ø×%Ò%ð —‘×!Ñ!ðôô —‘˜”Ø×Ñ×'Ñ'¨×(8Ñ(8Ó(:Ô;ðLÜ—7‘7˜4Ÿ<™<Ó(×0Ñ0°1Ò4Ü—w‘w—~‘~ d§l¡lÔ3ð(Ø ×.Ñ.×=Ñ=¸d¿l¹lÔKØ ŸK™K×,Ñ,Ü ! E¨$¯,©,¨Ð7MÐ"NÓ Oõð Ÿ™×)Ñ)¬!¨t¯|©|¨n¸OÐ,LÓ*MÕNà—K‘K×%Ñ%¤a¨%°·±¨~¸ZÐ(HÓ&IÕJð	 (àNðøô  )ò (Ø ŸK™K×-Ñ-¬aØ"9¸#¸Ð ?ó/Aô BäŸH™H QŸK™Kûð(ûô ò LØ—‘×!Ñ!¤! n°T·\±\°NÀ"ÀQÀCÀqÐ$IÓ"J×KÑKûðLûä ò 	6Ø�J‰JÐ/°Ö5ð	6úsc   ‚DK ÄAJ Å2AH2 Ç	A%J È2	JÈ;<I<É7J É<JÊJ Ê	KÊ5KËK ËKËK ËK-Ë,K-)NNNFNN)ro   r�   Ú__qualname__Ú__doc__ÚdescÚarg_defaultsr!   ÚclassmethodrM   rR   rc   rf   ri   ru   r,   ry   r…   r‘   r£   r±   Ú__classcell__)r1   s   @r2   r   r      sx  ø„ ñð K€DðØ�rðà�2ðð 	˜ðð 	�dð	ð
 	˜Dðð 	�tðð 	�tðð 	˜ðð 	 ðð 	˜6ðð 	Ð8ðð 	˜Dðð 	˜Dðð 	 ðð 	 ðð  	" 4ð!ð" 	˜ð#€Lð( GLØ,0õ"ð0 ñ29ó ð29ðh ñ
ó ð
ò!ò<
òò@ò0%ð ñó ðð ñó ðð, ñó ðò2ö,6r3   r   )r�   r©   r(   rš   r˜   Úsos.componentr   r|   r   r•   r   r   © r3   r2   ú<module>rº      s-   ðó 
Û 
Û Û Û å &Ý Ý ôh6�õ h6r3   