%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_apt_configure.cpython-312.pyc

�

���fa��
��UdZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
ddlmZmZmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZej<e�Z dZ!dZ"d
Z#dZ$dZ%ddd�Z&e
e'e'fe(d<dddgegd�Z)ee(d<dZ*dZ+dZ,dZ-ddd�Z.d d d�Z/d!d"gZ0gd#�Z1d$Z2de2iZ3	dTd%�Z4d&e'd'ed(ed)e5d*df
d+�Z6d,�Z7d-�Z8d.�Z9d/�Z:d0�Z;d1�Z<d2�Z=d3�Z>d4�Z?d5e'd*e'fd6�Z@d*e'fd7�ZAd*e'fd8�ZBd9�ZCd:e'd*eDfd;�ZEd<d=d>d?�ZFd@ZGd*e
e'e'ffdA�ZHdB�ZIdUdC�ZJdD�ZKdVdE�ZL	dWdF�ZMdG�ZNdH�ZOdI�ZPdJ�ZQdK�ZRdL�ZSdM�ZTdN�ZUdO�ZVdTdP�ZWdQ�ZX				dXdR�ZYdSe<iZZy)Yz*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-common�gnupg)�add-apt-repository�gpg�PACKAGE_DEPENDENCY_BY_COMMAND�cc_apt_configure�ubuntu�debian)�id�distros�	frequency�activate_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-ports�amd64�i386)�s390x�arm64�armhf�powerpc�ppc64el�riscv64a# 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��|�tj�}|tvrtj	�S|t
vrtj	�Std|z��)z�returns the default mirrors for the target. These depend on the
    architecture, for more see:
    https://wiki.ubuntu.com/UbuntuDevelopment/PackageArchive#Portsz#No default mirror known for arch %s)r�get_dpkg_architecture�PRIMARY_ARCHES�PRIMARY_ARCH_MIRRORS�copy�PORTS_ARCHES�
