3 ܓi3 @ s` d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlm Z G dd deZdS ) N)SoSComponent)_sos)__version__c s e Zd ZdZdZddddddddddddddddddZd# fd d Zedd Zed d Z dd Z dd Zdd Zdd Z dd Zedd Zedd Zedd Zdd Zd!d" Z ZS )$ 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 FNautozhttps://s3.amazonaws.com)upload_filecase_idlow_priorityZ upload_urlupload_directoryZupload_userZupload_passZ upload_methodZupload_no_ssl_verifyZupload_protocolZupload_s3_endpointZupload_s3_regionZupload_s3_bucketZupload_s3_access_keyZupload_s3_secret_keyZupload_s3_object_prefix upload_targetc s~ |st j||| d| _nN|d | _|d | _|d | _|| _|| _|| _|| _ t jd| _d| _|| _ | j | _d | _d S )NTZoptionspolicymanifestZsos_uiF)super__init__from_cmdlineoptsr r parsercmdlineargsZ_upload_fileloggingZ getLoggerui_logarchiveload_upload_targetsupload_targetsr )selfr r r Zin_placeZhook_commonsr ) __class__ /usr/lib/python3.6/__init__.pyr 5 s zSoSUpload.__init__c C s: d|_ |jdd}|jdddd |jdd d dd |jd d dd |jdd dd |jdd dd |jdd ddd |jdd dd |jdd dd |jdd dd |jdd dd |jdd d d |jd!d d"d |jd#d$d$d%d&gd'd( |jd)d$d$d*d+d,d-gd.d( |jd/d0d1d2d3 |jd4d5d6d7d8d5gd9d( d S ):Nzsos upload FILE [options]zUpload Optionsz.These options control how upload manages filesr FILEzThe file or archive to upload)metavarhelpz --case-idZstorer zspecify case identifier)actiondestr! z--upload-urlz&Upload the archive to specified server)defaultr! z --upload-userzUsername to authenticate withz --upload-passzPassword 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-keyzAccess key for the S3 bucketz--upload-s3-secret-keyzSecret key for the S3 bucketz--upload-s3-object-prefixzPrefix for the S3 object/keyz--upload-methodr ZputZpostz HTTP method to use for uploading)r$ choicesr! z--upload-protocolZhttpsZftpZsftpZs3z$Manually specify the upload protocolz--upload-no-ssl-verifyF store_truez'Disable SSL verification for upload url)r$ r" r! z--upload-targetlocalZredhatZ canonicalgenericzmManually specify vendor-specific target for uploads. Supported options are: redhat, canonical, generic, local)ZusageZadd_argument_groupadd_argument)clsr Z upload_grpr r r add_parser_optionsM sX zSoSUpload.add_parser_optionsc C s |j d |jd d S )NzSoS Upload Detailed HelpzThe upload command is designed to upload already existing sos reports, as well as other files like logs and vmcores to a distribution specific location.)Z set_titleZadd_text)r* Zsectionr r r display_help s zSoSUpload.display_helpc C s d}| j jdt d | j|}| j j| d}| jjsyt| | j jd W nL tk rr | jdd Y n. t k r } z| j|d W Y d d }~X nX d S ) 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 zExiting on user cancel N) r infor Z_fmt_msgr ZbatchinputKeyboardInterrupt_exit Exception)r Z disclaimerZ intro_msgprompter r r intro s zSoSUpload.introc C s | j | j| j j| j jdS )N)cmdlineoptsr r r )r r r r )r r r r get_commons s zSoSUpload.get_commonsc C s || _ dS )zMSet common host data for the Upload targets to reference N)commons)r r: r r r set_commons s zSoSUpload.set_commonsc C s t | jj }xP| jj D ]B}|j| |j r|jj}| jjd| d || _ |j | _qW | j s~| jd | _ | j j | _| jjd| j dS )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. zInstallation matches z, checking for upload targetsr( zUpload target set to N) listr valuesremoveZcheck_distributionr __name__r debugr nameZupload_namer0 )r Zchecksr Zcnamer r r determine_upload_target s z!SoSUpload.determine_upload_targetc C s\ ddl }i }xJ| j|jjdD ]6}|d | j| j| jd}|j| j |||j <