Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/uaclient/entitlements/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

���f1c�@s�ddlZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZddl
mZmZmZmZmZmZmZmZmZddlmZddlmZmZmZddlmZe��Z e�!e�"e#��Z$dZ%Gd	d
�d
ej&�Z'dS)�N)�exists)�Any�Dict�List�Optional�Tuple�Union)	�api�apt�contract�event_logger�
exceptions�http�messages�system�util)�base)�ApplicationStatus�CanDisableFailure�CanDisableFailureReason)�status_cache_filez<^linux-image-([\d]+[.-][\d]+[.-][\d]+-[\d]+-[A-Za-z0-9_-]+)$c	seZdZdZdZdZdZdZdZdZ	e
deee
dffdd	��Ze
de
fd
d��Ze
de
fdd
��Ze
dee
fdd��Ze
dee
fdd��Ze
dee
fdd��Zdefdd�Ze
ejde
fdd���Z	d>dedeeeeff�fdd�
Zdefdd�Zdej defdd�Z!defd d!�Z"dej fd"d#�Z#dej fd$d%�Z$dej fd&d'�Z%d(d)�Z&d*d+�Z'dee(ee)j*ffd,d-�Z+d.d/�Z,	d>d0e-e
e.fd1e-e
e.fd2edef�fd3d4�
Z/		d?dej d5eee
d6eddfd7d8�Z0dej ddfd9d:�Z1	d@dej d;efd<d=�Z2�Z3S)A�RepoEntitlementz1/etc/apt/sources.list.d/ubuntu-{name}.{extension}z$/etc/apt/preferences.d/ubuntu-{name}z	{}/ubuntuNFT�returncC�dS�N���selfrr�</usr/lib/python3/dist-packages/uaclient/entitlements/repo.py�repo_pin_priority6sz!RepoEntitlement.repo_pin_prioritycCs.d}t��j}|tjvrd}|jj|j|d�S)N�sources�list)�name�	extension)r�get_release_info�seriesr
�SERIES_NOT_USING_DEB822�repo_file_tmpl�formatr")rr#r%rrr�	repo_file:s


zRepoEntitlement.repo_filecCs
|jdS)Nz {})�
repo_url_tmplrrrr�repo_policy_check_tmplBs
z&RepoEntitlement.repo_policy_check_tmplcCs<g}|j�di�}|r|�di�}t�|�dg��}|}|S)zdebs to install on enablement�entitlement�
directives�additionalPackages)�entitlement_cfg�get�copy)r�packagesr,r-�additional_packagesrrrr2Fs
�zRepoEntitlement.packagescC�|j�di��di��d�S)Nr,r-�aptURL�r/r0rrrr�apt_urlW��zRepoEntitlement.apt_urlcCr4)Nr,r-�suitesr6rrrr�
apt_suites_r8zRepoEntitlement.apt_suitescCs tjt|j�d�}t�|�|S)z%Check if system needs to be rebooted.)�installed_pkgs)r�
should_reboot�setr2�event�needs_reboot)r�reboot_requiredrrr�_check_for_rebootgs
�
z!RepoEntitlement._check_for_rebootcCrrrrrrr�
repo_key_fileoszRepoEntitlement.repo_key_file�ignore_dependent_servicescsVt�j|d�\}}|dur||fS|js'|jr'dttjtjj	|j
|j
d��fS||fS)N)rCF��entitlement_name�title)�super�can_disable�origin�purgerr�NO_PURGE_WITHOUT_ORIGINr�REPO_PURGE_FAIL_NO_ORIGINr(rF)rrC�result�reason��	__class__rrrHts
����
zRepoEntitlement.can_disablecCs*|jduot|j�dk}|js|sdSdS)Nr��)r2�len�access_only)r�will_installrrr�enable_steps�s
zRepoEntitlement.enable_steps�progresscCsj|�tjj|jd��|�|�|jr.|jr.t|j	�dkr,|�
dtjjd�|j	�d��dS|�
|�dS)z�Enable specific entitlement.

        @return: True on success, False otherwise.
        @raises: UbuntuProError on failure to install suggested packages
        ��servicer�info� �r2T)rWr�CONFIGURING_APT_ACCESSr(rF�setup_apt_config�supports_access_onlyrTrSr2�emit�SKIPPING_INSTALLING_PACKAGES�join�install_packages)rrWrrr�_perform_enable�s�

��
�zRepoEntitlement._perform_enablecCs|jsdSdS)NrQrR)rJrrrr�
disable_steps�szRepoEntitlement.disable_stepscCs�|jrL|jrL|�dtj�|�dd�t�|j�}|�||�s!dSg}g}|D]}tj||jd�}|r=|�	|t
|�f�q'|�	|�q'|�|||�sLdSt|d�rU|�
�|�|�|jru|jru|�tjj|jd��|�|�|�|�dS)NrZ�F)�exclude_origin�remove_packages�rFT)rJrIr`r�PURGE_EXPERIMENTALr
� get_installed_packages_by_origin�purge_kernel_check�get_remote_versions_for_package�append�max�prompt_for_purge�hasattrrh�remove_apt_configrW�PURGING_PACKAGESr(rF�execute_reinstall�execute_removal)rrW�repo_origin_packages�packages_to_reinstall�packages_to_remove�package�alternativesrrr�_perform_disable�sB��
��

�

z RepoEntitlement._perform_disablecs�g�|D]}t�t|j�}|r��|�d��q�rl|��s"t���|�	dt
jj|j
d��|�	dd����t��j}|�	dt
jj|d��t��}�fdd�|D�}|s_|�	dt
j�dS|�	d	tjd
t
jifg�dS)a*
        Checks if the purge operation involves a kernel.

        When package called 'linux-image-*' is in the package list, warn the
        user that a kernel is being removed. Then, show the user what the
        current kernel is.

        If the current kernel is to be removed, and there are no other valid
        Ubuntu Kernels installed in the system, return False to abort the
        operation.

        If there is another Ubuntu kernel - besides the one installed - then
        prompt the user for confirmation before proceeding.
        �rZrXr[)�kernel_versioncsg|]}|�vr|�qSrr)�.0�version��linux_image_versionsrr�
<listcomp>s
�z6RepoEntitlement.purge_kernel_check.<locals>.<listcomp>F�message_operation�msgT)�re�search�
RE_KERNEL_PKGr"rn�group�is_interactiver
�#NonInteractiveKernelPurgeDisallowedr`r�PURGE_KERNEL_REMOVALr(rFrbr�get_kernel_info�
uname_release�PURGE_CURRENT_KERNEL�get_installed_ubuntu_kernels�PURGE_NO_ALTERNATIVE_KERNELr�prompt_for_confirmation�PURGE_KERNEL_CONFIRMATION)r�package_listrWry�m�current_kernel�installed_kernels�alternative_kernelsrr�rrl�sH��
��
����
z"RepoEntitlement.purge_kernel_checkcCs�d}|r|�dtj�|�dt�dd�|D���d}|r4|�dtj�|�dt�dd�|D���d}|rC|�dtjdtjifg�dS)	NFrZcSsg|]}|j�qSr�r"�r~ryrrrr�-sz4RepoEntitlement.prompt_for_purge.<locals>.<listcomp>TcSsg|]\}}|j�qSrr�)r~ry�_rrrr�7sr�r�)r`r�WARN_PACKAGES_REMOVALr�create_package_list_str�WARN_PACKAGES_REINSTALLr��PROCEED_YES_NO)rrxrwrW�promptrrrrp!s8�������	z RepoEntitlement.prompt_for_purgecs<t����fdd�|D�}|rt�|tjj|d��dSdS)Ncsg|]
}|j�vr|j�qSrr�r���installed_packagesrrr�Ns

�z3RepoEntitlement.execute_removal.<locals>.<listcomp>r\)r
�get_installed_packages_names�purge_packagesr�UNINSTALLING_PACKAGES_FAILEDr()rrx�	to_removerr�rruHs
����zRepoEntitlement.execute_removalcs0t����fdd�|D�}|rt�|�dSdS)Ncs*g|]\}}|j�vrd�|j|j��qS)z{}={})r"r(�ver_str)r~ryrr�rrr�`s

