Current File : //usr/lib/python3/dist-packages/uaclient/files/__pycache__/notices.cpython-312.pyc
�

Uٵg�!��8�ddlZddlZddlmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
eje
je��Ze
j$�Zedgd��ZGd�d	ee�ZGd
�d�Zdad�Zd
eddfd�Zd
eddfd�Zdeefd�Zy)�N)�
namedtuple)�Enum)�List)�defaults�event_logger�messages�system�util�NoticeFileDetails)�order_id�label�is_permanent�messagec��eZdZedddej
��Zedddd��Zed	d
dej��Zedddej��Z	ed
ddej��Zedddej��Zedddej��Z
edddej��Zedddejj ��Zedddej"��Zedddej&��Zedddej*��Zedddd��Zedd dej.��Zed!d"dej2��Zed#d$dej6��Zy%)&�Notice�contract_expired�5T)r
rrr�reboot_required�10FzSystem reboot required�enable_reboot_required�11�reboot_script_failed�12�fips_reboot_required�20�fips_system_reboot_required�21�fips_install_out_of_date�22�fips_disable_reboot_required�23�fips_proc_file_error�24�fips_manual_disable_url�25�wrong_fips_metapackage_on_cloud�lp_lts_reboot_required�30�operation_in_progress�60z"Operation in progress: {operation}�auto_attach_retry_full_notice�70�auto_attach_total_failure�71�limited_to_release�80N)�__name__�
__module__�__qualname__rr�CONTRACT_EXPIRED�REBOOT_REQUIRED�ENABLE_REBOOT_REQUIRED_TMPL�ENABLE_REBOOT_REQUIRED�REBOOT_SCRIPT_FAILED�FIPS_REBOOT_REQUIRED_MSG�FIPS_REBOOT_REQUIRED�FIPS_SYSTEM_REBOOT_REQUIRED�FIPS_INSTALL_OUT_OF_DATE�FIPS_DISABLE_REBOOT_REQUIRED�FIPS_PROC_FILE_ERROR�tmpl_msg�NOTICE_FIPS_MANUAL_DISABLE_URL�FIPS_MANUAL_DISABLE_URL�&NOTICE_WRONG_FIPS_METAPACKAGE_ON_CLOUD�WRONG_FIPS_METAPACKAGE_ON_CLOUD�LIVEPATCH_LTS_REBOOT_REQUIRED�OPERATION_IN_PROGRESS�AUTO_ATTACH_RETRY_NOTICE�AUTO_ATTACH_RETRY_FULL_NOTICE�&AUTO_ATTACH_RETRY_TOTAL_FAILURE_NOTICE�AUTO_ATTACH_RETRY_TOTAL_FAILURE�LIMITED_TO_RELEASE���8/usr/lib/python3/dist-packages/uaclient/files/notices.pyrrs���(� ����)�)�	��(����(�	�O�/�&����4�4�	��-�$����-�-�	��-�$����1�1�	��#4�+����4�4�	#�� 1�(����1�1�	 ��$5�,����5�5�	$� �-�$����-�-�6�6�	��0�'����7�7�	��'8�/����?�?�	'�#�%6�&����6�6�	%�!�.�%���4�	��%6�-����1�1�	%�!�'8�)����?�?�	'�#�+�"����+�+�	�rLrc�t�eZdZdedefd�Zdefd�Zdedeefd�Zdedede	fd	�Z
dedefd
�Zdeefd�Zy)
�NoticesManager�notice_details�descriptionc���tj�s+tjd|jj
�y|jjrtjntj}dj|jj|jj
�}tjtjj!||�|�y)z�Adds a notice file. If the notice is found,
        it overwrites it.

        :param notice_details: Holds details concerning the notice file.
        :param description: The content to be written to the notice file.
        z.NoticesManager.add(%s) called as non-root userN�{}-{})r
�we_are_currently_root�LOG�warning�valuer
rr�NOTICES_PERMANENT_DIRECTORY�NOTICES_TEMPORARY_DIRECTORY�formatrr	�
write_file�os�path�join)�selfrPrQ�	directory�filenames     rM�addzNoticesManager.addts����)�)�+��K�K�@��$�$�*�*�
�
��#�#�0�0�
�0�0��5�5�	�
�>�>�� � �)�)�>�+?�+?�+E�+E�
��	����G�G�L�L��H�-��	
rLc���tj�s+tjd|jj
�y|jjrtjntj}dj|jj|jj
�}tjtjj!||��y)ziDeletes a notice file.

        :param notice_details: Holds details concerning the notice file.
        z1NoticesManager.remove(%s) called as non-root userNrS)r