PORTS_MIRRORS�
ValueError��archs �C/usr/lib/python3/dist-packages/cloudinit/config/cc_apt_configure.py�get_default_mirrorsr4UsV���|��)�)�+���~��#�(�(�*�*��|���!�!�#�#�
�:�T�A�
B�B��name�cfg�cloud�args�returnc��t|�}|jdi�}t|t�s$t	djt
|�����t|�t�5}t|||�ddd�y#1swYyxYw)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})�config_typeN)
�convert_to_v3_apt_format�get�
isinstance�dictr0�format�type�apply_debconf_selectionsr�	apply_apt)r6r7r8r9�apt_cfg�gpg_contexts      r3�handlerHds|��
#�3�
'�C��g�g�e�R� �G��g�t�$��
"�"(�&�T�'�]�&�"C�
�	
�
�W�%�	��/�+��'�5�+�.�/�/�/�s�'A>�>Bc��tj�rytjd�stjd�syy)N)Fzsystem is snappy.zapt-getr<)Fzno apt commands.)TzApt is available.)r�system_is_snappyr
�which�r5r3�_should_configure_on_empty_aptrMws.������)��J�J�y�!�T�Z�Z��%6�(�$r5c��|s&t�\}}|stjd|�ytjd|�tj�d}tj
�}t
|||��}tjd|�d}|jdt�}	|	rtj|	�j}t|||�tj|jdd��r't|||�t||||�t!||�	t#|t$t&�d
|vr#|}
||
d<|d|
d<t/|d
|||
|�
�yy#t(t*f$rtj-d	�Y�NwxYw)Nz#Nothing to do: No apt config and %szhandling apt config: %s�codenamer1zApt 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)rM�LOG�debugr�lsb_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)r7r8r�
should_config�msg�releaser2�mirrors�matcher�matchcfg�paramss           r3rErE�si���;�=��
�s���I�I�;�S�A���I�I�'��-���� ��,�G��%�%�'�D�"�3��D�9�G��I�I�#�W�-��G��w�w�+�-?�@�H���*�*�X�&�-�-����g�u�-��}�}�S�W�W�4�e�<�=���U�C�(��c�7�G�U�;���$�'�C���l�M�:�
�C����#��y��"�8�,��x����	�N���"�!�	
���	
�W��C��
�
�A�B�C�s�!E�$F�Fc�b�|jd�s|dz
}tjdg|d��y)N�
zdebconf-set-selectionsT��data�capture)�endswithr
)�
selectionss r3�debconf_set_selectionsry�s2�����u�%��e��
��I�I�	!�"�
��r5c�\�g}g}|D]P}|tvr5tjd|�t|�|j|��@|j|��Rt	|�rtjd|�t	|�r't
jddgt|�zdd��yy)Nzunconfiguring %szSThe following packages were installed and preseeded, but cannot be unconfigured: %szdpkg-reconfigurez--frontend=noninteractiveTrt)�CONFIG_CLEANERSrWrX�append�len�warningr
�list)�packages�	unhandled�	to_config�pkgs    r3�dpkg_reconfigurer��s����I��I��"���/�!��I�I�(�#�.��C� �"����S�!����S�!�
"��9�~����
-��	
��9�~��	�	�
�!<�=��9�o�
���		
�r5c��|jd�}|stjd�ydjt	|j��D�cgc]}||��	c}�}t
|j��t�}|j�D]T\}}|j�D]<}|jd�r�tjdd|�}|j|��>�Vtj �}	tjd|�|j#|	�}
t%|
�d	k(rtjd
�yt'|
�ycc}w)z2apply_debconf_selections - push content to debconf�debconf_selectionsz(debconf_selections was not set in configN�
�#z[:\s].*�z
pkgs_cfgd: %srzno need for reconfig)r?rWrX�join�sorted�keysry�encode�set�items�
splitlines�
startswithr\�sub�addr�get_installed_packages�intersectionr}r�)r7�selsets�keyrx�	pkgs_cfgd�_key�content�liner��pkgs_installed�
need_reconfigs           r3rDrD�s���g�g�*�+�G���	�	�<�=�����F�7�<�<�>�4J�K�S�G�C�L�K�L�J��:�,�,�.�/���I� �����
��g��&�&�(�	�D����s�#���&�&��R��.�C��M�M�#��		���0�0�2�N��I�I�o�y�)��*�*�>�:�M�
�=��Q���	�	�(�)���]�#��+Ls�Ec��tjtjd���}tj	d|�|D]}tj|��y)z%clean out any local cloud-init configz/etc/cloud/cloud.cfg.d/*dpkg*��pathz#cleaning cloud-init config from: %sN)�globr
�target_pathrWrX�os�unlink)�flist�dpkg_cfgs  r3�clean_cloud_initr��sF���I�I�d�&�&�,K�L�M�E��I�I�3�U�;����
�	�	�(��r5c��|}|jd�r|dd}|jd�}|dk\r||dzd}|jdd�}|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�_)rw�find�replace)�mirror�string�poss   r3�mirrorurl_to_apt_fileprefixr�sZ���F�
���s����"���
�+�+�e�
�C�
�a�x���a��	�"��
�^�^�C��
%�F��Mr5c�^�t|�}tjt�}|j	�D]�\}}|j|�}|s�|tjjzt|�z}|tjjzt|�z}||k(r�rt|�}	tjd|z�D]9}
|�|
|	d��}tjd|
|�	t
j|
|��;��y#t$rtj!dd��Y�awxYw)z>rename_apt_lists - rename apt lists to preserve old cache dataz%s_*NzRenaming apt list %s to %szFailed to rename apt list:T)�exc_info)r4r
r��	APT_LISTSr�r?r�r��sepr�r}r�rWrX�renamerhr~)�new_mirrorsr2�default_mirrors�prer6�omirror�nmirror�oprefix�nprefix�olen�filename�newnames            r3rcrcs��)�$�/�O�
�
�
�9�
%�C�(�.�.�0�I�
��g��/�/�$�'����������#�&A�'�&J�J��������#�&A�'�&J�J���g����7�|���	�	�&�7�"2�3�	I�H� '��$�%��9�G��I�I�2�H�g�F�
I��	�	�(�G�,�		I�I���
I����8�4��H�
I�s�.D	�	 D,�+D,c�F�dddddd�}	||}|S#t$r|}Y|SwxYw)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)�updates�	backports�security�proposedrm)�KeyError)�suite�mapping�retsuites   r3�map_known_suitesr�/sJ��
&�)�'�'���G���5�>���O�������O��s�� � �deb822_entryc��tjd|�sBtjdd|�}tjt�d|�}dt	|d�zS|S)z0If no active Suites, disable this deb822 source.z\nSuites:[ \t]+([\w-]+)z\nSuites:.*r�z7## Entry disabled by cloud-init, due to disable_suites
z# disabled by cloud-init: )r\�findallr��DISABLE_SUITES_REDACT_PREFIXr)r�s r3�%disable_deb822_section_without_suitesr�Asa��
�:�:�0�,�?��v�v�n�b�,�?���v�v�,�-��L�
��
G��\�#?�@�
A�	
��r5c���g}|D�cgc]#}tjt|�d|i���%}}tj	d||�d}|j�D]�}|j
d�r|r	||�d�z
}n|j|��1|r|j�r0|r|jt|��d}|j|��s|}|j
d�s	||dzz
}��|rM|j�dd}	|	D�cgc]}||vr|��
}
}|
|	k7r"|t�|�d�z
}d	d
j|
���}||dzz
}��|r|jt|��dj|�Scc}wcc}w)z:reads the deb822 format config and comment disabled suitesrSzDisabling suites %s as %sr�r�r�zSuites:�NzSuites: � )
r�
render_stringr�rWrXr�r�r|�isspacer��splitr�r�)�disabled�srcrm�new_srcr��disabled_suite_names�new_deb822_entryr��new_line�orig_suites�
new_suitess           r3�disable_suites_deb822r�Qs����G����	��� 0�� 7�)�W�9M�N�����I�I�)�8�5I�J������ � ,���?�?�3��� �t�f�B�K�/� ����t�$���t�|�|�~�����9�:J�K��$&� ��N�N�4� �������y�)���t��+�����*�*�,�q�r�*�K�)���� 4�4���J��
�[�(� �'C�&D�T�F�"�$M�M� �%�c�h�h�z�&:�%;�<���H�t�O�+��A ,�B����<�=M�N�O��9�9�W����S��<s�(E/�
E4c��|s|S|}t|�r
t|||�S|D]�}t|�}tj|d|i�}t
j
d||�d}|jd�D]�}|jd�r||z
}�|j�}t|�dkDrEd}	|djd�r"|dd	D]}
|	dz
}	|
jd
�s�n||	|k(rd|z}||z
}��|}��|S)zRreads the config for suites to be disabled and removes those
    from the templaterSzDisabling suite %s as %sr�Tr�r���[N�]z"# suite disabled by cloud-init: %s)�is_deb822_sources_formatr�r�rr�rWrXr�r�r�r}rw)r�r�rm�retsrcr��releasesuite�newsrcr��cols�pcol�cols           r3�disable_suitesr��s+����
�
�F���$�$�X�s�G�<�<���� ��'�� �.�.�u�y�'�6J�K���	�	�,�e�\�B����%�%�d�+�	�D����s�#��$����
�:�:�<�D��4�y�1�}�����7�%�%�c�*�#�A�B�x�"����	���<�<��,�!�"�
��:��-�?�$�F�D��d�N�F�'	�(��5�8�Mr5c�^�dD](}|j|g�D]}t||||����*y)z=Adds any keys included in the primary/security mirror clauses��primaryr�)�	file_nameN)r?�add_apt_key)r7r8rr�r�s     r3rara�s9��&�;���g�g�c�2�&�	;�F����s�c�:�	;�;r5�apt_src_contentc���tjd|tj�rytjd|tj�rytj	d�y)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.)r\r��MrWr~)r�s r3r�r��sO��
�z�z�%�����=��	�z�z�2�O�R�T�T����K�K�	H��r5zetc/apt�sources.listzsources.list.d)�Dir::Etc�Dir::Etc::sourcelist�Dir::Etc::sourcepartsz@(Dir::Etc|Dir::Etc::sourceparts|Dir::Etc::sourcelist) \"([^\"]+)c���	ddl}|j�|jjdtd�}|jjdtd�}|jjdtd�}d|�d|��d|�d|�d�d	�S#t
$r�	t
jddg�\}}nH#tj$r2td}td}td}d|�d|��d|�d|�d�d	�cYcYSwxYwtjt|�}t|�}|jdtd�}|jdtd�}|jdtd�}Y��wxYw)
aReturn 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.
    rNr�r�r�z