�z5RepoEntitlement.execute_reinstall.<locals>.<listcomp>)r
r��reinstall_packages)rrw�to_reinstallrr�rrt[s
��z!RepoEntitlement.execute_reinstallc
Cstjtjj|jd�f}|j}|�di��di�}|�d�}|s*tjtjj|jd�fS|�d�}|s<tjtj	j|jd�fSt
jtjd�}|D]}t
�|j�||�|�}|ratjtjj|jd�f}nqE|jr~|jD]}	t
�|	�s}tjtjj|j|	d�fSqh|S)Nrir,r-r5r9)�	error_msg)rYry)r�DISABLEDr�SERVICE_NOT_CONFIGUREDr(rFr/r0�NO_APT_URL_FOR_SERVICE�NO_SUITES_FOR_SERVICEr
�get_apt_cache_policy�APT_POLICY_FAILEDr�r�r+�ENABLED�SERVICE_IS_ACTIVE�check_packages_are_installedr2�is_installed� SERVICE_DISABLED_MISSING_PACKAGEr")
r�current_statusr/r-�repo_url�repo_suites�policy�suite�
service_matchryrrr�application_statushsL��
�
����

���z"RepoEntitlement.application_statuscCsF|j}tdd�t�|����d�D��rdS|sdSt|t�|�v�S)z�Check if apt url delta should be applied.

        :param apt_url: string containing the apt url to be used.

        :return: False if apt url is already found on the source file.
                 True otherwise.
        css�|]}|�d�VqdS)�#N)�
startswith)r~�linerrr�	<genexpr>�s
��
�z<RepoEntitlement._check_apt_url_is_applied.<locals>.<genexpr>�
FT)r)�allr�	load_file�strip�split�bool)rr7�apt_filerrr�_check_apt_url_is_applied�s�z)RepoEntitlement._check_apt_url_is_applied�orig_access�deltas�allow_enablec
s0t��|||�r
dS|�di�}|�di�}|�d�}|�d�}t��}|r-|r-|��}	n|��\}	}
|	tjkr:dS|�	|�sxt
�d|j|�t
�tjj|jd��|�di�}|�di��d�}|rjt�|j|�|�t���|�t���|r�t
�d	|�t
�tjjd
�|�d��|jt��|d�dS)
a1Process any contract access deltas for this entitlement.

        :param orig_access: Dictionary containing the original
            resourceEntitlement access details.
        :param deltas: Dictionary which contains only the changed access keys
        and values.
        :param allow_enable: Boolean set True if allowed to perform the enable
            operation. When False, a message will be logged to inform the user
            about the recommended enabled service.

        :return: True when delta operations are processed; False when noop.
        Tr,r-r5r.Fz.New aptURL, updating %s apt sources list to %srXz%New additionalPackages, installing %r�, r\)r�)rG�process_contract_deltasr0r�read�"_check_application_status_on_cacher�rr�r��LOGrZr"r>r�REPO_UPDATING_APT_SOURCESr(r
�remove_auth_apt_repor)rrr	�ProgressWrapperr^� REPO_REFRESH_INSTALLING_PACKAGESrbrc)
rr�r�r��delta_entitlement�delta_directives�
delta_apt_url�delta_packages�status_cacher�r��orig_entitlement�old_urlrOrrr��sL




