File: //lib/python3/dist-packages/uaclient/__pycache__/apt.cpython-310.pyc
o
V$�c V � @ sv d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z
d dlmZm
Z
mZmZ d dlmZmZmZmZmZ d dlmZ dZdZdZd Zd
ZdZdZd
ZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'g d�Z(e�)� Z*ej+G dd� dej,��Z-edde.fde.fde.fg�Z/dd� Z0de.d eej1 fd!d"�Z2di fd#e
e. d$ee. d%eee.e.f d e.fd&d'�Z3e
dd(�di fd$ee. d%eee.e.f d e.fd)d*��Z4di fd+e.d$ee. d%eee.e.f d e.fd,d-�Z5i fd%eee.e.f d e.fd.d/�Z6ddi fd0e
e. d1ee
e. d$ee. d%eee.e.f d e.f
d2d3�Z7d4e.d5e.d6e.d7e
e. d8e.d dfd9d:�Z8d;d<� Z9d=d>� Z: ded4e.d5e.d8ee. d dfd?d@�Z;dAdB� Z<dCdD� Z=dEdF� Z>dGdH� Z?ddI�dJdK�Z@dLe.d eAfdMdN�ZBd e
e/ fdOdP�ZCdfdReAd e
e. fdSdT�ZDdde-jEfdUee. dVee. dWee- d dfdXdY�ZFdZe.d[e.d\e.d eAfd]d^�ZGd eeH fd_d`�ZId ee j fdadb�ZJdgdcdd�ZKdS )h� N)� lru_cache)�Dict�List�
NamedTuple�Optional)�event_logger�
exceptions�gpg�messages�system)�ESM_APT_ROOTDIRg N@z # ubuntu-advantage-toolszDir::Etc::netrc/zDir::Etc::netrcparts/zDir::State::lists/z$Acquire::http::Proxy "{proxy_url}";
z%Acquire::https::Proxy "{proxy_url}";
z4Acquire::http::Proxy::esm.ubuntu.com "{proxy_url}";
z5Acquire::https::Proxy::esm.ubuntu.com "{proxy_url}";
z/etc/apt/trusted.gpg.d/z/usr/share/keyringsz/usr/lib/apt/methods/httpsz /usr/sbin/update-ca-certificatesz//etc/apt/apt.conf.d/90ubuntu-advantage-aptproxyz*/var/lib/apt/periodic/update-success-stampaL # Written by ubuntu-advantage-tools
deb https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-security main
# deb-src https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-security main
deb https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-updates main
# deb-src https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-updates main
)g �?g @g $@c @ s e Zd Ze� Ze� ZdS )�
AptProxyScopeN)�__name__�
__module__�__qualname__�object�GLOBAL�UACLIENT� r r �./usr/lib/python3/dist-packages/uaclient/apt.pyr
9 s
r
�InstalledAptPackages�name�version�archc
C s | � d�\}}tj�d�sdS z0t�� �!}tjddd�||||�tj� |d�gt
td� W d � W dS 1 s8w Y W dS tj
yy } z-|jdkrpt|j��� }t�d |�rbt�d
�| ���t�d|�rpt�d�| ���t�d
��d}~w tjy� t�d�t
|���w )a Validate apt credentials for a PPA.
@param repo_url: private-ppa url path
@param username: PPA login username.
@param password: PPA login password or resource token.
@raises: UserFacingError for invalid credentials, timeout or unexpected
errors.
�://z/usr/lib/apt/apt-helperNz
download-filez{}://{}:{}@{}/ubuntu/pool/zapt-helper-output)�timeout�retry_sleeps�d z401\s+unauthorized|httperror401z'Invalid APT credentials provided for {}zconnection timed outz-Timeout trying to access APT repository at {}z7Unexpected APT error. See /var/log/ubuntu-advantage.logzVCannot validate credentials for APT repo. Timeout after {} seconds trying to reach {}.)�split�os�path�exists�tempfile�TemporaryDirectoryr �subp�format�join�APT_HELPER_TIMEOUT�APT_RETRIESr �ProcessExecutionError� exit_code�str�stderr�lower�re�search�UserFacingError�
subprocess�TimeoutExpired)�repo_url�username�password�protocol� repo_path�tmpd�er, r r r �assert_valid_apt_credentialsD sT
���&�
��������r: � apt_error�returnc C s� d}t � }| �� �d�D ]}|r*t�d|�}|r*d|�� d �d�d }|�|� q|rBtjj t
|�dkr8d nd
d�t|��d�}|S )aA Parse apt update errors for invalid apt config in user machine.
This functions parses apt update errors regarding the presence of
invalid apt config in the system, for example, a ppa that cannot be
reached, for example.
In that scenario, apt will output a message in the following formats:
The repository 'ppa 404 Release' ...
Failed to fetch ppa 404 ...
On some releases, both of these errors will be present in the apt error
message.
:param apt_error: The apt error string
:return: a NamedMessage containing the error message
N�
z2(Failed to fetch |The repository .)(?P<url>[^\s]+)z- �urlz/distsr � �s� )�plural�failed_repos)
�set�stripr r. r/ � groupdict�addr
�APT_UPDATE_INVALID_URL_CONFIGr% �lenr&