apt-config�dumpr�)�
sourcelist�sourceparts)�apt_pkg�init_config�configr?�DEFAULT_APT_CFG�ImportErrorr
�ProcessExecutionErrorr\r��
APT_CFG_RErA)r��etcr�r��apt_dumpr��matched_cfg�apt_cmd_configs        r3�get_apt_cfgr�s���$
�	������n�n� � ��_�Z�-H�I���^�^�'�'�"�O�4J�$K�
�
��n�n�(�(�#�_�5L�%M�
��2�#��a�
�|�,��3�%�q��
�Q�/����+�
�
	��)�)�\�6�$:�;�K�H�a���)�)�	�!�*�-�C�(�)?�@�J�)�*A�B�K� !�#��a�
�|�4�!"�3�%�q��
�Q�7��
�	���j�j��X�6���k�*��� � ��_�Z�-H�I��#�'�'�"�O�4J�$K�
�
�%�(�(�#�_�5L�%M�
��%
�s8�A=B�	E1�B6�5E1�6AC;�6E1�:C;�;A3E1�0E1c���t�}|d}|d�|jj�d�}tjr|}n|}||d�}|D] }	||	||	<||	||	j�<�"|j
dd�}
|
s�tjd�tjrdnd	}|jd
|jj�|���}|s|jd�}|stjd|�ytj|�}
tj|
|�}
|
rAt|
�r||k(r1tj!d
|�|}ntj!d|�|}t#|j
d�|
|�}tj$||d��||k(r�t&j(j+|�r�t,j
|jj�}|rJ|tj|�k7r1tjd|�tj$|t.�yytjd|�tj0|�yyy)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)rSrO�sources_listNz1No custom template provided, fall back to builtinz.deb822r�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�distror6r�APT_DEB822_SOURCE_LIST_FILE�lowerr?rW�info�get_template_filenamer~r�load_text_filerr�r�rXr��
write_filer�r��exists�DEB822_ALLOWED_APT_SOURCES_LIST�UBUNTU_DEFAULT_APT_SOURCES_LIST�del_file)r7rmrnr8rF�apt_sources_list�apt_sources_deb822�aptsrc_filerq�k�tmpl�tmpl_fmt�template_fn�renderedr��expected_contents                r3rbrbsE���m�G��|�,��#�M�2�3�E�L�L�4E�4E�3F�h�O���+�+�(��&�� �g�
6�F�
�'���A�J��q�	�#�A�J��q�w�w�y��'��7�7�>�4�(�D�����D�E� (� D� D�9�"���1�1��E�L�L�-�-�.�x�j�9�
����5�5�n�E�K���K�K�=�{�K���"�"�;�/���&�&�t�V�4�H��#�H�-��.�.��	�	�%�&��
1���I�I�"� �
�
+�K��c�g�g�&6�7��7�K�H��O�O�K���6��(�(�R�W�W�^�^�<L�-M�:�>�>��L�L���
����4�#6�#6�7G�#H�H����@�$�����$�&E��I�
�H�H�;�=M�
�
�M�M�*�+�#.N�(r5c���tjd|�	tj|�j}td||||��S#tj$rtjd��wxYw)zM
    actual adding of a key as defined in key argument
    to the system
    zAdding key:
'%s'r�)�output_fileru�hardenedz(failed to add apt GPG Key to apt keyring)	rWrX�pathlib�Path�stem�apt_keyr
rri)r�r�rr!r6s     r3�add_apt_key_rawr&Lsk��
�I�I�!�3�'���|�|�I�&�+�+����3�D�s�X�
�	
���%�%���
�
�@�A�
��s�.A�*A1c��g}t�}tj|jdd��rHdD]C}|j|�s�||D]'}ddhj	|�s�|jd��)�E|jdi�}|j
�D]P}ddhj	|�r|jd�||jdd	��s�@|jd
��R|D]0}	tj|	�r�|jt|	��2|r%|jjt|��yy)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.
    rQFr�r��keyidrrR�sourcer�rN)r�rr`r?r�r��values�shutilrKr|rr�install_packagesr�)
r7rVr8�missing_packages�
required_cmds�
mirror_key�mirror_item�apt_sources_dict�ent�commands
          r3r_r_\s=��#%��#&�5�M��}�}�S�W�W�4�e�<�=�1�	1�J��w�w�z�"�$'�z�?�1�K��w�'�4�4�[�A�%�)�)�%�0�1�		1��w�w�y�"�-���&�&�(�4���7��(�(��-����e�$������2�.�/����2�3�	4�
!�L���|�|�G�$��#�#�$A�'�$J�K�L��
���%�%�f�-=�&>�?�r5c��d|vr+d|vr't}d|vr|d}|j|d|�|d<d|vrt|d|xs|d||��Sy)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(r��	keyserverr��r!N)�DEFAULT_KEYSERVER�
getkeybyidr&)r2r8rr!r�r5s      r3r�r�~sp���#�~�%�s�*�%�	��#���K�(�I��^�^�C��L�)�<��E�
���|����J�	�4�S��_�c�H�
�	
�r5c��|�i}|�td��t|t�std|z��|D�]5}||}tjd|�d|vr||d<d|vrd|dvrt
|||d�	�}||d
<n
t
|||�d|vr�Z|d}tj||�}|djd�s&tjjd|d�|d<|djd
�s
|dxxd
z
cc<||�r	tjdd|g���tj"|d��}		d|z}
d}d|vr|dsd}t%j&|	|
|����8|j*j-d��y#tj$rtj!d��wxYw#t($r}tj!d|	|��d}~wwxYw)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_FILETr6�KEY_FILEr�z/etc/apt/sources.list.d/z.listrz--no-updatezadd-apt-repository failed.r�z%s
�ar|�w)�omodezfailed write to file %s: %s)�force)r0r@rA�	TypeErrorrWrXr�rr�r�r�r�r�rwr
rrir�rrrgr�update_package_sources)
�srcdictr8rrUrVr�r2�key_filer)�sourcefn�contentsr=�details
             r3rjrj�s��6�������;�<�<��g�t�$��0�G�<�=�=��-���h����	�	�*�C�0��S� �&�C�
�O��s�?�{�c�(�m�;�"�3��s�T�B�H�*2�O�J�'���U�C�(��3����X����(�(���A���:��)�)�#�.� �g�g�l�l�*�C�
�O��C�
�O��:��'�'��0��
�O�w�&�O��� �
��	�	�)�=�&�A��
��#�#��Z��9��
	���(�H��E��3��s�8�}����O�O�H�h�e�<�U-�^
�L�L�'�'�d�'�3�
��)�-�-�
��
�
�:�;��
���	��M�M�7��6�J���	�s$�F�>*F5�*F2�5	G�>G�Gc�$�i}tjddd��t|t�rHtjd�|D],}d|vrd|d<t
j|d�}n|d}|||<�.|St|t�r|}|Std��)	z1convert v1 apt format to v2 (dict in apt_sources)zConfig key 'apt_sources'�22.1zUse 'apt' instead)�
deprecated�deprecated_version�
extra_messagez9apt config: convert V1 to V2 format (source list to dict)r�zcloud_config_sources.listzunknown apt_sources format)
r	�	deprecater@rrWrXr�
rand_dict_keyrAr0)�srclistrA�srcentr�s    r3�convert_v1_to_v2_apt_formatrO�s����G�
���-�!�)��
�'�4� ��	�	�M�N��		"�F���'�&A��z�"��(�(��2M�N���Z�(��!�G�C�L�		"��N�
�G�T�	"����N��5�6�6r5c�X�|j|d��|j|�||<||=yy)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�newkeys    r3�convert_keyrVs4���z�z�&�$��+����F�+��v���6�N��r5c�b�gd�}d}ddgi}|D]\}}t||||�s�d}�|r|g|d<yy)zBconvert old apt_mirror keys into the new more advanced mirror spec))�
apt_mirror�uri)�apt_mirror_searchr^)�apt_mirror_search_dns�
search_dnsF�arches�defaultTr�N)rV)rRrS�keymap�	converted�newmcfgrTrUs       r3�convert_mirrorrbsX���F�
�I��)��%�G� ������v�w���7��I��
�$�I��y��r5c�L�ddddddddddd	d
�}g}|D]#}||vs�||dvr||=�|j|��%|s|Stjd|��d
��|jdd�}|�atjdd
��|D]C}||}||}||=|�|j|d���%|||k7s�.t	d|�d||�d|����|Si}|D]}||��	t|||||��t
||�|D]"}|j|d���t	d|z��||d<|S)z:convert old to new keys and adapt restructured mirror specrRN�proxy�
http_proxy�https_proxy�	ftp_proxyrQr	rP)�apt_sourcesrXrZr[�	apt_proxy�apt_http_proxy�
apt_ftp_proxy�apt_https_proxy�apt_preserve_sources_list�apt_custom_sources_listrP)Nr�zThe following config key(s): rG)rHrIr<z0Support for combined old and new apt module keysz3Old and New apt format defined with unequal values z vs z @ z&old apt key '%s' left after conversion)r|r	rKr?r0rVrb)rR�
mapoldkeys�
needtoconvertrT�	newaptcfgrU�verifyrSs        r3�convert_v2_to_v3_apt_formatrs!s���!��!�!%��&�&�&�%<�#1�2��J��M��-���V���f�~��+��6�N��$�$�V�,�-���
�
���2�=�/�B�!���
�
�5�$�'�I������I�%�	
�$�	�F���'�F��F�^�F��v���~����v�t�!<�!D����6�*�*� ��y��0�&�:���	��
��F��D���f��)�����
�6�0B�C�D�
�6�6�"��P���:�:�f�d�#�/��E��N�O�O�P�
�F�5�M��Mr5c�`�|jdd�}|�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'rhN)r?rOrs)r7rhs  r3r>r>ks:���'�'�-��.�K���8��E��M��&�c�
*�C��Jr5c���d}|r�d}g}|dk(rd}n|dk(rd}ntd��tj||�j}dj	|jd�d	d�}|r|j
d
|z�|jd�g}	|jj}
d|
�d
|�d�d|
��}|D]}|	j
||z��tj|	�}|S)zG
    Try to resolve a list of predefines DNS names to pick mirrors
    Nr�r�r�r�zsecurity-mirrorzunknown mirror type�.r�z.%s)z.localdomainr�zhttp://�-z%sr�)r0r�get_hostname_fqdn�fqdnr�r�r|�extendrr6�search_for_mirror)
