HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_apt_configure.cpython-311.pyc
�

���f;���h�UdZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddl	mZm
Z
mZddlmZdd	lmZdd
lmZmZddlmZeje��adZd
ZdZdZeZddgZ ddded��e ed��gegd�Z!ee"d<ee!��ZdZ#dZ$dZ%dZ&ddd�Z'd d d�Z(d!d"gZ)gd#�Z*dMd$�Z+d%e,d&ed'ed(ed)e-d*dfd+�Z.d,�Z/d-�Z0dNd.�Z1dNd/�Z2dNd0�Z3d1�Z4d2�Z5d3�Z6d4�Z7d5�Z8d6�Z9d7�Z:d8�Z;d9�Z<dOd;�Z=dPd<�Z>d=�Z?	dQd>�Z@d?�ZAd@�ZBdA�ZCdB�ZDdC�ZEdD�ZFdE�ZGdF�ZHdG�ZIdNdH�ZJdI�ZK	dRdK�ZLdLe4iZMdS)Sz*Apt Configure: Configure apt for the user.�N)�Logger)�dedent)�gpg)�log)�subp�	templater�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCEz
^[\w-]+:\wz/etc/apt/trusted.gpgz/etc/apt/trusted.gpg.d/z/etc/apt/cloud-init.gpg.d/�ubuntu�debian�cc_apt_configurez
Apt ConfigurezConfigure apt for the usera�        This module handles both configuration of apt options and adding
        source lists.  There are configuration options such as
        ``apt_get_wrapper`` and ``apt_get_command`` that control how
        cloud-init invokes apt-get. These configuration options are
        handled on a per-distro basis, so consult documentation for
        cloud-init's distro support for instructions on using
        these config options.

        .. note::
            To ensure that apt configuration is valid yaml, any strings
            containing special characters, especially ``:`` should be quoted.

        .. note::
            For more information about apt configuration, see the
            ``Additional apt configuration`` example.a-	        apt:
          preserve_sources_list: false
          disable_suites:
            - $RELEASE-updates
            - backports
            - $RELEASE
            - mysuite
          primary:
            - arches:
                - amd64
                - i386
                - default
              uri: 'http://us.archive.ubuntu.com/ubuntu'
              search:
                - 'http://cool.but-sometimes-unreachable.com/ubuntu'
                - 'http://us.archive.ubuntu.com/ubuntu'
              search_dns: false
            - arches:
                - s390x
                - arm64
              uri: 'http://archive-to-use-for-arm64.example.com/ubuntu'

          security:
            - arches:
                - default
              search_dns: true
          sources_list: |
              deb $MIRROR $RELEASE main restricted
              deb-src $MIRROR $RELEASE main restricted
              deb $PRIMARY $RELEASE universe restricted
              deb $SECURITY $RELEASE-security multiverse
          debconf_selections:
              set1: the-package the-package/some-flag boolean true
          conf: |
              APT {
                  Get {
                      Assume-Yes 'true';
                      Fix-Broken 'true';
                  }
              }
          proxy: 'http://[[user][:pass]@]host[:port]/'
          http_proxy: 'http://[[user][:pass]@]host[:port]/'
          ftp_proxy: 'ftp://[[user][:pass]@]host[:port]/'
          https_proxy: 'https://[[user][:pass]@]host[:port]/'
          sources:
              source1:
                  keyid: 'keyid'
                  keyserver: 'keyserverurl'
                  source: 'deb [signed-by=$KEY_FILE] http://<url>/ bionic main'
              source2:
                  source: 'ppa:<ppa-name>'
              source3:
                  source: 'deb $MIRROR $RELEASE multiverse'
                  key: |
                      ------BEGIN PGP PUBLIC KEY BLOCK-------
                      <key data>
                      ------END PGP PUBLIC KEY BLOCK-------
              source4:
                  source: 'deb $MIRROR $RELEASE multiverse'
                  append: false
                  key: |
                      ------BEGIN PGP PUBLIC KEY BLOCK-------
                      <key data>
                      ------END PGP PUBLIC KEY BLOCK-------)�id�name�title�description�distros�examples�	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�riscv64c���|�tj|��}|tvrt���S|t
