| Current Path : /usr/lib/python3/dist-packages/uaclient/__pycache__/ |
| Current File : //usr/lib/python3/dist-packages/uaclient/__pycache__/apt.cpython-38.pyc |
U
8�-d�f � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl Z d dl
mZ d dlm
Z
mZmZmZmZmZ d dlZd dlZd dlmZmZmZmZmZ d dlmZ dZdZdZd Z d
Z!dZ"dZ#d
Z$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dddgZ-e�.� Z/ej0G dd� dej1��Z2edde3fde3fde3fg�Z4dd � Z5e3eej6 d!�d"d#�Z7di fee3 ee3 ee
e3e3f e3d$�d%d&�Z8edd'�di fee3 ee
e3e3f e3d(�d)d*��Z9G d+d,� d,�Z:d-d.� Z;d/d0� Z<e3ee3 d1�d2d3�Z=di fe3ee3 ee
e3e3f e3d4�d5d6�Z>i fee
e3e3f e3d7�d8d9�Z?ddi fee3 eee3 ee3 ee
e3e3f e3d:�d;d<�Z@e3e3e3ee3 e3dd=�d>d?�ZAd@dA� ZBdBdC� ZCdqe3e3ee3 ddD�dEdF�ZDdGdH� ZEdIdJ� ZFdKdL� ZGdMdN� ZHddO�dPdQ�ZIe3eJd1�dRdS�ZKee4 dT�dUdV�ZLdreJee3 dX�dYdZ�ZMdde2jNfee3 ee3 ee2 dd[�d\d]�ZOe3e3e3eJd^�d_d`�ZPeeQ dT�dadb�ZReej dT�dcdd�ZSddT�dedf�ZTee3 e3dg�dhdi�ZUdjdk� ZVdldm� ZWee3 e
e3ee3ee3 f f dn�dodp�ZXdS )s� N)� lru_cache)�Dict�Iterable�List�
NamedTuple�Optional�Union)�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 = s r �InstalledAptPackages�name�version�archc
C s | � d�\}}tj�d�sdS zFt�� �4}tjddd�||||�tj� |d�gt
td� W 5 Q R X W n� tj
k
r� } z`|jdkr�t|j��� }t�d |�r�t�d
�| ���nt�d|�r�t�d�| ���t�d
��W 5 d}~X Y n* tjk
�r t�d�t
|���Y nX dS )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)Ztimeout�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�tempfileZTemporaryDirectoryr
�subp�format�join�APT_HELPER_TIMEOUT�APT_RETRIESr
�ProcessExecutionErrorZ exit_code�str�stderr�lower�re�search�UserFacingError�
subprocessZTimeoutExpired)�repo_url�username�passwordZprotocol� repo_pathZtmpd�er+ r r r �assert_valid_apt_credentialsH sT
���
���� ��r6 )� apt_error�returnc C s� d}t � }| �� �d�D ]<}|rt�d|�}|rd|�� d �d�d }|�|� q|r�tjj t
|�dkrpd 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� )Zplural�failed_repos)
�set�stripr r- r. � groupdict�addr ZAPT_UPDATE_INVALID_URL_CONFIGr% �lenr&