a >h3@s`ddlZddlZddlZddlZddlZddlmZddlmZ ddlm Z GdddeZ dS)N) SoSComponent)_sos) __version__cseZdZdZdZddddddddddddddddddZd#fd d Zed d Zed dZ ddZ ddZ ddZ ddZ ddZeddZeddZeddZdd Zd!d"ZZS)$ 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 locationFNautozhttps://s3.amazonaws.com) upload_filecase_id low_priorityZ upload_urlupload_directoryZ upload_userZ upload_passZ upload_methodZupload_no_ssl_verifyZupload_protocolZupload_s3_endpointZupload_s3_regionZupload_s3_bucketZupload_s3_access_keyZupload_s3_secret_keyZupload_s3_object_prefix upload_targetcs~|st|||d|_nN|d|_|d|_|d|_||_||_||_||_ t d|_ d|_||_ ||_d|_dS)NToptionspolicymanifestZsos_uiF)super__init__ from_cmdlineoptsrrparsercmdlineargsZ _upload_fileloggingZ getLoggerui_logarchiveload_upload_targetsupload_targetsr )selfrrrZin_placeZ hook_commonsr __class__7/usr/lib/python3.9/site-packages/sos/upload/__init__.pyr5s     zSoSUpload.__init__cCs.d|_|dd}|jdddd|jdd d d d |jd ddd|jdddd|jdddd|jdd ddd |jdddd|jdddd|jdddd|jdddd|jddd d|jd!dd"d|jd#d$gd%d&d'|jd(d$gd)d*d'|jd+d,d-d.d/|jd0d1gd2d3d'dS)4Nzsos upload FILE [options]zUpload Optionsz.These options control how upload manages filesrFILEzThe file or archive to upload)metavarhelpz --case-idstorer 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)rZputZpostz HTTP method to use for uploading)r'choicesr#z--upload-protocol)rhttpsftpsftpZs3z$Manually specify the upload protocolz--upload-no-ssl-verifyF store_truez'Disable SSL verification for upload url)r'r%r#z--upload-targetlocal)ZredhatZ canonicalgenericr-zmManually specify vendor-specific target for uploads. Supported options are: redhat, canonical, generic, local)usageadd_argument_group add_argument)clsrZ upload_grprrr add_parser_optionsMst zSoSUpload.add_parser_optionscCs|d|ddS)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_titleadd_text)r2sectionrrr display_helps zSoSUpload.display_helpc Csd}|jdtd||}|j|d}|jjszt||jdWnLtyp|ddYn0t y}z||dWYd }~n d }~00d 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 rExiting on user cancelN) rinforZ_fmt_msgrZbatchinputKeyboardInterrupt_exit Exception)rZ disclaimerZ intro_msgprompterrr intros    zSoSUpload.introcCs|j|j|jj|jjdS)N) cmdlineoptsrr r )rrr r )rrrr get_commonss zSoSUpload.get_commonscCs ||_dS)zMSet common host data for the Upload targets to reference N)commons)rrErrr set_commonsszSoSUpload.set_commonscCst|j}|jD]B}|||r|jj}|jd|d||_ | |_ q|j sz|jd|_ |j |_ |j d|j dS)aThis 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) listrvaluesremoveZcheck_distributionr__name__rdebugr nameZ upload_namer;)rZchecksr Zcnamerrr determine_upload_targets      z!SoSUpload.determine_upload_targetcCsXddl}i}||jjdD]6}|d|j|j|jd}||||| <q|S)zELoads all upload targets supported by the local installation rNtargetsr:)rrr) Zsos.upload.targets _load_modulesZuploadrNrrrrFrDZ get_target_id)rsosZsupported_upload_tgtsr Z target_classrrr rszSoSUpload.load_upload_targetscCs2g}|jD]"}tj|r ||||q |S)zHelper to import upload targets)__path__ospathisdirextend_find_modules_in_path)r2packageZsubmodmodulesrSrrr rOs   zSoSUpload._load_modulescCsng}tj|rjtt|D]J}|ds.qd|vr8qtj|\}}d|d|}|||q|S)aUGiven 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..) rRrSexistssortedlistdirendswithsplitextrU_import_modules)r2rSZ modulenamerXZpyfilefname_modnamerrr rVs   zSoSUpload._find_modules_in_pathcCs&t|}ddt|tjD}|S)z/Import and return all found classes in a modulecSs$g|]\}}|jdr||fqS)zsos.upload.targets) __module__ startswith).0rLr2rrr s z-SoSUpload._import_modules..) importlib import_moduleinspectZ getmembersZisclass)r2rcmodulerXrrr r`s   zSoSUpload._import_modulescCs(||_|jd}|jr$|jdS)NrC)rDrEr rZ_configure_low_priority)r cmdline_optsrrr pre_work s  zSoSUpload.pre_workc Csz||jr6||jj|_|jj|jd|_|jj }|rX|dkrX|j ||_ n| |j s||j dtd|j |zt|jjdkrBtj|jr(z,|j |j|j td|jdWnFty$}z,|j td|tdWYd}~n d}~00n|j t|jd n|j td|jd WnFty}z,|j td |jd |d WYd}~n d}~00Wn ty|ddYn0dS)N)rlr-z|No upload target set via command line options or autodetected. Please specify one using the option --upload-target. Exiting.r:rzFile z uploaded successfullyzUpload attempt failed: z is not a file.z is empty.zCannot upload z:  r8r9)rmrrBrrrrZprompt_for_case_idZcaseidr rrMrerrorsysexitrDrRstatst_sizerSisfileZupload_archiver;rbr?r=r>)rZcmdline_targeterrrArrr executesJ   ":zSoSUpload.execute)NNNFNN)rJrd __qualname____doc__ZdescZ arg_defaultsr classmethodr3r6rBrDrFrMrrOrVr`rmrv __classcell__rrrr rsP 4    r) rRrprrjrhZ sos.componentrrPrrbrrrrrr  s