vrt���Std|z���)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�targets  �C/usr/lib/python3/dist-packages/cloudinit/config/cc_apt_configure.py�get_default_mirrorsr1�sg���|��)�&�1�1���~���#�(�(�*�*�*��|����!�!�#�#�#�
�:�T�A�
B�
B�B�r�cfg�cloudr�args�returnc�(�d}|�|at|��}|�di��}t|t��s0td�t|��������t||��t|||��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.N�aptz9Expected dictionary for 'apt' config, found {config_type})�config_type)
�LOG�convert_to_v3_apt_format�get�
isinstance�dictr-�format�type�apply_debconf_selections�	apply_apt)rr3r4rr5r/�apt_cfgs       r0�handlerD�s����F�
����
"�3�
'�
'�C��g�g�e�R� � �G��g�t�$�$�
��G�N�N� ��M�M�
O�
�
�
�
�	
��W�f�-�-�-�
�g�u�f�%�%�%�%�%r2c��tj��rdStjd��stjd��sdSdS)N)Fzsystem is snappy.zapt-getr8)Fzno apt commands.)TzApt is available.)r	�system_is_snappyr�which�r2r0�_should_configure_on_empty_aptrI�sH������*�)�)��J�y�!�!�)�T�Z��%6�%6�)�(�(�$�$r2c���|s0t��\}}|st�d|��dSt�d|��tj|���d}tj|��}t
|||���}t�d|��tj|�dd����rt|||��n[tj
|�d	d����r3t||��t||||��t|||��	t|tt ��n1#t"t$f$rt�d
��YnwxYwd|vrf|}||d<|d
|d
<d}	|�dt(��}
|
rt+j|
��j}	t1|d||||	���dSdS)Nz#Nothing to do: No apt config and %szhandling apt config: %s�r/�codename)r.zApt Mirror info: %s�generate_mirrorlistsF�preserve_sources_listz)Failed to apply proxy or apt config info:�sources�RELEASE�MIRROR�add_apt_repo_match)r/�template_params�
aa_repo_match)rIr:�debugr	�lsb_releaser'�find_apt_mirror_info�is_truer<rM�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_REPO_MATCH�re�compile�search�add_apt_sources)r3r4r/�
should_config�msg�releaser.�mirrors�params�matcher�matchcfgs           r0rBrB�s"����;�=�=��
�s��	��I�I�;�S�A�A�A��F��I�I�'��-�-�-���f�-�-�-�j�9�G��%�f�-�-�D�"�3��D�9�9�9�G��I�I�#�W�-�-�-��|�C�G�G�2�E�:�:�;�;�0��S�'�5�1�1�1�1�	
��s�w�w�6��>�>�	?�	?�0���V�$�$�$��c�7�G�U�;�;�;���&�$�/�/�/�C���l�M�:�:�:�:���W��C�C�C��
�
�A�B�B�B�B�B�C�����C�����#��y��"�8�,��x�����7�7�/�1C�D�D���	2��j��*�*�1�G���	�N���"�!�	
�	
�	
�	
�	
�	
��s�E�+F
�	F
c�l�|�d��s|dz
}tjdg||d���dS)N�
zdebconf-set-selectionsT��datar/�capture)�endswithr)�
selectionsr/s  r0�debconf_set_selectionsrvsT�����u�%�%���e��
��I�	!�"�
���	�����r2c��g}g}|D]f}|tvrFt�d|��t||��|�|���Q|�|���gt	|��rt�d|��t	|��r,t
jddgt|��zd|d���dSdS)Nzunconfiguring %szSThe following packages were installed and preseeded, but cannot be unconfigured: %szdpkg-reconfigurez--frontend=noninteractiveTrq)�CONFIG_CLEANERSr:rU�append�len�warningr�list)�packagesr/�	unhandled�	to_config�pkgs     r0�dpkg_reconfigurer�s���I��I��"�"���/�!�!��I�I�(�#�.�.�.��C� ��(�(�(����S�!�!�!�!����S�!�!�!�!�
�9�~�~�
����
-��	
�	
�	
��9�~�~�
��	�
�!<�=��9�o�o�
����	
�	
�	
�	
�	
�	
�
�
r2c�<�
�|�d���
�
st�d��dSd��
fd�t	�
�����D����}t
|���|���t��}�
�	��D]]\}}|�
��D]C}|�d��r�tj
dd	|��}|�|���D�^tj|��}t�d
|��|�|��}	t%|	��dkrt�d��dSt'|	|���dS)
z2apply_debconf_selections - push content to debconf�debconf_selectionsz(debconf_selections was not set in configN�
c� ��g|]
}�|��SrHrH)�.0�key�selsetss  �r0�
<listcomp>z,apply_debconf_selections.<locals>.<listcomp>7s���K�K�K�S�G�C�L�K�K�Kr2rK�#z[:\s].*�z
pkgs_cfgd: %srzno need for reconfig)r<r:rU�join�sorted�keysrv�encode�set�items�
splitlines�
startswithrd�sub�addr	�get_installed_packages�intersectionrzr�)r3r/ru�	pkgs_cfgd�_key�content�liner��pkgs_installed�
need_reconfigr�s          @r0rArA,s�����g�g�*�+�+�G����	�	�<�=�=�=������K�K�K�K�F�7�<�<�>�>�4J�4J�K�K�K�L�L�J��:�,�,�.�.�v�>�>�>�>����I� �������
��g��&�&�(�(�	�	�D����s�#�#�
���&��R��.�.�C��M�M�#�����		��0��8�8�N��I�I�o�y�)�)�)��*�*�>�:�:�M�
�=���Q����	�	�(�)�)�)����]�6�2�2�2�2�2�2r2c��tjtj|d����}t�d|��|D]}tj|���dS)z%clean out any local cloud-init configz/etc/cloud/cloud.cfg.d/*dpkg*z#cleaning cloud-init config from: %sN)�globr�target_pathr:rU�os�unlink)r/�flist�dpkg_cfgs   r0�clean_cloud_initr�Osg���I����!@�A�A�
�
�E��I�I�3�U�;�;�;�����
�	�(������r2c���|}|�d��r
|dd�}|�d��}|dkr
||dzd�}|�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�_)rt�find�replace)�mirror�string�poss   r0�mirrorurl_to_apt_fileprefixr�Zsn���F�
���s������"����
�+�+�e�
�
�C�
�a�x�x���a��	�	�"��
�^�^�C��
%�
%�F��Mr2c��t|��}tj|t��}|���D�]\}}|�|��}|s�|tjjzt|��z}|tjjzt|��z}	||	kr�mt|��}
tjd|z��D]n}|	�||
d���}t�
d||��	t
j||���C#t$rt�dd���Y�kwxYw��dS)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)r1rr��	APT_LISTSr�r<r��path�sepr�rzr�r:rU�renamerar{)
�new_mirrorsr/r.�default_mirrors�prer�omirror�nmirror�oprefix�nprefix�olen�filename�newnames
             r0r\r\lse��)�$�/�/�O�
�
�6�9�
-�
-�C�*�0�0�2�2�I�I���w��/�/�$�'�'���	������#�&A�'�&J�&J�J������#�&A�'�&J�&J�J���g�����7�|�|���	�&�7�"2�3�3�	I�	I�H� '���$�%�%���9�G��I�I�2�H�g�F�F�F�
I��	�(�G�,�,�,�,���
I�
I�
I����8�4��H�H�H�H�H�
I����	I�I�Is�>D�&D=�<D=c�n�||vrt�d||��|�||��S)z�mirror_to_placeholder
    replace the specified mirror in a template with a placeholder string
    Checks for existance of the expected mirror and warns if not foundz%Expected mirror '%s' not found in: %s)r:r{r�)�tmplr��placeholders   r0�mirror_to_placeholderr��s:���T������;�V�T�J�J�J��<�<���,�,�,r2c�N�dddddd�}	||}n#t$r|}YnwxYw|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)�updates�	backports�security�proposedrj)�KeyError)�suite�mapping�retsuites   r0�map_known_suitesr��sX��
&�)�'�'����G���5�>�����������������Os��"�"c��|s|S|}|D]�}t|��}tj|d|i��}t�d||��d}|�d��D]�}|�d��r||z
}�|���}t|��dkrWd}	|d�d��r)|dd	�D]}
|	dz
}	|
�	d
��rn�||	|krd|z}||z
}��|}��|S)zRreads the config for suites to be disabled and removes those
    from the templaterPzDisabling suite %s as %sr�Tr����[N�]z"# suite disabled by cloud-init: %s)
r�r�
render_stringr:rUr�r��splitrzrt)�disabled�srcrj�retsrcr��releasesuite�newsrcr��cols�pcol�cols           r0�disable_suitesr��sO�����
�
�F����� ��'�'�� �.�u�y�'�6J�K�K���	�	�,�e�\�B�B�B����%�%�d�+�+�	�	�D����s�#�#�
��$����
�:�:�<�<�D��4�y�y�1�}�}�����7�%�%�c�*�*�"�#�A�B�B�x�"�"����	���<�<��,�,�"�!�E�"���:��-�-�?�$�F�D��d�N�F�F�����Mr2c�f�dD]-}|�|g��D]}t|||�����.dS)z=Adds any keys included in the primary/security mirror clauses)�primaryr�)�	file_nameN)r<�add_apt_key)r3r/r�r�s    r0rZrZ�sU��&�7�7���g�g�c�2�&�&�	7�	7�F����#�6�6�6�6�6�	7�7�7r2c�H�d}||d�}|D]*}||||<||||���<�+|�dd��}|��t�d��|�d|jjz��}|s|�d��}|st�d��dStj	|��}tj||��}	t|�d	��|	|��}
tj
||
d
���dS)z�generate_sources_list
    create a source.list file based on a custom or default template
    by replacing mirrors and release in the templatez/etc/apt/sources.list)rPrL�sources_listNz1No custom template provided, fall back to builtinzsources.list.%szsources.listz6No template found, not rendering /etc/apt/sources.listr����mode)�lowerr<r:�info�get_template_filename�distrorr{r	�	load_filerr�r��
write_file)r3rjrkr4�aptsrcrl�kr��template_fn�renderedr�s           r0r[r[�s:��%�F� �g�
6�
6�F�
�'�'���A�J��q�	�#�A�J��q�w�w�y�y����7�7�>�4�(�(�D��|����D�E�E�E��1�1����!2�3�
�
���	F��5�5�n�E�E�K��	��K�K�H�
�
�
�
�F��~�k�*�*���&�t�V�4�4�H��c�g�g�&6�7�7��7�K�K�H��O�F�H�5�1�1�1�1�1�1r2c�d�tjd��}tjt	|����tjt	||jj�d�z��|d�d�d���tjt	||jj�d�z��|d�d�d���d	S)
zUgenerate_mirrorlists
    create one file for every mirror for apt-transport-mirror(1)z/etc/apt/mirrors�.listrr�r�r�z-security.listrN)�pathlib�Pathr	�
ensure_dir�strr�r�r)r3rkr4�aptmirs    r0rMrM�s����\�,�
-�
-�F��O�C��K�K� � � ��O��F���)�0�0�0�0�1�1��9��!�!�!�
�����
	�O��F���)�9�9�9�9�:�:��:��"�"�"�
������r2Fc���t�d|��	tj|��j}td|||���S#tj$rt�d���wxYw)zM
    actual adding of a key as defined in key argument
    to the system
    zAdding key:
'%s'r�)�output_filerr�hardenedz(failed to add apt GPG Key to apt keyring)	r:rUr�r��stem�apt_keyr�ProcessExecutionErrorrb)r�r�r�r/rs     r0�add_apt_key_rawr��s{��
�I�I�!�3�'�'�'���|�I�&�&�+���u�$�S�8�L�L�L�L���%�����
�
�@�A�A�A�
����s�+A	�	+A4c��d|vr5d|vr1t}d|vr|d}tj|d|��|d<d|vr t|d|p|d|���SdS)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
    �keyidr��	keyserverr��r�N)�DEFAULT_KEYSERVERr�
getkeybyidr�)�entr/r�r�rs     r0r�r�
s����#�~�~�%�s�*�*�%�	��#����K�(�I��^�C��L�)�<�<��E�
���|�|����J�	�4�S��_�x�
�
�
�	
��|r2c�8�|j���dS�N)r��update_package_sources)r4s r0�update_packagesr
s��	�L�'�'�)�)�)�)�)r2c�*�|�i}|�td���t|t��std|z���|D�]�}||}t�d|��d|vr||d<d|vr"d|dvrt
||d�	��}||d
<nt
||��}d|vr�j|d}tj||��}|d�	d��s)tj�d|d��|d<|d�
d
��s|dxxd
z
cc<||��rK	tjdd|g|���n.#tj$rt�d���wxYw��Ltj||d��}		d|z}
d}d|vr
|dsd}t%j|	|
|������#t($r"}t�d|	|���d}~wwxYwt+|��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��sourcez	$KEY_FILETr�KEY_FILEr�z/etc/apt/sources.list.d/r�zadd-apt-repositoryz--no-updaterKzadd-apt-repository failed.z%s
�ary�w)�omodezfailed write to file %s: %s)r-r=r>�	TypeErrorr:rUr�rr�r�r�r�r�rtrr�rbr�r	r�r`r
)
�srcdictr4r/rSrTr�r�key_filer�sourcefn�contentsr�details
             r0rgrg!s���6�������;�<�<�<��g�t�$�$�>��0�G�<�=�=�=��.�.���h����	�	�*�C�0�0�0��S� � �&�C�
�O��s�?�?�{�c�(�m�;�;�"�3���>�>�>�H�*2�O�J�'�'�"�3��/�/�H��3�����X����(���A�A���:��)�)�#�.�.�	� �g�l�l�*�C�
�O���C�
�O��:��'�'��0�0�	'��
�O�O�O�w�&�O�O�O��=�� � �		�
��	�)�=�&�A�!��������-�
�
�
��
�
�:�;�;�;��
����
��#�F�C�
�O�<�<��
	���(�H��E��3���s�8�}�����O�H�h�e�<�<�<�<�<���	�	�	��M�M�7��6�J�J�J������	�����E����
�Fs$�E�+F�',G�
H�G<�<Hc�N�i}t�d��t|t��rLt�d��|D].}d|vrd|d<tj|d��}n|d}|||<�/n't|t��r|}ntd���|S)z1convert v1 apt format to v2 (dict in apt_sources)zIDEPRECATION: 'apt_sources' deprecated config key found. Use 'apt' insteadz9apt config: convert V1 to V2 format (source list to dict)r�zcloud_config_sources.listzunknown apt_sources format)	r:r{r=r|rUr	�
rand_dict_keyr>r-)�srclistr�srcentr�s    r0�convert_v1_to_v2_apt_formatrzs����G��K�K�	�����'�4� � �7��	�	�M�N�N�N��		"�		"�F���'�'�&A��z�"��(��2M�N�N����Z�(��!�G�C�L�L�		"�
�G�T�	"�	"�7�����5�6�6�6��Nr2c�l�|�|d���|�|��||<||=dSdS)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    r0�convert_keyr"�s>���z�z�&�$���+����F�+�+��v���6�N��t��5r2c�h�gd�}d}ddgi}|D]\}}t||||��rd}�|r|g|d<dSdS)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")rr�keymap�	converted�newmcfgr r!s       r0�convert_mirrorr.�s{�����F�
�I��)��%�G� �������v�w���7�7�	��I���&�$�I��y����&�&r2c���ddddddddddd	d
�}g}|D])}||vr#||dvr||=�|�|���*|s|St�dd
�|����|�dd��}|�wt�d��|D]X}||}||}||=|�|�|d����.|||krtd|�d||�d|������Y|Si}|D]"}||�t
|||||���#t||��|D]*}|�|d���td|z����+||d<|S)z:convert old to new keys and adapt restructured mirror specrON�proxy�
http_proxy�https_proxy�	ftp_proxyrNr�rR)�apt_sourcesr$r&r'�	apt_proxy�apt_http_proxy�
apt_ftp_proxy�apt_https_proxy�apt_preserve_sources_list�apt_custom_sources_listrR)Nr�zdDEPRECATION apt: converted deprecated config V2 to V3 format for keys '%s'. Use updated config keys.z, r8zODEPRECATION: apt config: deprecated V1/2 and V3 format specified, preferring V3z3Old and New apt format defined with unequal values z vs z @ z&old apt key '%s' left after conversion)ryr:r{r�r<r-r"r.)r�
mapoldkeys�
needtoconvertr �	newaptcfgr!�verifyrs        r0�convert_v2_to_v3_apt_formatr?�s"��!��!�!%��&�&�&�%<�#1�2���J��M��-�-���V����f�~��+�+��6�N�N��$�$�V�,�,�,�����
��K�K�	/��	�	�-� � �����
�
�5�$�'�'�I������
�	
�	
�	
�$�	�	�F���'�F��F�^�F��v���~����v�t�!<�!<�!D����6�*�*�*� �j��v�v�y��0�0�0�&�&�:����+��
��F��D�D���f��)�����
�6�0B�C�C�C���6�6�"�"�"��P�P���:�:�f�d�#�#�/��E��N�O�O�O�0��F�5�M��Mr2c�x�|�dd��}|�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'r4N)r<rr?)r3r4s  r0r;r;�sC���'�'�-��.�.�K���8��E�E��M��&�c�
*�
*�C��Jr2c���d}|r�d}g}|dkrd}n|dkrd}ntd���tj||��j}d�|�d��d	d���}|r|�d
|z��|�d��g}	|jj	}
d|
�d
|�d�d|
��}|D]}|	�||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�)r-r	�get_hostname_fqdn�fqdnr�r�ry�extendr�r�search_for_mirror)
�
configured�
mirrortyper3r4r��mydom�doms�	mirrordnsrE�mirror_listr��	mirrorfmt�posts
             r0�search_for_mirror_dnsrPs/���F��5�������"�"� �I�I�
�:�
%�
%�)�I�I��2�3�3�3��%�c�5�1�1�6��������C������,�-�-���	'��K�K���
�&�&�&����
�	
�	
�	
�����"���+1�6�6�9�9�d�d�d�F�F�K�	��	3�	3�D����y�D�1�2�2�2�2��'��4�4���Mr2c���|�	|�|}||d�S|j���}|r,|���}|d|d<|d|d<|St|��S)z^sets security mirror to primary if not defined.
    returns defaults if no mirrors are definedNrr�rr�r)�
datasource�get_package_mirror_infor*r1)�pmirror�smirrorr.r4�mirror_info�ms      r0�update_mirror_inforX4s������?��G�"��8�8�8��"�:�:�<�<�K���
��������|��)���*�
��*�
����t�$�$�$r2c��|�|d��}|�dSd}|D]'}|�d��pg}||vr|cSd|vr|}�(|S)zuout of a list of potential mirror configurations select
    and return the one matching the architecture (or default)Nr)r*r)r3rIr.�mirror_cfg_listr*�mirror_cfg_elemr)s       r0�get_arch_mirrorconfigr\Ls{���g�g�j�$�/�/�O����t��G�*�&�&�� �$�$�X�.�.�4�"���6�>�>�"�"�"�"�����%�G���Nr2c��t|||��}|�dS|�dd��}|�(tj|�dd����}|�&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%rfr()r\r<r	rGrP)r3rIr.r4�mcfgr�s      r0�
get_mirrorr__s���!��j�$�7�7�D��|��t��X�X�e�T�
"�
"�F��~��'�����4�(@�(@�A�A���~�&��H�H�\�4�(�(�*�c�5�
�
���Mr2c�T�|�.tj��}t�d|��t	|d||��}t�d|��t	|d||��}t�d|��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
    Nz!got arch for mirror selection: %sr�zgot primary mirror: %sr�zgot security mirror: %srrQ)r	r'r:rUr_rX)r3r4r.rTrUrVs      r0rWrWys����|��)�+�+���	�	�5�t�<�<�<���i��u�5�5�G��I�I�&��0�0�0���j�$��6�6�G��I�I�'��1�1�1�$�W�g�t�U�C�C�K�(�	�2�K����r2c����d}�fd�|D��}t|��rGt�d|��tj|d�|��dz��nNtj�|��r/tj	|��t�d|����
dd��rEt�d|��tj|��
d����dStj�|��r1tj	|��t�d	|��dSdS)
zHapply_apt_config
    Applies any apt*proxy config from if specified
    ))r0�Acquire::http::Proxy "%s";)r1rb)r3zAcquire::ftp::Proxy "%s";)r2zAcquire::https::Proxy "%s";c�p��g|]2\}}��|���|��|��z��3SrHr)r�r�fmtr3s   �r0r�z$apply_apt_config.<locals>.<listcomp>�s;���L�L�L�{��c�c�g�g�d�m�m�L�s�S�W�W�T�]�]�"�L�L�Lr2zwrite apt proxy info to %sr�z#no apt proxy configured, removed %s�confNzwrite apt config info to %sz$no apt config configured, removed %s)rzr:rUr	r�r�r�r��isfile�del_filer<)r3�proxy_fname�config_fname�cfgs�proxiess`    r0r]r]�sH���
�D�M�L�L�L�d�L�L�L�G�
�7�|�|�F��	�	�.��<�<�<����T�Y�Y�w�%7�%7�$�%>�?�?�?�?�	�����	$�	$�F��
�k�"�"�"��	�	�7��E�E�E�
�w�w�v�t���H��	�	�/��>�>�>����c�g�g�f�o�o�6�6�6�6�6�	�����	%�	%�H��
�l�#�#�#��	�	�8�,�G�G�G�G�G�H�Hr2Tc�������d�����fd�}��fd�}|dkr
|��S|dks|dkr
|��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�0�tj�t��rtgng}tjt
��D]I}|�d��s|�d��r|�t
|z���J|r|ndS)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�rf�APT_LOCAL_KEYS�listdir�APT_TRUSTED_GPG_DIRrtry)�	key_files�files  r0�_get_key_fileszapt_key.<locals>._get_key_files�s���)+����~�(F�(F�N�^�$�$�B�	��J�2�3�3�	=�	=�D��}�}�V�$�$�
=��
�
�f�(=�(=�
=�� � �!4�t�!;�<�<�<��%�-�y�y�2�-r2c���d}�s.tjtd������n�	�rtnt
}t
j���}d�|���}tj||��nz#tj
$r0tjtd������Yn<t$r0tjtd������YnwxYw|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	�logexcr:r?�CLOUD_INIT_GPG_DIRrpr�dearmorr�rr��UnicodeDecodeError)r��key_dir�stdoutrrr�r�s   ���r0�apt_key_addzapt_key.<locals>.apt_key_add�s1���
 �	��	��K��@�G�G��M�M�
�
�
�
�
�*2�K�&�&�8K����T�*�*��&�-�-�g�{�C�C�	���	�6�2�2�2�2���-�
�
�
����;�B�B�4�H�H������&�
�
�
����>�E�E�d�K�K������
�����s�AB�<C<�6C<�;C<c���g}���D]d}	|�tj|�������-#tj$r&}t
�d||��Yd}~�]d}~wwxYwd�|��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": %sNr�)ryrr|rr�r:r{r�)�key_listr�errorrsr}s   ��r0�apt_key_listzapt_key.<locals>.apt_key_list�s������&��(�(�	L�	L�H�
L�������� M� M� M�N�N�N�N���-�
L�
L�
L����9�8�U�K�K�K�K�K�K�K�K�����
L�����y�y��"�"�"s�);�A0�
A+�+A0r��fingerr|z@apt_key() commands add, list, and finger are currently supported)r-)�commandr�rrr�r}r{r�rss ````  @r0r�r��s��������
.�
.�
.��������8#�#�#�#�#�#��%����{�}�}��	�H�	�	��6� 1� 1��|�~�~���N�
�
�	
r2z
cloud-init)NNr)FN)NFN)NNN)NNFT)N�__doc__r�r�r�rd�loggingr�textwrapr�	cloudinitrrrrr	�cloudinit.cloudr
�cloudinit.configr�cloudinit.config.schemarr
�cloudinit.settingsr�	getLogger�__name__r:rcrnrprvrrr�__annotations__r�r_r^rr)r,r(r+r1r�r|rDrIrBrvr�rAr�r�r\r�r�r�rZr[rMr�r�r
rgrr"r.r?r;rPrXr\r_rWr]r�rxrHr2r0�<module>r�s|��1�0�0�����	�	�	�	�����	�	�	�	�������������������$�$�$�$�$�$�+�+�+�+�+�+�+�+�+�+�!�!�!�!�!�!�#�#�#�#�#�#�<�<�<�<�<�<�<�<�+�+�+�+�+�+��g���!�!��#��'��/��1���	��X�
����
)��6�	9���$���@
?�B	
�B	
�D�J�!�{^�^��j�^�^�^�@�,�t�
�
��
!�	�:�
�:��+��3�4����
6�6���
��6�"��K�K�K��
C�
C�
C�
C�&�

�&��&�#(�&�/5�&�=A�&�	�&�&�&�&�4%�%�%�-
�-
�-
�`����
�
�
�
�B 3� 3� 3� 3�F������$I�I�I�2-�-�-����$#�#�#�L7�7�7�2�2�2�<���"����
�
�
�
�&*�*�*�
FJ�V�V�V�V�r���6���&�&�&�$H�H�H�V���&�&�&�R%�%�%�0���&���4����0H�H�H�:HL�N
�N
�N
�N
�d�"����r2