https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/uaclient/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/uaclient/__pycache__/actions.cpython-310.pyc
o

��Jhp:�@sTddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZmZm
Z
mZmZmZmZmZddl
mZddl
mZmZddl
mZddl
mZmZmZddlmZmZmZm Z dd	l!m"Z"m#Z#dd
l$m%Z%m&Z&m'Z'm(Z(m)Z)e�*�Z+e�,e�-e.��Z/dZ0dZ1d
e
j2dej3dejfdd�Z4	d8d
e
j2deej5dej3dejde6f
dd�Z7	d8d
e
j2de8de6de6ddf
dd�Z9	d9d
e
j2dej:ddfdd�Z;dd ddd!�d
e
j2d"e8d#e6d$e8de6d%e	ee8fd&d'�Z<ddd(�d
e
j2d)e	e8d*e6fd+d,�Zd-e8ddfd.d/�Z=	d:d-e8d0e	ee>ddfd1d2�Z?d
e
j2fd3d4�Z@d
e
j2d5e8fd6d7�ZAdS);�N)�List�Optional)�api�clouds�config�contract�entitlements�event_logger�
exceptions�	livepatch)�log)�messages�secret_manager)�status)�system�timer�util)�APPARMOR_PROFILES�CLOUD_BUILD_INFO�DEFAULT_CONFIG_FILE�DEFAULT_LOG_PREFIX)�
machine_token�notices)�AttachmentData�attachment_data_file�machine_id_file�only_series_check_marker_file�timer_jobs_state_file)zapt-news.servicezesm-cache.servicezua-timer.servicezua-timer.timerzua-auto-attach.pathzua-auto-attach.servicezua-reboot-cmds.servicezubuntu-advantage.service�
�cfg�contract_client�attached_atcCs<ddlm}t�t|d��tj|d�||�|��dS)Nr��update_motd_messages�r!�r)�uaclient.timer.update_messagingr#r�writer�	ua_statusr�update_activity_token)rr r!r#�r*�2/usr/lib/python3/dist-packages/uaclient/actions.py�_handle_partial_attach9s
r,F�services_to_be_enabled�silentc

CsDd}g}g}z'|D]"}t||j|j|d�\}	}
||	M}|	s$|�|j�q	tj|jd�q	WnJtjyH}zt�|j�t	|||�|�d}~wtj
yY|�|j�d}Yntyw}zd}|�|j�|�|�WYd}~nd}~ww|s�t	|||�t�|�|r�tj
dd�t||�D�d��tjdd�|D�d��dS)	NT)r�name�variantr.)�serviceFcSs,g|]\}}|tjjt|�t��d�f�qS))�	error_msg�log_path)r
�UNEXPECTED_ERROR�format�str�pro_log�get_user_or_root_log_file_path)�.0r/�	exceptionr*r*r+�
<listcomp>rs����z,_enable_default_services.<locals>.<listcomp>)�failed_servicescSsg|]}|tjf�qSr*)r
�!E_ATTACH_FAILURE_DEFAULT_SERVICES)r9r/r*r*r+r;�s��)�enable_entitlement_by_namer/r0�append�event�service_processedr
�ConnectivityError�service_failedr,�UbuntuProError�	Exception�services_failed�AttachFailureUnknownError�zip�AttachFailureDefaultServices)
rr-r r!r.�retr<�unexpected_errors�enable_by_default_service�ent_ret�reason�exc�er*r*r+�_enable_default_servicesFs^
��
���
������rQ�token�allow_enable�returnc
Cs�ddlm}ddlm}tj�|�t�|�}t	�
|�}tjjtj
jd�}|j||d�}	t��j}
|	�di��di�}tdd	�|�d
g�D��}|�di��di��d
d�}
|
r�zt�|
�}Wn
tjyiYnwt�|
�}|j|jkr~tj|j|jd��tjtjj|j|jd�t �!|
�|�!|	�z||�Wntj"y�}z|�#�|�d}~wwtj$�%�|	�di��dt�$|��}t&�!|�|r�t	�'||�(��}t)|||||d�t*�!t+|d��||�t,�-�dS)aC
    Common functionality to take a token and attach via contract backend
    :raise ConnectivityError: On unexpected connectivity issues to contract
        server or inability to access identity doc from metadata service.
    :raise ContractAPIError: On unexpected errors when talking to the contract
        server.
    r)�+check_entitlement_apt_directives_are_uniquer")�tz)�contract_token�
attachment_dt�machineTokenInfo�contractInfocss,�|]}|�d�dkr|�d�|fVqdS)�type�supportN)�get)r9rPr*r*r+�	<genexpr>�s���z$attach_with_token.<locals>.<genexpr>�resourceEntitlementsr\�affordances�
onlySeriesN)�release�series_codename�	machineId)rr-r r!r.r$).�uaclient.entitlementsrUr&r#r�secrets�
add_secretr�get_machine_token_filer�UAContractClient�datetime�now�timezone�utc�add_contract_machiner�get_release_info�seriesr]�dict�get_distro_infor
�MissingSeriesInDistroInfoFile�eol�AttachFailureRestrictedReleaserbrcr�add�Notice�LIMITED_TO_RELEASErr'�%EntitlementsAPTDirectivesAreNotUnique�delete�get_machine_id�cache_clearr�get_enabled_by_default_servicesrrQrrr�start)rrRrSr.rUr#�machine_token_filer r!�new_machine_token�current_seriesrZ�support_resource�only_series�allowed_release�current_releaserP�
machine_idr-r*r*r+�attach_with_token�s�


�
�
�
��
��

��

�
��r�T�cloudcCs|�|�}t|||d�dS)a\
    :raise ConnectivityError: On unexpected connectivity issues to contract
        server or inability to access identity doc from metadata service.
    :raise ContractAPIError: On unexpected errors when talking to the contract
        server.
    :raise NonAutoAttachImageError: If this cloud type does not have
        auto-attach support.
    )rRrSN)�acquire_pro_tokenr�)rr�rSrRr*r*r+�auto_attach�s

r��)�access_onlyr0r.�
extra_argsr/r�r0r�c	Csftj|||||d�}|st�tjj|jd��|�t	�
��\}}|r/|s/t�tjj|jd��||fS)z�
    Constructs an entitlement based on the name provided. Passes kwargs onto
    the entitlement constructor.
    :raise EntitlementNotFoundError: If no entitlement with the given name is
        found, then raises this error.
    )rr/r0r�r�)�title)r�entitlement_factoryr@�infor
�
ENABLING_TMPLr5r��enabler�ProgressWrapper�ENABLED_TMPL)	rr/r�r0r.r��entitlementrMrNr*r*r+r>�s�r>)�simulate_with_token�show_allr�r�cCs:|rtj|||d�\}}||fStj||d�}d}||fS)z6
    Construct the current Pro status dictionary.
    )rrRr��rr�r)r(�simulate_statusr)rr�r�rrJr*r*r+rs	
�	�r�filenamec
Cs�gd�}d}d}z	t�|�\}}Wn'tjy8}zt�dt|��t�d�|�t|��WYd}~dSd}~ww|r[g}|�	d�D]
}t
�||�rO|�|�qBt�|d�
|��dSdS)z�
    Helper which gets ubuntu_pro apparmor logs from the kernel from the last
    day and writes them to the specified filename.
    )�
journalctlz-bz-kz--since=1 day agoz7apparmor=\".*(profile=\"ubuntu_pro_|name=\"ubuntu_pro_)Nz!Failed to collect kernel logs:
%s�{}-error�
)r�subpr
�ProcessExecutionError�LOG�warningr6�
write_filer5�split�re�searchr?�join)r��cmd�apparmor_re�kernel_logs�_rP�
apparmor_logs�kernel_liner*r*r+�_write_apparmor_logs_to_file0s$$��
��r��return_codesc
Csrz
tj|��|d�\}}Wntjy,}zt�d�|�t|��WYd}~dSd}~wwt�|d�||��dS)zCHelper which runs a command and writes output or error to filename.)�rcsr�Nzstdout:
{}

