HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //lib/python3.6/site-packages/sos/upload/targets/__pycache__/redhat.cpython-36.pyc
3

mk�h�(�@s�ddlZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZ
yddlZdZWnek
rxdZYnXGd	d
�d
e�ZdS)�N)�UploadTarget)�
convert_bytes�TIMEOUT_DEFAULT)�DeviceAuthorizationClass)�
RHELPolicy)�_sosTFcs�eZdZdZdZdZdZd'�fdd�	ZdZd	Z	e	Z
d
ZdZdZ
dd
�Z�fdd�Zdd�Zdd�Zdd�Zdd�Zd(dd�Zdd�Zdd�Zdd �Zd)�fd!d"�	Zd#d$�Z�fd%d&�Z�ZS)*�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 TargetZredhatNcst�j|||d�dS)N)�parser�args�cmdline)�super�__init__)�selfr	r
r)�	__class__��/usr/lib/python3.6/redhat.pyr
!szRHELUploadTarget.__init__zhttps://api.access.redhat.comzsftp://sftp.access.redhat.com�posti@cCst|jdt�S)z.Return true if we are running in a RHEL systemZpolicy)�
isinstance�commonsr)rrrr�check_distribution-sz#RHELUploadTarget.check_distributioncst�j|�|jdj|_dS)N�cmdlineopts)r�pre_workr�upload_directory)rZhook_commons)rrrr1szRHELUploadTarget.pre_workcCs@|jdjr|jjtd��|jdjs<|j|_|jjd�dS)NrzVThe option --upload-user has been deprecated in favour of device authorization in RHELz&No case id provided, uploading to SFTP)rZupload_user�ui_log�info�_�case_id�RH_SFTP_HOST�
upload_url)rrrr�prompt_for_upload_user7s
z'RHELUploadTarget.prompt_for_upload_usercCs |jdjr|jjtd��dS)NrzVThe option --upload-pass has been deprecated in favour of device authorization in RHEL)rZupload_passrrr)rrrr�prompt_for_upload_passwordBsz+RHELUploadTarget.prompt_for_upload_passwordcCs�d|jdj�d�}yP|jr"|jS|jdjr:|jdjS|jdjdkrP|jS|jdjsb|jSWn4tk
r�}z|jjd|���WYdd}~XnX|j�|��S)Nz/support/v1/cases/rz/attachmentsZsftpz=There was a problem while setting the remote upload target:  )	rrrZupload_protocolr�	Exceptionrr�RH_API_HOST)rZrh_case_api�errr�get_upload_urlJs
zRHELUploadTarget.get_upload_urlcCsd|j��}d|iS)NzBearer Z
Authorization)�
_device_token)rZstr_authrrr�_get_upload_https_auth^sz'RHELUploadTarget._get_upload_https_authTcCshd|jjd�d||j�fi}t|j|j�}|j�|_|jj	d|j
����tj|j
�||j�|td�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
        �file�/�z/Device authorized correctly. Uploading file to )�files�headers�verify�timeout���)�name�split�_get_upload_headersr�client_identifier_url�token_endpoint�get_access_tokenr%rr�get_upload_url_string�requestsrr$r&r)r�archiver,r*�RHELAuthrrr�_upload_https_postbs
z#RHELUploadTarget._upload_https_postcCs|j�j|j�rddd�SiS)NZfalsezno-cache)Z	isPrivatez
cache-control)r$�
startswithr")rrrrr1{s
z$RHELUploadTarget._get_upload_headerscCs4|j�j|j�rdS|j�j|j�r(dS|j|j�S)NzRed Hat Customer PortalzRed Hat Secure FTP)r$r:r"rZ_get_obfuscated_upload_urlr)rrrrr5�s
z&RHELUploadTarget.get_upload_url_stringcCsL|jjd�d}|jdjr2|jdj�d|��}|jrHtjj|j|�}|S)z�The RH SFTP server will only automatically connect file uploads to
        cases if the filename _starts_ with the case number
        r(r)rrr.)Zupload_archive_namer0rrr�os�path�join)rZfnamerrr�_get_sftp_upload_name�sz&RHELUploadTarget._get_sftp_upload_namec
s�|jjd�d|j�kr"t�j�Sts.td��d}d}|js�yt|j	|j
�}Wn:tk
r�}zdt|�krx|jj
d�WYdd}~XnX|j�|_|jr�|jj
d|j����|jd}d}|j�r8|j�}	tj||	d	d
�}|jdk�rtj|j�d}tj|j�d
}n*|jjd|j�d|j����|jjd�n~ddi}
tj|tj|
�d	d�}|jdk�r�tj|j�}|d}|d
}|jj
td|�d���n|jjd|j�d|j����|�r�|�r�t�j||d�Std��dS)z�Override 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//r)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.z/Device authorized correctly. Uploading file to z/support/v2/sftp/token�
)r+r-��Zusername�tokenz$DEBUG: auth attempt failed (status: z): zUUnable to retrieve Red Hat auth token using provided credentials. Will try anonymous.ZisAnonymousT)�datar-zUser z^ used for anonymous upload. Please inform your support engineer so they may retrieve the data.z)DEBUG: anonymous request failed (status: )�user�passwordz1Could not retrieve valid or anonymous credentials)rr0r$r�upload_sftp�REQUESTS_LOADEDr!r%rr2r3�strrrr4r5r"r&r6rZstatus_code�json�loads�text�debug�error�dumpsr)
rrCrDZ_tokenZ_userr8r#Zurl�retr+ZadataZanonZresp)rrrrE�sV


zRHELUploadTarget.upload_sftpcCs@tjj|�}||jkr<|jjtdt|j��d���|j|_	dS)NzLSize of archive is bigger than Red Hat Customer Portal limit for uploads of z  via sos http upload. 
)
r;r<�getsize�_max_size_requestrZwarningrrrr)rr7�sizerrr�check_file_too_big�s

z#RHELUploadTarget.check_file_too_bigcs�y*|j�j|j�r|j|�t�j|�}Wnhtk
r�}zLd}|jj|j�sP�|jj	t
d|�d|j����|j|_t�j|�}WYdd}~XnX|S)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$r:r"rRr�upload_archiver!rrrLrr)rr7Zuploadedr#)rrrrS�s
zRHELUploadTarget.upload_archive)NNN)T)NN)�__name__�
__module__�__qualname__r2r3Zupload_target_nameZupload_target_idr
r"rZ_upload_urlZ_upload_methodr%rPrrrr r$r&r9r1r5r>rErRrS�
__classcell__rr)rrrs0

Kr)r;rHZsos.upload.targetsrZ
sos.utilitiesrrZsos.policies.authrZsos.policies.distros.redhatrZsosrrr6rF�ImportErrorrrrrr�<module>	s