관리-도구
편집 파일: cc_apt_configure.cpython-39.pyc
a ����'�DgQ�����������������������@���s���U�d�Z�ddlZddlZddlZddlZddlZddlZddlmZ�ddl m Z mZmZm Z �ddlmZmZmZmZmZ�ddlmZ�ddlmZ�ddlmZ�dd lmZ�dd lmZ�e�e�Z dZ!dZ"d Z#dZ$dZ%ddd�Z&e e'e'f�e(d<�dddgeg�d�Z)ee(d<�dZ*dZ+dZ,dZ-ddd�Z.d d d�Z/d!d"gZ0g�d#�Z1d$Z2de2iZ3dud%d&�Z4e'eee5dd'�d(d)�Z6d*d+��Z7d,d-��Z8d.d/��Z9d0d1��Z:d2d3��Z;d4d5��Z<d6d7��Z=d8d9��Z>d:d;��Z?e'e'd<�d=d>�Z@e'd?�d@dA�ZAe'd?�dBdC�ZBdDdE��ZCe'eDdF�dGdH�ZEdIdJdKdL�ZFdMZGe e'e'f�d?�dNdO�ZHdPdQ��ZIdvdSdT�ZJdUdV��ZKdwdWdX�ZLdxdYdZ�ZMd[d\��ZNd]d^��ZOd_d`��ZPdadb��ZQdcdd��ZRdedf��ZSdgdh��ZTdidj��ZUdkdl��ZVdydmdn�ZWdodp��ZXdzdrds�ZYdte<iZZdS�){z*Apt Configure: Configure apt for the user.�����N)�indent)�Dict�Iterable�List�Mapping)�features� lifecycle�subp� templater�util)�Cloud)�Config)� MetaSchema)�GPG)�PER_INSTANCEz ^[\w-]+:\wz/etc/apt/trusted.gpgz/etc/apt/trusted.gpg.d/z/etc/apt/cloud-init.gpg.d/z&# cloud-init disable_suites redacted: zsoftware-properties-commonZgnupg)�add-apt-repository�gpg�PACKAGE_DEPENDENCY_BY_COMMANDZcc_apt_configureZubuntuZdebian)�idZdistrosZ frequencyZactivate_by_schema_keys�metaz/var/lib/apt/listsz'/etc/apt/apt.conf.d/94cloud-init-configz)/etc/apt/apt.conf.d/90cloud-init-aptproxyzkeyserver.ubuntu.comz!http://archive.ubuntu.com/ubuntu/z"http://security.ubuntu.com/ubuntu/��PRIMARY�SECURITYz$http://ports.ubuntu.com/ubuntu-portsZamd64Zi386)Zs390xZarm64ZarmhfZpowerpcZppc64elZriscv64a��# Ubuntu sources have moved to the /etc/apt/sources.list.d/ubuntu.sources # file, which uses the deb822 format. Use deb822-formatted .sources files # to manage package sources in the /etc/apt/sources.list.d/ directory. # See the sources.list(5) manual page for details. c�����������������C���s@���|�du�rt����}�|�tv�r t���S�|�tv�r0t���S�td|����dS�)z�returns the default mirrors for the target. These depend on the architecture, for more see: https://wiki.ubuntu.com/UbuntuDevelopment/PackageArchive#PortsNz#No default mirror known for arch %s)r����get_dpkg_architecture�PRIMARY_ARCHES�PRIMARY_ARCH_MIRRORS�copy�PORTS_ARCHES� PORTS_MIRRORS� ValueError��arch��r"����E/usr/lib/python3.9/site-packages/cloudinit/config/cc_apt_configure.py�get_default_mirrorsU���s����r$���)�name�cfg�cloud�args�returnc�����������������C���sp���t�|�}|�di��}t|t�s2tdjt|�d���t|��t���}t |||��W�d����n1�sb0����Y��dS�)z�process the config for apt_config. This can be called from curthooks if a global apt config was provided or via the "apt" standalone command.�aptz9Expected dictionary for 'apt' config, found {config_type})Zconfig_typeN) �convert_to_v3_apt_format�get� isinstance�dictr����format�type�apply_debconf_selectionsr���� apply_apt)r%���r&���r'���r(����apt_cfg�gpg_contextr"���r"���r#����handled���s���� ��r5���c�������������������C���s(���t����rdS�t�d�s$t�d�s$dS�dS�)N)Fzsystem is snappy.zapt-getr*���)Fzno apt commands.)TzApt is available.)r���Zsystem_is_snappyr ����whichr"���r"���r"���r#����_should_configure_on_empty_aptw���s ����r7���c�������������� ���C���s,��|�s"t���\}}|s"t�d|��d�S�t�d|���t���d�}t���}t|�||d�}t�d|��d�}|��dt�} | r|t � | �j}t|�||��t� |��dd��r�t|�||��t|�|||��t||��zt|�tt��W�n �ttfy����t�d ��Y�n0�d |�v��r(|} || d<�|d�| d<�t|�d �||| |d ��d�S�)Nz#Nothing to do: No apt config and %szhandling apt config: %s�codenamer ���zApt Mirror info: %s�add_apt_repo_match�preserve_sources_listFz)Failed to apply proxy or apt config info:�sources�RELEASE�MIRROR)�template_params� aa_repo_match)r7����LOG�debugr���Zlsb_releaser����find_apt_mirror_infor,����ADD_APT_REPO_MATCH�re�compile�search�_ensure_dependencies�is_false�add_mirror_keys�generate_sources_list�rename_apt_lists�apply_apt_config�APT_PROXY_FN� APT_CONFIG_FN�IOError�OSError� exception�add_apt_sources)r&���r'���r���Z should_config�msg�releaser!����mirrorsZmatcherZmatchcfg�paramsr"���r"���r#���r2�������sD���� �r2���c�����������������C���s(���|���d�s|�d7�}�tjdg|�dd��d�S�)N���� zdebconf-set-selectionsT��dataZcapture)�endswithr ���)� selectionsr"���r"���r#����debconf_set_selections����s���� �r\���c�����������������C���s����g�}g�}|�D�]8}|t�v�r:t�d|��t�|����|�|��q|�|��qt|�rZt�d|��t|�r~tjddgt|��d�dd��d�S�)Nzunconfiguring %szSThe following packages were installed and preseeded, but cannot be unconfigured: %szdpkg-reconfigurez--frontend=noninteractiveTrX���)�CONFIG_CLEANERSr@���rA����append�len�warningr ����list)ZpackagesZ unhandledZ to_config�pkgr"���r"���r#����dpkg_reconfigure����s*���� ���rc���c����������� ���������s����|���d�����st�d��dS�d���fdd�t������D���}t|�����t��}��� ��D�]:\}}|� ��D�](}|�d�rvqft� dd |�}|�|��qfqVt���}t�d |��|�|�}t|�dkr�t�d��dS�t|��dS�) z2apply_debconf_selections - push content to debconfZdebconf_selectionsz(debconf_selections was not set in configN� c��������������������s���g�|�]}��|��qS�r"���r"���)�.0�key�Zselsetsr"���r#���� <listcomp>���������z,apply_debconf_selections.<locals>.<listcomp>�#z[:\s].*��z pkgs_cfgd: %sr���zno need for reconfig)r,���r@���rA����join�sorted�keysr\����encode�set�items� splitlines� startswithrD����sub�addr���Zget_installed_packages�intersectionr_���rc���) r&���r[���Z pkgs_cfgdZ_keyZcontent�linerb���Zpkgs_installedZ need_reconfigr"���rg���r#���r1�������s(���� r1���c������������������C���s6���t���tjdd��}�t�d|���|�D�]}t�|��q"dS�)z%clean out any local cloud-init configz/etc/cloud/cloud.cfg.d/*dpkg*��pathz#cleaning cloud-init config from: %sN)�globr ����target_pathr@���rA����os�unlink)�flistZdpkg_cfgr"���r"���r#����clean_cloud_init����s����r���c�����������������C���sL���|�}|��d�r|dd��}|�d�}|dkr<||d�d��}|�dd�}|S�)z�mirrorurl_to_apt_fileprefix Convert a mirror url to the file prefix used by apt on disk to store cache information for that mirror. To do so do: - take off ???:// - drop tailing / - convert in string / to _�/r������z://����N�_)rZ����find�replace)�mirror�string�posr"���r"���r#����mirrorurl_to_apt_fileprefix��s���� r����c�������������� ���C���s����t�|�}t�t�}|���D�]�\}}|��|�}|s2q|tjj�t |��}|tjj�t |��}||krdqt |�} t�d|��D�]X} d|| | d��f�}t� d| |��zt�| |��W�qz�ty����tjddd��Y�qz0�qzqdS�)z>rename_apt_lists - rename apt lists to preserve old cache dataz%s_*z%s%sNzRenaming apt list %s to %szFailed to rename apt list:T)�exc_info)r$���r ���r{���� APT_LISTSrq���r,���r|���ry����sepr����r_���rz���r@���rA����renamerP���r`���)Znew_mirrorsr!���Zdefault_mirrorsZprer%���ZomirrorZnmirrorZoprefixZnprefixZolen�filenameZnewnamer"���r"���r#���rK�����s$���� rK���c�����������������C���s8���dddddd�}z||��}W�n�t�y2���|�}Y�n0�|S�)z�there are a few default names which will be auto-extended. This comes at the inability to use those names literally as suites, but on the other hand increases readability of the cfg quite a lotz$RELEASE-updatesz$RELEASE-backportsz$RELEASE-securityz$RELEASE-proposedz$RELEASE)ZupdatesZ backports�securityZproposedrT���)�KeyError)�suite�mappingZretsuiter"���r"���r#����map_known_suites/��s����� r����)�deb822_entryr)���c�����������������C���s<���t��d|��s8t��dd|��}�t��t��d|��}�dt|�d��S�|�S�)z0If no active Suites, disable this deb822 source.z\nSuites:[ \t]+([\w-]+)z\nSuites:.*rk���z7## Entry disabled by cloud-init, due to disable_suites z# disabled by cloud-init: )rD����findallrt����DISABLE_SUITES_REDACT_PREFIXr���)r����r"���r"���r#����%disable_deb822_section_without_suitesA��s�������r����)r)���c����������� ���������s$��g�}�fdd�|�D����t��d|�����d}|���D�]�}|�d�r^|rR||��d�7�}q0|�|��q0|rj|���r�|r�|�t|���d}|�|��q0|}|�d�s�||d�7�}q0��r�|���dd ��}��fd d�|D��}||kr�|t��|��d�7�}dd� |����}||d�7�}q0|�r|�t|���d� |�S�) z:reads the deb822 format config and comment disabled suitesc��������������������s ���g�|�]}t��t|�d���i��qS�)r<���)r ���� render_stringr�����re���r����)rT���r"���r#���rh���T��s����z)disable_suites_deb822.<locals>.<listcomp>zDisabling suites %s as %srk���rj���rd���zSuites:����Nc��������������������s���g�|�]}|��vr|�qS�r"���r"���r����)�disabled_suite_namesr"���r#���rh���r��s����zSuites: � ) r@���rA���rr���rs���r^����isspacer�����splitr����rl���) �disabled�srcrT���Znew_srcZnew_deb822_entryrw���Znew_lineZorig_suitesZ new_suitesr"���)r����rT���r#����disable_suites_deb822Q��sH���� � � �r����c�����������������C���s����|�s|S�|}t�|�r t|�||�S�|�D�]�}t|�}t�|d|i�}t�d||��d}|�d�D�]�}|�d�rt||7�}q\|� ��}t |�dkr�d} |d��d�r�|dd ��D�]} | d7�} | �d �r��q�q�|| �|kr�d|�}||7�}q\|}q$|S�)zRreads the config for suites to be disabled and removes those from the templater<���zDisabling suite %s as %srk���Trj���r���������[N�]z"# suite disabled by cloud-init: %s)�is_deb822_sources_formatr����r����r ���r����r@���rA���rr���rs���r����r_���rZ���)r����r����rT���Zretsrcr����ZreleasesuiteZnewsrcrw���ZcolsZpcol�colr"���r"���r#����disable_suites���s6���� r����c�����������������C���s0���dD�]&}|���|g��D�]}t||||d��qqdS�)z=Adds any keys included in the primary/security mirror clauses��primaryr����)� file_nameN)r,����add_apt_key)r&���r'���r���rf���r����r"���r"���r#���rI������s����rI���)�apt_src_contentr)���c�����������������C���s6���t��d|�t�j�rdS�t��d|�t�j�r(dS�t�d��dS�)a?��Simple check for deb822 format for apt source content Only validates that minimal required keys are present in the file, which indicates we are likely deb822 format. Doesn't handle if multiple sections all contain deb822 keys. Return True if content looks like it is deb822 formatted APT source. z^(deb |deb-src )Fz'^(Types: |Suites: |Components: |URIs: )Tzapt.sources_list value does not match either deb822 source keys or deb/deb-src list keys. Assuming APT deb/deb-src list format.)rD���r�����Mr@���r`���)r����r"���r"���r#���r�������s������r����zetc/apt�sources.listzsources.list.d)�Dir::Etc�Dir::Etc::sourcelist�Dir::Etc::sourcepartsz@(Dir::Etc|Dir::Etc::sourceparts|Dir::Etc::sourcelist) \"([^\"]+)c������������������C���s4��zJddl�}�|�����|�j�dtd��}|�j�dtd��}|�j�dtd��}W�n��t�y���zt�ddg�\}}W�nT�tjy����td�}td�}td�}d|��d|���d|��d|��d�d ��Y��Y�S�0�t� t |�}t|�}|�dtd��}|�dtd��}|�dtd��}Y�n0�d|��d|���d|��d|��d�d �S�) a��Return a dict of applicable apt configuration or defaults. Prefer python apt_pkg if present. Fallback to apt-config dump command if present out output parsed Fallback to DEFAULT_APT_CFG if apt-config command absent or output unparsable. r���Nr����r����r����z apt-config�dumpr����)� sourcelist�sourceparts)�apt_pkgZinit_configZconfigr,����DEFAULT_APT_CFG�ImportErrorr ����ProcessExecutionErrorrD���r����� APT_CFG_REr.���)r�����etcr����r����Zapt_dumpr����Zmatched_cfgZapt_cmd_configr"���r"���r#����get_apt_cfg���s@��������� �r����c�����������������C���s���t���}|d�}|d���|jj��d�}tjr0|}n|}||d�}|D�] } || �|| <�|| �|| ���<�qB|��dd�} | s�t�d��tjr�dnd }|� d |jj��|����}|s�|� d�}|s�t� d|��dS�t�|�} t �| |�} | �rt| ��r||k�rt�d |��|}nt�d|��|}t|��d�| |�}tj||dd��||k�r�tj�|��r�t�|jj�}|�r�|t�|�k�r�t�d|��t�|t��nt�d|��t�|��dS�)z�generate_sources_list create a source.list file based on a custom or default template by replacing mirrors and release in the templater����r����z.sources)r<���r8����sources_listNz1No custom template provided, fall back to builtinz.deb822rk���z sources.list.r����z#No template found, not rendering %szAProvided 'sources_list' user-data is deb822 format, writing to %szFProvided 'sources_list' user-data is not deb822 format, fallback to %sr����i���)�modez*Replacing %s to favor deb822 source formatz)Removing %s to favor deb822 source format)r�����distror%���r���ZAPT_DEB822_SOURCE_LIST_FILE�lowerr,���r@����infoZget_template_filenamer`���r���Zload_text_filer ���r����r����rA���r����� write_filer|���ry����exists�DEB822_ALLOWED_APT_SOURCES_LIST�UBUNTU_DEFAULT_APT_SOURCES_LIST�del_file)r&���rT���rU���r'���r3���Zapt_sources_listZapt_sources_deb822Zaptsrc_filerV����kZtmplZtmpl_fmtZtemplate_fnZrenderedr����Zexpected_contentr"���r"���r#���rJ�����sp���� � ������rJ���Fc�����������������C���sR���t��d|���z t�|�j}td|||�|d�W�S��tjyL���t��d����Y�n0�dS�)zM actual adding of a key as defined in key argument to the system zAdding key: '%s'ru���)�output_filerY����hardenedz(failed to add apt GPG Key to apt keyringN) r@���rA����pathlib�Path�stem�apt_keyr ���r����rQ���)rf���r����r���r����r%���r"���r"���r#����add_apt_key_rawL��s���� � r����c����������� ������C���s����g�}t���}t�|��dd��rVdD�]4}|��|�r |�|�D�]}ddh�|�r6|�d��q6q |��di��}|���D�]6}ddh�|�r�|�d��||�dd ��rj|�d ��qj|D�]} t�| �s�|� t | ���q�|r�|j�t |���dS�)a���Install missing package dependencies based on apt_sources config. Inspect the cloud config user-data provided. When user-data indicates conditions where add_apt_key or add-apt-repository will be called, ensure the required command dependencies are present installed. Perform this inspection upfront because it is very expensive to call distro.install_packages due to a preliminary 'apt update' called before package installation. r:���Fr����rf����keyidr���r;����sourcerk���r���N)rp���r���rH���r,���rv���ru����values�shutilr6���r^���r���r����Zinstall_packagesrm���) r&���r?���r'���Zmissing_packagesZ required_cmdsZ mirror_keyZmirror_itemZapt_sources_dict�ent�commandr"���r"���r#���rG���\��s&���� rG���c�����������������C���s`���d|�v�r8d|�vr8t�}d|�v�r$|�d�}|�|�d�|�|�d<�d|�v�r\t|�d�|pR|�d�||d�S�dS�)z� Add key to the system as defined in ent (if any). Supports raw keys or keyid's The latter will as a first step fetched to get the raw key r����rf���� keyserverr�����r����N)�DEFAULT_KEYSERVERZ getkeybyidr����)r����r'���r���r����r����r����r"���r"���r#���r����~��s�����r����c����������� ������C���s���|du�ri�}|du�rt�d��t|�t�s2td|����|�D��]�}|�|�}t�d|��d|vr`||d<�d|v�r�d|d�v�r�t|||dd �}||d <�nt|||��d|vr�q6|d�}t�||�}|d�� d�s�t j�d|d��|d<�|d�� d �s�|d��d 7��<�||��r>zt�dd|g��W�q6�tj�y:���t�d����Y�q60�q6tj|d�d�} z8d|�} d}d|v��rt|d��std}tj| | |d��W�q6�t�y��}�zt�d| |����W�Y�d}~q6d}~0�0�q6|jjdd��dS�)a��� install keys and repo source .list files defined in 'sources' for each 'source' entry in the config: 1. expand template variables and write source .list file in /etc/apt/sources.list.d/ 2. install defined keys 3. update packages via distro-specific method (i.e. apt-key update) @param srcdict: a dict containing elements required @param cloud: cloud instance object Example srcdict value: { 'rio-grande-repo': { 'source': 'deb [signed-by=$KEY_FILE] $MIRROR $RELEASE main', 'keyid': 'B59D 5F15 97A5 04B7 E230 6DCA 0620 BBCF 0368 3F77', 'keyserver': 'pgp.mit.edu' } } Note: Deb822 format is not supported Nz did not get a valid repo matcherzunknown apt format: %szadding source/key '%s'r����r����z $KEY_FILETr����ZKEY_FILEr����z/etc/apt/sources.list.d/z.listr���z--no-updatezadd-apt-repository failed.rx���z%s �ar^����w)�omodezfailed write to file %s: %s)�force)r���r-���r.���� TypeErrorr@���rA���r����r ���r����rs���r|���ry���rl���rZ���r ���r����rQ���r{���r���r����rO���r����Zupdate_package_sources) �srcdictr'���r���r>���r?���r����r�����key_filer����Zsourcefn�contentsr����Zdetailr"���r"���r#���rR������s\���� � � rR���c�����������������C���s~���i�}t�jdddd��t|�t�rbt�d��|�D�]2}d|vrNd|d<�t�|d�}n|d�}|||<�q,nt|�t�rr|�}nt d��|S�) z1convert v1 apt format to v2 (dict in apt_sources)zConfig key 'apt_sources'�22.1zUse 'apt' instead)� deprecated�deprecated_versionZ extra_messagez9apt config: convert V1 to V2 format (source list to dict)r����zcloud_config_sources.listzunknown apt_sources format) r���� deprecater-���ra���r@���rA���r���Z rand_dict_keyr.���r���)Zsrclistr����Zsrcentrf���r"���r"���r#����convert_v1_to_v2_apt_format���s$����� r����c�����������������C���s,���|���|d�dur(|���|�||<�|�|=�dS�dS�)ziconvert an old key to the new one if the old one exists returns true if a key was found and convertedNTF�r,���)�oldcfg�aptcfg�oldkey�newkeyr"���r"���r#����convert_key��s ����r����c�����������������C���sH���g�d�}d}ddgi}|D�]\}}t�|�|||�rd}q|rD|g|d<�dS�)zBconvert old apt_mirror keys into the new more advanced mirror spec))� apt_mirror�uri)�apt_mirror_searchrF���)�apt_mirror_search_dns� search_dnsF�arches�defaultTr����N)r����)r����r����ZkeymapZ convertedZnewmcfgr����r����r"���r"���r#����convert_mirror��s���� r����c�����������������C���sZ��ddddddddddd d �}g�}|D�]*}||�v�r$|�|�dv�rD|�|=�q$|��|��q$|sX|�S�tjd|���d d��|��dd�}|dur�tjdd d��|D�]V}||�}|�|�}|�|=�|du�s�|�|d�du�r�q�|||�kr�td|||�|f���q�|�S�i�}|D�]"}||�dur�t|�||||���q�t|�|��|D�]$}|��|d�du�r(td|����q(||�d<�|�S�)z:convert old to new keys and adapt restructured mirror specr;���N�proxy� http_proxy�https_proxy� ftp_proxyr:���r����r9���)�apt_sourcesr����r����r����Z apt_proxyZapt_http_proxyZ apt_ftp_proxyZapt_https_proxyZapt_preserve_sources_listZapt_custom_sources_listr9���)Nrk���zThe following config key(s): r����)r����r����r*���z0Support for combined old and new apt module keysz@Old and New apt format defined with unequal values %s vs %s @ %sz&old apt key '%s' left after conversion)r^���r���r����r,���r���r����r����)r����Z mapoldkeysZ needtoconvertr����Z newaptcfgr����Zverifyr����r"���r"���r#����convert_v2_to_v3_apt_format!��sj����� ���� r����c�����������������C���s,���|���dd�}|dur t|�|�d<�t|��}�|�S�)z�convert the old list based format to the new dict based one. After that convert the old dict keys/format to v3 a.k.a 'new apt config'r����N)r,���r����r����)r&���r����r"���r"���r#���r+���k��s ����r+���c����������� ������C���s����d}|�r�d}g�}|dkrd}n|dkr,d}nt�d��t�||�j}d�|�d�d d���}|rl|�d |���|�d��g�} |jj } d| |d | f�}|D�]}| �||���q�t� | �}|S�)zG Try to resolve a list of predefines DNS names to pick mirrors Nrk���r����r����r����zsecurity-mirrorzunknown mirror type�.r����z.%s)z.localdomainrk���zhttp://%s-%s%s/%sz%s)r���r���Zget_hostname_fqdn�fqdnrl���r����r^����extendr����r%����search_for_mirror) Z configured� mirrortyper&���r'���r����ZmydomZdomsZ mirrordnsr����Zmirror_listr����Z mirrorfmtZpostr"���r"���r#����search_for_mirror_dnsz��s.����� r����c�����������������C���sX���|�dur|du�r|�}|�|d�S�|j����}|rP|���}|d�|d<�|d�|d<�|S�t|�S�)z^sets security mirror to primary if not defined. returns defaults if no mirrors are definedNr���r����r���r����r���)Z datasourceZget_package_mirror_infor���r$���)�pmirror�smirrorr!���r'����mirror_info�mr"���r"���r#����update_mirror_info���s���� r��c�����������������C���sT���|���|d�}|du�rdS�d}|D�].}|��d�p0g�}||v�rB|��S�d|v�r |}q |S�)zuout of a list of potential mirror configurations select and return the one matching the architecture (or default)Nr����r����r����)r&���r����r!���Zmirror_cfg_listr����Zmirror_cfg_elemr����r"���r"���r#����get_arch_mirrorconfig���s����r��c�����������������C���s`���t�|�||�}|du�rdS�|�dd�}|du�r>t�|�dd��}|du�r\t|�dd�||�|�}|S�)z�pass the three potential stages of mirror specification returns None is neither of them found anything otherwise the first hit is returnedNr����rF���r����)r��r,���r���r����r����)r&���r����r!���r'���Zmcfgr����r"���r"���r#���� get_mirror���s�����r��c�����������������C���sn���|du�rt����}t�d|��t|�d||�}t�d|��t|�d||�}t�d|��t||||�}|d�|d<�|S�) a��find_apt_mirror_info find an apt_mirror given the cfg provided. It can check for separate config of primary and security mirrors If only primary is given security is assumed to be equal to primary If the generic apt_mirror is given that is defining for both Nz!got arch for mirror selection: %sr����zgot primary mirror: %sr����zgot security mirror: %sr���r=���)r���r���r@���rA���r��r��)r&���r'���r!���r����r����r���r"���r"���r#���rB������s����rB���c��������������������s����d}��fdd�|D��}t�|�rBt�d|��t�|d�|�d���n"tj�|�rdt� |��t�d|����� dd�r�t�d |��t�|��� d���n"tj�|�r�t� |��t�d |��dS�)zHapply_apt_config Applies any apt*proxy config from if specified ))r�����Acquire::http::Proxy "%s";)r����r��)r����zAcquire::ftp::Proxy "%s";)r����zAcquire::https::Proxy "%s";c��������������������s(���g�|�] \}}����|�r|����|���qS�r"���r����)re���r%����fmt�r&���r"���r#���rh�����ri���z$apply_apt_config.<locals>.<listcomp>zwrite apt proxy info to %srd���z#no apt proxy configured, removed %sZconfNzwrite apt config info to %sz$no apt config configured, removed %s)r_���r@���rA���r���r����rl���r|���ry����isfiler����r,���)r&���Zproxy_fnameZconfig_fnameZcfgsZproxiesr"���r��r#���rL������s���� rL���Tc��������������������sZ���dd�������fdd�}���fdd�}|�dkr6||�S�|�dksF|�d krN||�S�t�d ��dS�)ad��apt-key replacement commands implemented: 'add', 'list', 'finger' @param output_file: name of output gpg file (without .gpg or .asc) @param data: key contents @param human_output: list keys formatted for human parsing @param hardened: write keys to to /etc/apt/cloud-init.gpg.d/ (referred to with [signed-by] in sources file) c������������������S���sJ���t�j�t�rtgng�}�t��t�D�]}|�d�r |��t|���q |�rF|�S�dS�)z�return all apt keys /etc/apt/trusted.gpg (if it exists) and all keyfiles (and symlinks to keyfiles) in /etc/apt/trusted.gpg.d/ are returned based on apt-key implementation )z.gpgz.ascrk���)r|���ry���r���APT_LOCAL_KEYS�listdir�APT_TRUSTED_GPG_DIRrZ���r^���)Z key_files�filer"���r"���r#����_get_key_files/��s ���� zapt_key.<locals>._get_key_filesc�������������� ������s����d}�st��td������n|z2�r&tnt}|�����}d�|��}t��||��W�nH�tj yt���t��td������Y�n$�t y����t��td������Y�n0�|S�)ziapt-key add <file> returns filepath to new keyring, or '/dev/null' when an error occurs z /dev/nullz)Unknown filename, failed to add key: "{}"z{}{}.gpgz Gpg error, failed to add key: {}z#Decode error, failed to add key: {})r���Zlogexcr@���r/����CLOUD_INIT_GPG_DIRr��Zdearmorr����r ���r�����UnicodeDecodeError)r4���r����Zkey_dir�stdout)rY���r����r����r"���r#����apt_key_add>��s(���� � � � � zapt_key.<locals>.apt_key_addc��������������������sh���g�}����D�]R}z|��|�j|�d���W�q �tjyZ�}�zt�d||��W�Y�d}~q d}~0�0�q d�|�S�)zapt-key list returns string of all trusted keys (in /etc/apt/trusted.gpg and /etc/apt/trusted.gpg.d/) )�human_outputzFailed to list key "%s": %sNrd���)r^���Z list_keysr ���r����r@���r`���rl���)r4���Zkey_listr�����error)r ��r��r"���r#����apt_key_listZ��s���� �&zapt_key.<locals>.apt_key_listru���Zfingerra���z@apt_key() commands add, list, and finger are currently supportedN)r���)r����r���r����rY���r����r��r��r��r"���)r ��rY���r����r��r����r#���r������s�����r����z cloud-init)N)F)FN)NN)N)NNFT)[�__doc__rz���Zloggingr|���r����rD���r�����textwrapr����typingr���r���r���r���Z cloudinitr���r���r ���r ���r���Zcloudinit.cloudr���Zcloudinit.configr ���Zcloudinit.config.schemar���Z cloudinit.gpgr���Zcloudinit.settingsr���Z getLogger�__name__r@���rC���r ��r��r��r����r����str�__annotations__r���r����rN���rM���r����r���r���r���r���r����r����r$���ra���r5���r7���r2���r\���rc���r1���r���r����rK���r����r����r����r����rI����boolr����r����r����r����rJ���r����rG���r����rR���r����r����r����r����r+���r����r��r��r��rB���rL���r����r]���r"���r"���r"���r#����<module> ���s���� �� �� �� . # /(��3F " �� X J) ����� Y