HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sos/upload/targets/__pycache__/redhat.cpython-310.pyc
o

([QhX)�@s�ddlZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZ
zddlZdZWney;dZYnwGd	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 Target�redhatNcst�j|||d�dS)N)�parser�args�cmdline)�super�__init__)�selfr
rr��	__class__��;/usr/lib/python3/dist-packages/sos/upload/targets/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 system�policy)�
isinstance�commonsr�rrrr�check_distribution-sz#RHELUploadTarget.check_distributioncst��|�|jdj|_dS)N�cmdlineopts)r
�pre_workr�upload_directory)r�hook_commonsrrrr1szRHELUploadTarget.pre_workcCsD|jdjr|j�td��|jdjs |j|_|j�d�dSdS)NrzVThe option --upload-user has been deprecated in favour of device authorization in RHELz&No case id provided, uploading to SFTP)r�upload_user�ui_log�info�_�case_id�RH_SFTP_HOST�
upload_urlrrrr�prompt_for_upload_user7s��z'RHELUploadTarget.prompt_for_upload_usercCs$|jdjr|j�td��dSdS)NrzVThe option --upload-pass has been deprecated in favour of device authorization in RHEL)r�upload_passrr r!rrrr�prompt_for_upload_passwordBs
��z+RHELUploadTarget.prompt_for_upload_passwordc
Cs�d|jdj�d�}z7|jr|jWS|jdjr|jdjWS|jdjdkr+|jWS|jdjs@|jd�|jd�s@|jWSWnty\}z|j�d|���WYd}~nd}~ww|j	�|��S)Nz/support/v1/cases/rz/attachments�sftprz=There was a problem while setting the remote upload target:  )
rr"r$�upload_protocolr#�prompt_for_case_id�	Exceptionrr �RH_API_HOST)r�rh_case_api�errr�get_upload_urlJs4
�
�������zRHELUploadTarget.get_upload_urlcCsd|j��}d|iS)NzBearer �
Authorization)�
_device_token)r�str_authrrr�_get_upload_https_auth`sz'RHELUploadTarget._get_upload_https_authTcCshd|j�d�d||��fi}t|j|j�}|��|_|j�	d|�
����tj|�
�||��|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�/����/Device authorized correctly. Uploading file to )�files�headers�verify�timeout)�name�split�_get_upload_headersr�client_identifier_url�token_endpoint�get_access_tokenr1rr �get_upload_url_string�requestsrr/r3r)r�archiver:r8�RHELAuthrrr�_upload_https_postds ���
��z#RHELUploadTarget._upload_https_postcCs|���|j�r
ddd�SiS)N�falsezno-cache)�	isPrivatez
cache-control)r/�
startswithr,rrrrr>}s
z$RHELUploadTarget._get_upload_headerscCs4|���|j�r
dS|���|j�rdS|�|j�S)NzRed Hat Customer PortalzRed Hat Secure FTP)r/rIr,r#�_get_obfuscated_upload_urlr$rrrrrB�s
z&RHELUploadTarget.get_upload_url_stringcCsL|j�d�d}|jdjr|jdj�d|��}|jr$tj�|j|�}|S)z�The RH SFTP server will only automatically connect file uploads to
        cases if the filename _starts_ with the case number
        r5r6rr!)�upload_archive_namer=rr"r�os�path�join)r�fnamerrr�_get_sftp_upload_name�sz&RHELUploadTarget._get_sftp_upload_namec

s�|j�d�d|��vrt���Ststd��d}d}|jsKz	t|j	|j
�}WntyE}zdt|�vr;|j�
d�WYd}~n
d}~ww|��|_|jrY|j�
d|�����|jd}d}|jr�|��}	tj||	d	d
�}|jdkr�t�|j�d}t�|j�d
}nT|j�d|j�d|�����|j�d�n>ddi}
tj|t�|
�d	d�}|jdkr�t�|j�}|d}|d
}|j�
td|�d���n|j�d|j�d|�����|r�|r�t�j||d�Std��)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//�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.r7z/support/v2/sftp/token�
)r9r;���username�tokenz$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: )�user�passwordz1Could not retrieve valid or anonymous credentials)r#r=r/r
�upload_sftp�REQUESTS_LOADEDr+r1rr?r@�strrr rArBr,r3rCr�status_code�json�loads�text�debug�error�dumpsr!)
rrXrY�_token�_userrEr.�url�retr9�adata�anon�resprrrrZ�sv
����
	�


���
����zRHELUploadTarget.upload_sftpcCsDtj�|�}||jkr |j�tdt|j��d���|j|_	dSdS)NzLSize of archive is bigger than Red Hat Customer Portal limit for uploads of z  via sos http upload. 
)
rLrM�getsize�_max_size_requestr�warningr!rr#r$)rrD�sizerrr�check_file_too_big�s
���z#RHELUploadTarget.check_file_too_bigc
s�z|���|j�r|�|�t��|�}W|StyL}z*d}|j�|j�s(�|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/rIr,ror
�upload_archiver+r$rrbr!r#)rrD�uploadedr.rrrrp�s*
������zRHELUploadTarget.upload_archive)NNN)T)NN)�__name__�
__module__�__qualname__r?r@�upload_target_name�upload_target_idrr,r#�_upload_url�_upload_methodr1rlrrr%r'r/r3rFr>rBrPrZrorp�
__classcell__rrrrrs2

Kr)rLr^�sos.upload.targetsr�
sos.utilitiesrr�sos.policies.authr�sos.policies.distros.redhatr�sosrr!rCr[�ImportErrorrrrrr�<module>s