/usr/lib/python3/dist-packages/sos/upload/targets/__pycache__
NameSizeModeActions
redhat.cpython-310.pyc78780644editdlrm
ubuntu.cpython-310.pyc19700644editdlrm
__init__.cpython-310.pyc226560644editdlrm
Edit: /usr/lib/python3/dist-packages/sos/upload/targets/__pycache__/redhat.cpython-310.pyc (7878B)
o G%@i))@sddlZddlZddlmZddlmZmZddlmZddl m Z ddl m Z zddlZdZWn ey;dZYnwGd d d eZdS) N) UploadTarget) convert_bytesTIMEOUT_DEFAULT)DeviceAuthorizationClass) RHELPolicy)_sosTFcseZdZdZdZdZdZd'fdd ZdZd Z e Z d Z dZ d Z d d ZfddZddZddZddZddZd(ddZddZddZdd Zd'fd!d" Zd#d$Zfd%d&ZZS))RHELUploadTargetzVhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth/devicezPhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/tokenzRed Hat Upload TargetredhatNcstj|||ddS)N)parserargscmdline)super__init__)selfr r r  __class__;/usr/lib/python3/dist-packages/sos/upload/targets/redhat.pyr!szRHELUploadTarget.__init__zhttps://api.access.redhat.comzsftp://sftp.access.redhat.composti@cCst|jdtS)z.Return true if we are running in a RHEL systempolicy) isinstancecommonsrrrrrcheck_distribution-sz#RHELUploadTarget.check_distributioncst||jdj|_dS)N cmdlineopts)r pre_workrupload_directory)r hook_commonsrrrr1s zRHELUploadTarget.pre_workcCsD|jdjr|jtd|jdjs |j|_|jddSdS)NrzVThe option --upload-user has been deprecated in favour of device authorization in RHELz&No case id provided, uploading to SFTP)r upload_userui_loginfo_case_id RH_SFTP_HOST upload_urlrrrrprompt_for_upload_user7s  z'RHELUploadTarget.prompt_for_upload_usercCs$|jdjr|jtddSdS)NrzVThe option --upload-pass has been deprecated in favour of device authorization in RHEL)r upload_passrr r!rrrrprompt_for_upload_passwordBs z+RHELUploadTarget.prompt_for_upload_passwordc Csd|jdjd}z,|jr|jWS|jdjr|jdjWS|jdjdkr+|jWS|jdjs5|jWSWntyQ}z|jd|WYd}~nd}~ww|j|S)Nz/support/v1/cases/rz /attachmentssftpz=There was a problem while setting the remote upload target: ) rr"r$upload_protocolr# Exceptionrr RH_API_HOST)r rh_case_apierrrget_upload_urlJs,   zRHELUploadTarget.get_upload_urlcCsd|j}d|iS)NzBearer Authorization) _device_token)rstr_authrrr_get_upload_https_auth^s z'RHELUploadTarget._get_upload_https_authTcCshd|jdd||fi}t|j|j}||_|j d| t j | |||tdS)zIf 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 file//Device authorized correctly. Uploading file to )filesheadersverifytimeout)namesplit_get_upload_headersrclient_identifier_urltoken_endpointget_access_tokenr0rr get_upload_url_stringrequestsrr.r2r)rarchiver9r7RHELAuthrrr_upload_https_postbs   z#RHELUploadTarget._upload_https_postcCs||jr dddSiS)Nfalsezno-cache) isPrivatez cache-control)r. startswithr+rrrrr={s z$RHELUploadTarget._get_upload_headerscCs4||jr dS||jrdS||jS)NzRed Hat Customer PortalzRed Hat Secure FTP)r.rHr+r#_get_obfuscated_upload_urlr$rrrrrAs  z&RHELUploadTarget.get_upload_url_stringcCsL|jdd}|jdjr|jdjd|}|jr$tj|j|}|S)zThe RH SFTP server will only automatically connect file uploads to cases if the filename _starts_ with the case number r4r5rr!)upload_archive_namer<rr"rospathjoin)rfnamerrr_get_sftp_upload_names  z&RHELUploadTarget._get_sftp_upload_namec s|jdd|vrtStstdd}d}|jsKz t|j |j }WntyE}zdt |vr;|j dWYd}~n d}~ww||_|jrY|j d||jd}d} |jr|} tj|| d d } | jd krt| jd }t| jd }nT|j d| jd| |j dn>ddi} tj|t| d d} | jd krt| j} | d }| d }|j td|dn|j d| jd| |r|rtj|||dStd)zOverride the base upload_sftp to allow for setting an on-demand generated anonymous login for the RH SFTP server if a username and password are not given z//zPpython3-requests is not installed and is required for obtaining SFTP auth token.Nzend user deniedz:Device token authorization has been cancelled by the user.r6z/support/v2/sftp/token )r8r:usernametokenz$DEBUG: auth attempt failed (status: z): zUUnable to retrieve Red Hat auth token using provided credentials. Will try anonymous. isAnonymousT)datar:zUser z^ used for anonymous upload. Please inform your support engineer so they may retrieve the data.z)DEBUG: anonymous request failed (status: )userpassworduser_dirz1Could not retrieve valid or anonymous credentials)r#r<r.r upload_sftpREQUESTS_LOADEDr*r0rr>r?strrr r@rAr+r2rBr status_codejsonloadstextdebugerrordumpsr!)rrWrXrY_token_userrDr-urlretr8adataanonresprrrrZsz         zRHELUploadTarget.upload_sftpcCsDtj|}||jkr |jtdt|jd|j|_ dSdS)NzLSize of archive is bigger than Red Hat Customer Portal limit for uploads of z via sos http upload. ) rKrLgetsize_max_size_requestrwarningr!rr#r$)rrCsizerrrcheck_file_too_bigs   z#RHELUploadTarget.check_file_too_bigc sz||jr||t|}W|StyL}z*d}|j|js(|j t d|d|j |j |_t|}WYd}~|Sd}~ww)zOverride the base upload_archive to provide for automatic failover from RHCP failures to the public RH dropbox Fz0Upload to Red Hat Customer Portal failed due to z . Trying N) r.rHr+ror upload_archiver*r$rrbr!r#)rrCuploadedr-rrrrps*  zRHELUploadTarget.upload_archive)NNN)T)__name__ __module__ __qualname__r>r?upload_target_nameupload_target_idrr+r# _upload_url_upload_methodr0rlrrr%r'r.r2rEr=rArOrZrorp __classcell__rrrrrs2    Lr)rKr^sos.upload.targetsr sos.utilitiesrrsos.policies.authrsos.policies.distros.redhatrsosrr!rBr[ ImportErrorrrrrrs