rTrUrVrWr
rrrXrYrZrr	�ensure_file_absentr\r]r^)r_rPr`ras    rM�removezNoticesManager.remove�s���
�)�)�+��K�K�C��$�$�*�*�
�
��#�#�0�0�
�0�0��5�5�	�
�>�>�� � �)�)�>�+?�+?�+E�+E�
��	�!�!�"�'�'�,�,�y�(�"C�DrLr`�returnc	���tj|�D�cgc]S}tjjtjj	||��r|j||�r|��Uc}Scc}w)z�Gets the list of notice file names in the given directory.

        :param directory: The directory to search for notice files.
        :returns: List of notice file names.
        )r\�listdirr]�isfiler^�_is_valid_notice_file)r_r`�	file_names   rM�_get_notice_file_namesz%NoticesManager._get_notice_file_names�s\�� �Z�Z�	�2�
���w�w�~�~�b�g�g�l�l�9�i�@�A��*�*�9�i�@�
�
�	
��
s�AA3rkc���|tjk(}tD�chc]7}|j|k(r&dj	|j
|j���9}}||vScc}w)z�Checks if the notice file is valid.

        :param file_name: The name of the notice file.
        :returns: True if the file is valid, False otherwise.
        rS)rrXrrrZrr
)r_r`rk�is_permanent_dir�n�valid_file_namess      rMrjz$NoticesManager._is_valid_notice_file�sh��%��(L�(L�L���
���~�~�!1�1�
�N�N�1�:�:�q�w�w�/�
��
�
�,�,�,��
s�<Ac��|jd�\}}tD]9}|j|k(s�|j|k(s�#|jj
cSy)z�Gets the default message for a notice file.

        :param file_name: The name of the notice file.
        :returns: The default message defined in the enum.
        �-�)�splitrrr
rWr)r_rkrr
�notices     rM�_get_default_messagez#NoticesManager._get_default_message�sQ��$�/�/�#�.���%��	,�F����(�*�v�|�|�u�/D��|�|�+�+�+�	,�rLc�
�tjtjf}g}|D]�}tjj|�s�#|j
|�}|D]l}	tjtjj||��}|r|j|��K|j|�}|j|��n��|j�|S#t$rtjd|z�Y��wxYw)zdGets all the notice files currently saved.

        :returns: List of notice file contents.
        zPermission error while reading )rrXrYr\r]�existsrlr	�	load_filer^�PermissionErrorrUrV�appendrv�sort)r_�notice_directories�notices�notice_directory�notice_file_names�notice_file_name�notice_file_contents�default_messages        rM�listzNoticesManager.list�s��
�0�0��0�0�
���� 2�	4���7�7�>�>�"2�3�� $� ;� ;�<L� M��$5�
4� ��+1�+;�+;������%5�7G�H�,�(�(��N�N�#7�8�&*�&?�&?�(�'�O��N�N�?�3�!
4�		4�*	�������'���K�K�9�<L�L���	�s�3C�!D�DN)
r1r2r3r�strrbrerrl�boolrjrvr�rKrLrMrOrOss{��
��
��
�>E�V�E�,
��
��S�	�
�-�s�-�s�-�t�-�
�c�
�c�
� �d�3�i� rLrOc�.�t�
t�atS�N)�_notice_clsrOrKrLrM�
get_noticer��s����$�&���rLrPrfc�t�t�}|jjdi|��}|j||�y)NrK)r�rrZrb)rP�kwargsrurQs    rMrbrb�s2��
�\�F�/�.�(�(�/�/�9�&�9�K�
�J�J�~�{�+rLc�:�t�}|j|�yr�)r�re)rPrus  rMreres��
�\�F�
�M�M�.�!rLc�6�t�}|j�Sr�)r�r�)rus rMr�r�	s��
�\�F��;�;�=�rL)�loggingr\�collectionsr�enumr�typingr�uaclientrrrr	r
�	getLogger�replace_top_level_logger_namer1rU�get_event_logger�eventrrrOr�r�rbrer�r�rKrLrM�<module>r�s����	�"���C�C��g���:��:�:�8�D�E��%��%�%�'����I���
`�
��`�F}�}�@���,��,�T�,�"�6�"�d�"�
�d�3�i�rL