HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-87-generic #88-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 09:28:41 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/sos/upload/targets/__pycache__/redhat.cpython-312.pyc
�

([QhX)���ddlZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZ
	ddlZdZGd	�d
e�Zy#e$rdZY�wxYw)�N)�UploadTarget)�
convert_bytes�TIMEOUT_DEFAULT)�DeviceAuthorizationClass)�
RHELPolicy)�_sosTFc���eZdZdZdZdZdZd�fd�	ZdZdZ	e	Z
d	ZdZd
Z
d�Z�fd�Zd
�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�fd�	Zd�Z�fd�Z�xZS)�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�redhatNc�*��t�|�|||��y)N)�parser�args�cmdline)�super�__init__)�selfr
rr�	__class__s    ��;/usr/lib/python3/dist-packages/sos/upload/targets/redhat.pyrzRHELUploadTarget.__init__!s���
����T�7��C�zhttps://api.access.redhat.comzsftp://sftp.access.redhat.com�posti@c�<�t|jdt�S)z.Return true if we are running in a RHEL system�policy)�
isinstance�commonsr�rs r�check_distributionz#RHELUploadTarget.check_distribution-s���$�,�,�x�0�*�=�=rc�`��t�|�|�|jdj|_y)N�cmdlineopts)r�pre_workr�upload_directory)r�hook_commonsrs  �rrzRHELUploadTarget.pre_work1s'���
����&� $���]� ;� L� L��rc�
�|jdjr$|jjt	d��|jdj
s-|j|_|jjd�yy)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_urlrs r�prompt_for_upload_userz'RHELUploadTarget.prompt_for_upload_user7sl���<�<�
�&�2�2��K�K����5�6�
��|�|�M�*�2�2�"�/�/�D�O��K�K���E�F�3rc��|jdjr%|jjt	d��yy)NrzVThe option --upload-pass has been deprecated in favour of device authorization in RHEL)r�upload_passr$r%r&rs r�prompt_for_upload_passwordz+RHELUploadTarget.prompt_for_upload_passwordBs8���<�<�
�&�2�2��K�K����5�6�
�3rc�J�d|jdj�d�}	|jr|jS|jdjr|jdjS|jdjdk(r|jS|jdjs7|jdj|jd�s|jS|j�|��S#t$r(}|jjd|���Yd}~�<d}~wwxYw)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�	Exceptionr$r%�RH_API_HOST)r�rh_case_api�es   r�get_upload_urlzRHELUploadTarget.get_upload_urlJs��*����]�3�;�;�<�L�J��	�������&��|�|�M�*�5�5��|�|�M�2�=�=�=��|�|�M�*�:�:�f�D��(�(�(��<�<�
�.�6�6����X�&�9�9��L�L��/�1��(�(�(��"�"�#�K�=�1�1���	��K�K���*�*+��.�
�
��	�s)�C1�1C1�)'C1�AC1�1	D"�:D�D"c�(�d|j��}d|iS)NzBearer �
Authorization)�
_device_token)r�str_auths  r�_get_upload_https_authz'RHELUploadTarget._get_upload_https_auth`s ���T�/�/�0�1����*�*rc��d|jjd�d||j�fi}t|j|j
�}|j
�|_|jjd|j����tj|j�||j�|t��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_tokenr9r$r%�get_upload_url_string�requestsrr6r;r)r�archiverCrA�RHELAuths     r�_upload_https_postz#RHELUploadTarget._upload_https_postds���
�W�\�\�'�'��,�R�0�'��-�-�/�1�
��,��*�*��#�#���&�6�6�8��������J� �6�6�8�9�;�	<��}�}�T�0�0�2�%�%)�%@�%@�%B�$*�O�E�	Erc�b�|j�j|j�rddd�SiS)N�falsezno-cache)�	isPrivatez
cache-control)r6�
startswithr3rs rrGz$RHELUploadTarget._get_upload_headers}s/����� �+�+�D�,<�,<�=�!(�:�F�F��	rc���|j�j|j�ry|j�j|j�ry|j	|j
�S)NzRed Hat Customer PortalzRed Hat Secure FTP)r6rSr3r(�_get_obfuscated_upload_urlr)rs rrKz&RHELUploadTarget.get_upload_url_string�sW����� �+�+�D�,<�,<�=�,���� �+�+�D�,=�,=�>�'��.�.�t���?�?rc��|jjd�d}|jdjr|jdj�d|��}|jr*t
jj|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?rr&)�upload_archive_namerFrr'r �os�path�join)r�fnames  r�_get_sftp_upload_namez&RHELUploadTarget._get_sftp_upload_name�sy���(�(�.�.�s�3�B�7���<�<�
�&�.�.��|�|�M�2�:�:�;�1�U�G�D�E�� � ��G�G�L�L��!6�!6��>�E��rc����|jjd�d|j�vrt�
|��St
st
d��d}d}|js6	t|j|j�}|j�|_|jr,|jjd|j����|j dz}d}|jr�|j#�}	t%j&||	d	�
�}|j(dk(rFt+j,|j.�d}t+j,|j.�d
}�n|jj1d|j(�d|j+����|jj3d�n�ddi}
t%j&|t+j4|
�d	��}|j(dk(rRt+j,|j.�}|d}|d
}|jjt7d|�d���n9|jj1d|j(�d|j+����|r|rt�
|�||��St
d��#t$r3}dt|�vr|jjd�Yd}~��Gd}~wwxYw)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.r@z/support/v2/sftp/token�
)rBrD���username�tokenz$DEBUG: auth attempt failed (status: z): zUUnable to retrieve Red Hat auth token using provided credentials. Will try anonymous.�isAnonymousT)�datarDzUser 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(rFr6r�upload_sftp�REQUESTS_LOADEDr2r9rrHrIrJ�strr$r%rKr3r;rLr�status_code�json�loads�text�debug�error�dumpsr&)rrerf�_token�_userrNr5�url�retrB�adata�anon�resprs             �rrgzRHELUploadTarget.upload_sftp�s����
���"�"�4�(��+�4�3F�3F�3H�H��7�&�(�(���>�?�
?�����
�!�!�
A�3��.�.��'�'���&.�%>�%>�%@��"�����K�K���!�!%�!;�!;�!=� >�@�
A����!9�9��������1�1�3�G��-�-��W�b�A�C����#�%��
�
�3�8�8�,�Z�8�����C�H�H�-�g�6�����!�!�:�3�?�?�:K�3��x�x�z�l�$�����!�!�7��
#�D�)�E��=�=��4�:�:�e�+<�b�I�D����3�&��z�z�$�)�)�,���Z�(���g������ � ���e�W�%M�N�O��
���!�!�?��'�'�(��D�I�I�K�=�:���V��7�&�E�F�&�C�C��K�L�L��e�
�%��A��.��K�K�$�$�:����	
�s�  J%�%	K!�.(K�K!c��tjj|�}||jk\rM|jjt
dt|j��d���|j|_	yy)NzLSize of archive is bigger than Red Hat Customer Portal limit for uploads of z  via sos http upload. 
)
rXrY�getsize�_max_size_requestr$�warningr&rr(r))rrM�sizes   r�check_file_too_bigz#RHELUploadTarget.check_file_too_big�sr���w�w���w�'��
�4�)�)�)��K�K����*�"�4�#9�#9�:�;�<-�-�.�
�#�/�/�D�O�*rc	����	|j�j|j�r|j|�t�|�|�}|S#t$r�}d}|jj|j�s�|jjtd|�d|j����|j|_t�|�|�}Yd}~|Sd}~wwxYw)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)r6rSr3r}r�upload_archiver2r)r$ror&r()rrM�uploadedr5rs    �rrzRHELUploadTarget.upload_archive�s����
	7��"�"�$�/�/��0@�0@�A��'�'��0��w�-�g�6�H�����		7��H��?�?�-�-�d�.>�.>�?���K�K����D��C�y��!2�!2� 3�5�6�
�#�/�/�D�O��w�-�g�6�H����		7�s�A	A�	C�A<C�C)NNN)T)NN)�__name__�
__module__�__qualname__rHrI�upload_target_name�upload_target_idrr3r(�_upload_url�_upload_methodr9rzrrr*r-r6r;rOrGrKr\rgr}r�
__classcell__)rs@rr
r
s����E��8�N�0����D�2�K�2�L��K��N��M�"��>�M�	G��2�,+�E�2�
@�
�IM�V
0��rr
)rXrk�sos.upload.targetsr�
sos.utilitiesrr�sos.policies.authr�sos.policies.distros.redhatr�sosrr&rLrh�ImportErrorr
�rr�<module>r�sM��
��+�8�6�2�����O�
j�|�j��	���O��s�<�A�A