stderr:
{})rr�r�r
r�r�r5r6)r�r�r��out�errrPr*r*r+�_write_command_output_to_fileIs$���r�cs,�jpt�jtjjtg�fdd�tjD��S)Nc3s(�|]}t|tjj�r|��jVqdS�N)�
issubclassr�repo�RepoEntitlement�	repo_file)r9�entitlement_clsr%r*r+r^^s��
�z#_get_state_files.<locals>.<genexpr>)	�cfg_pathr�log_filer�ua_file�pathrr�ENTITLEMENT_CLASSESr%r*r%r+�_get_state_filesWs�
��r��
output_dirc
Cs�tdd�|��td�tj�d�|��tdd�|��tdd�|��td	�d
�dd�tD���d
�|��tD]}td�|�d�||�ddgd�q9t|dd�\}}t�d�|�t	j
|tjd��t�
�}t�d�|�t	�
|��t|�}t��r�t��dt�nt��g}t|�D]7\}}	zt�t�|	��}
t�tj�|d�|��|
�Wq�ty�}zt�d|	t|��WYd}~q�d}~ww|t�td�D]K}tj�|��rzt�|�}
Wnty�}zt�d|t|��WYd}~q�d}~wwt�|
�}
t���r	t�||
�t�tj�|tj� |��|
�q�t!d�|��t"D]1}tj�|��rRz	t#�$||�W�q"t�yQ}zt�d|t|��WYd}~�q"d}~ww�q"dS)zG
    Write all relevant Ubuntu Pro logs to the specified directory
    zcloud-idz{}/cloud-id.txtz	{} statusz{}/livepatch-status.txtzsystemctl list-timers --allz{}/systemd-timers.txtzujournalctl --boot=0 -o short-precise -u cloud-init-local.service -u cloud-init-config.service -u cloud-config.servicez{}/cloud-init-journal.txtzjournalctl -o short-precise {}� cSsg|]}d|vrd�|��qS)z.servicez-u {})r5)r9�sr*r*r+r;�sz collect_logs.<locals>.<listcomp>z{}/pro-journal.txtzsystemctl status {}z	{}/{}.txtr�)r�Fr�z{}/pro-status.json)�clsz{}/environment_vars.jsonNz
user{}.logz&Failed to collect user log file: %s
%s�*zFailed to load file: %s
%sz{}/apparmor_logs.txtzFailed to copy file: %s
%s)%r�r5r�
LIVEPATCH_CMDr��UA_SERVICESrrr��json�dumpsr�DatetimeAwareJSONEncoder�get_pro_environmentr��we_are_currently_rootr7�get_all_user_log_files�USER_LOG_COLLECTED_LIMIT�get_user_log_file�	enumerate�redact_sensitive_logs�	load_file�osr�rEr�r�r6�globr�isfile�basenamer�r�shutil�copy)
rr�r1�
pro_statusr��env_vars�state_files�user_log_files�log_file_idxr��contentrP�fr*r*r+�collect_logsfs�
�
���	���
������
�����

������r�)F)Tr�)Brjr�r��loggingr�r�r��typingrr�uaclientrrrrrr	r
rrr7r
rrr(rrr�uaclient.defaultsrrrr�uaclient.filesrr�uaclient.files.state_filesrrrrr�get_event_loggerr@�	getLogger�replace_top_level_logger_name�__name__r�r�r��UAConfigrir,�EnableByDefaultService�boolrQr6r��AutoAttachInstancer�r>r��intr�r�r�r*r*r*r+�<module>s�(
��
������
�F�����
�b���
�������

�%���
���
�
�

https://t.me/RX1948 - 2025