�����z'RepoEntitlement.process_contract_deltasr��cleanup_on_failurecCs�|s|j}|s	dS|�d|j�d��z|�|�Wntjy,|r+|�t�	���w|�
tjj
|jd��|jrDddi}gd�}nd}g}ztj|||d�WdStjyn|rmt�d	�
|j��|�t�	���w)
z�Install contract recommended packages for the entitlement.

        :param package_list: Optional package list to use instead of
            self.packages.
        :param cleanup_on_failure: Cleanup apt files if apt install fails.
        Nr��pre_installri�DEBIAN_FRONTEND�noninteractive)z--allow-downgradesz$-o Dpkg::Options::="--force-confdef"z$-o Dpkg::Options::="--force-confold")r2�apt_options�override_env_varsz.Apt install failed, removing apt config for {})r2r`�	messagingr0�_update_sources_listr
�UbuntuProErrorrrr	r�rWr�INSTALLING_SERVICE_PACKAGESr(rF�apt_noninteractiver
�run_apt_install_commandr�rZr")rrWr�r�r�r�rrrrc�sH
��
����z RepoEntitlement.install_packagescCs�d}d}d}|jjs|jjr't�d|jjtj�}t�d|jjtj�}tjj	}n |jj
s/|jjrGt�d|jj
tj�}t�d|jjtj�}tjj}tj
|||d�|j}|j}|d�di�}|d�di�}|�d�}	|	s�|jjd	}
|�d
�s�t�|j�}|�|
|j�}|r�|�d�}	|	s�|
}	t�d|j�|�d�}
|
s�tj|jd
��|�d�}|s�tj|jd
��|�d�}|s�tj|jd
��|jr�|js�tj |j|jd��|j!j"|jd�}t�#|||j|j�g}t$tj%�s�|�&d�t$tj'�s�|�&d�|�r"|�(dt)j*j"d�+|�d��ztj,|d�Wntj-�y!|�.t/�0���wt�1||j2�"|�|	||j3�|�4t)j5j"|jd��zt�6|�WdStj-�yV|j.t/�0�dd��w)z�Setup apt config based on the resourceToken and directives.
        Also sets up apt proxy if necessary.

        :raise UbuntuProError: on failure to setup any aspect of this apt
           configuration
        Nr�https)�
http_proxy�https_proxy�proxy_scoper,r-�obligations�
resourceToken�machineToken�enableByDefaultzWNo resourceToken present in contract for service %s. Using machine token as credentials�aptKey�rEr5r9rDr�zapt-transport-httpszca-certificatesrZr�r\F)�run_apt_update)7�cfg�global_apt_http_proxy�global_apt_https_proxyr�validate_proxy�PROXY_VALIDATION_APT_HTTP_URL�PROXY_VALIDATION_APT_HTTPS_URLr
�
AptProxyScope�GLOBAL�ua_apt_http_proxy�ua_apt_https_proxy�UACLIENT�setup_apt_proxyr)r/r0�machine_token_file�
machine_tokenr�UAContractClient�get_resource_machine_accessr"r��warningrFr
�RepoNoAptKey�MissingAptURLDirective�RepoNoSuitesrrI�RepoPinFailNoOrigin�repo_pref_file_tmplr(�add_ppa_pinningr�APT_METHOD_HTTPS_FILErn�CA_CERTIFICATES_FILEr`r�INSTALLING_PACKAGESrbr�r�rrr	r��add_auth_apt_repor*rBrW�APT_UPDATING_LIST�update_sources_list)rrWr�r��scope�
repo_filename�resource_cfgr-r��tokenr��client�machine_accessr�r�r��repo_pref_file�prerequisite_pkgsrrrr^1s���
���
�
�
�


��



���
��z RepoEntitlement.setup_apt_configr�c	Cs�t��j}|j}|j��|j�di�}|�di�}|�d�}|s(tj	|jd��|�
tjj
|jd��t�|||j�t�||�|jrQ|jj
|jd�}t�|�|r_|�
tj�t��dSdS)z�Remove any repository apt configuration files.

        :param run_apt_update: If after removing the apt update
            command after removing the apt files.
        r,r-r5r�rir�N)rr$r%r)r��entitlementsr"r0r
rrWr�REMOVING_APT_CONFIGURATIONr(rFr
r�rB�remove_apt_list_filesrr�ensure_file_absent�APT_UPDATING_LISTS�run_apt_update_command)	rrWr�r%rr,�access_directivesr�rrrrrr�s*

�
�
�z!RepoEntitlement.remove_apt_config)F)NT)T)4�__name__�
__module__�__qualname__r'rr*rIr�r��supports_purge�propertyr�int�strrr)r+rr2rr7r:r�rA�abc�abstractmethodrBrrrHrVr	r�rdrer{rlrprurtrr�NamedMessager�r�rrr�rcr^rr�
__classcell__rrrOrr#s����
	,A
�'

�1�
�
���F��
��
�;~���r)(r%r1�loggingr��os.pathr�typingrrrrrr�uaclientr	r
rrr
rrrr�uaclient.entitlementsr�(uaclient.entitlements.entitlement_statusrrr�uaclient.files.state_filesr�get_event_loggerr>�	getLogger�replace_top_level_logger_namerr�r��
UAEntitlementrrrrr�<module>s ,

Spamworldpro Mini