�
configured�
mirrortyper7r8r��mydom�doms�	mirrordnsry�mirror_listr�	mirrorfmt�posts
             r3�search_for_mirror_dnsr�zs����F��������"� �I�
�:�
%�)�I��2�3�3��%�%�c�5�1�6�6��������C����,�-����K�K���
�&����
�	
������"�"��+1�9�d�F�K�	��	3�D����y�D�1�2�	3��'�'��4���Mr5c��|�	|�|}||d�S|jj�}|r"|j�}|d|d<|d|d<|St|�S)z^sets security mirror to primary if not defined.
    returns defaults if no mirrors are definedrr�rr�r )�
datasource�get_package_mirror_infor-r4)�pmirror�smirrorr2r8�mirror_info�ms      r3�update_mirror_infor��st�����?��G�"��8�8��"�"�:�:�<�K��
�������|��)���*�
��*�
����t�$�$r5c��|j|d�}|�yd}|D]&}|jd�xsg}||vr|cSd|vs�%|}�(|S)zuout of a list of potential mirror configurations select
    and return the one matching the architecture (or default)Nr]r^rQ)r7r}r2�mirror_cfg_listr^�mirror_cfg_elemr]s       r3�get_arch_mirrorconfigr��si���g�g�j�$�/�O�����G�*�&�� �$�$�X�.�4�"���6�>�"�"����%�G�&��Nr5c���t|||�}|�y|jdd�}|�%tj|jdd��}|�t	|jdd�|||�}|S)z�pass the three potential stages of mirror specification
    returns None is neither of them found anything otherwise the first
    hit is returnedNrYr^r\)r�r?rr{r�)r7r}r2r8�mcfgr�s      r3�
get_mirrorr��sz��!��j�$�7�D��|���X�X�e�T�
"�F��~��'�'�����4�(@�A���~�&��H�H�\�4�(�*�c�5�
���Mr5c��|�*tj�}tjd|�t	|d||�}tjd|�t	|d||�}tjd|�t||||�}|d|d<|S)afind_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
    z!got arch for mirror selection: %sr�zgot primary mirror: %sr�zgot security mirror: %srrT)rr*rWrXr�r�)r7r8r2r�r�r�s      r3rZrZ�s����|��)�)�+���	�	�5�t�<���i��u�5�G��I�I�&��0���j�$��6�G��I�I�'��1�$�W�g�t�U�C�K�(�	�2�K����r5c���d}|D��cgc]+\}}|j|�s�||j|�z��-}}}t|�r?tjd|�t	j
|dj
|�dz�nJtjj|�r+t	j|�tjd|�|jdd�r<tjd|�t	j
||jd��ytjj|�r,t	j|�tjd|�yycc}}w)	zHapply_apt_config
    Applies any apt*proxy config from if specified
    ))rd�Acquire::http::Proxy "%s";)rer�)rgzAcquire::ftp::Proxy "%s";)rfzAcquire::https::Proxy "%s";zwrite apt proxy info to %sr�z#no apt proxy configured, removed %s�confNzwrite apt config info to %sz$no apt config configured, removed %s)r?r}rWrXrrr�r�r��isfiler)r7�proxy_fname�config_fname�cfgsr6�fmt�proxiess       r3rdrds���
�D�7;�L�{��c�c�g�g�d�m�s�S�W�W�T�]�"�L�G�L�
�7�|��	�	�.��<�����T�Y�Y�w�%7�$�%>�?�	������	$��
�
�k�"��	�	�7��E�
�w�w�v�t���	�	�/��>�����c�g�g�f�o�6�	������	%��
�
�l�#��	�	�8�,�G�
&��Ms
�E)�E)c�������d�����fd�}��fd�}|dk(r||�S|dk(s|dk(r||�Std��)adapt-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��tjjt�rtgng}tjt
�D],}|j
d�s�|jt
|z��.|r|SdS)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.ascr�)r�r�r��APT_LOCAL_KEYS�listdir�APT_TRUSTED_GPG_DIRrwr|)�	key_files�files  r3�_get_key_fileszapt_key.<locals>._get_key_files/sf��)+�����~�(F�^�$�B�	��J�J�2�3�	=�D��}�}�-�.�� � �!4�t�!;�<�	=�&�y�-�2�-r5c����d}�s+tjtdj���|S	�rtnt
}|j
��}dj|��}tj||�|S#tj$r-tjtdj���Y|St$r-tjtdj���Y|SwxYw)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�logexcrWrB�CLOUD_INIT_GPG_DIRr��dearmorrr
r�UnicodeDecodeError)rGr��key_dir�stdoutrur!r s    ���r3�apt_key_addzapt_key.<locals>.apt_key_add>s����
 �	���K�K��@�G�G��M�
�&��
�*2�&�8K��%�,�,�T�2��&�-�-�g�{�C�	����	�6�2�����-�-�
�����;�B�B�4�H����	&�
�����>�E�E�d�K����	
�s�AA;�;<C/�:1C/�.C/c���g}��D]%}	|j|j|�����'dj
|�S#tj$r!}tjd||�Yd}~�hd}~wwxYw)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": %sNr�)r|�	list_keysr
rrWr~r�)rG�key_listrB�errorr�r�s    ��r3�apt_key_listzapt_key.<locals>.apt_key_listZs������&�(�	L�H�
L�����)�)�(��)�N��	L��y�y��"�"���-�-�
L����9�8�U�K�K��
L�s�"A�A8�A3�3A8r��fingerrz@apt_key() commands add, list, and finger are currently supported)r0)	r3rr rur!r�r�r�r�s	  ````  @r3r%r%sQ���&
.��8#� �%���3���	�H�	��6� 1��C� � ��N�
�	
r5z
cloud-init)N)F)FN)NN)NNFT)[�__doc__r��loggingr�r"r\r+�textwrapr�typingrrrr�	cloudinitrr	r
rr�cloudinit.cloudr
�cloudinit.configr�cloudinit.config.schemar�
cloudinit.gpgr�cloudinit.settingsr�	getLogger�__name__rWr[r�r�r�r�r�str�__annotations__rr�rfrer7r,r/r+r.rrr4rrHrMrEryr�rDr�r�rcr�r�r�r�ra�boolr�r�rrrbr&r_r�rjrOrVrbrsr>r�r�r�r�rZrdr%r{rLr5r3�<module>r�sl��1���	��	�
��0�0�@�@�!�#�.��+��g����!��#��'��/��1��G��7��4��w�s�C�x�0����(�#��!�	��j��
!�	�:�
�:��+��3�4���
6�6��
��6�"��K��#��$,�-L�"M��
�C�/��/�6�/�%�/�t�/��/�&%�+
�\�
�@ $�F��$I�2�$
��
��
� ,�S�,�^%�c�%�P;��c��d��4�*�-���H��
0�T�#�s�(�^�0�fC,�L
� @�D
�(>B�U�p�8�&�$G�T�&�R%�0�&�4�0H�>�	
�
��
U
�r�"��r5

Zerion Mini Shell 1.0