404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.188.96.76: ~ $
3

\�me��	@s�UdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZm
Z
mZmZddlmZmZmZmZmZddlmZddlmZddlmZmZdd	lmZeje �Z!d
Z"dZ#dZ$d
Z%dZ&eZ'ddgZ(ddd�Z)ee*e*f)ddde	d�e(e	d�e	d�ge'gd�Z+e+ee+�ZdZ,dZ-dZ.dZ/dd d!�Z0d"d"d!�Z1d#d$gZ2d%d&d'd(d)d*gZ3d}d+d,�Z4e*eee5dd-�d.d/�Z6d0d1�Z7d2d3�Z8d~d4d5�Z9dd6d7�Z:d�d8d9�Z;d:d;�Z<d<d=�Z=d>d?�Z>d@dA�Z?e*e*dB�dCdD�Z@e*dE�dFdG�ZAe*dE�dHdI�ZBdJdK�ZCe*eDdL�dMdN�ZEdOdPdQdR�ZFdSZGee*e*fdE�dTdU�ZHdVdW�ZId�dYdZ�ZJd[d\�ZKd�d]d^�ZLd_d`�ZMd�dadb�ZNdcdd�ZOdedf�ZPdgdh�ZQdidj�ZRdkdl�ZSdmdn�ZTdodp�ZUdqdr�ZVdsdt�ZWd�dudv�ZXdwdx�ZYd�dzd{�ZZd|e<iZ[dS)�z*Apt Configure: Configure apt for the user.�N)�dedent�indent)�Dict�Iterable�List�Mapping)�features�gpg�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/z&# cloud-init disable_suites redacted: ZubuntuZdebianzsoftware-properties-commonZgnupg)zadd-apt-repositoryr	Zcc_apt_configurez
Apt ConfigurezConfigure apt for the useraT        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.

        By default, cloud-init will generate default
        apt sources information in deb822 format at
        :file:`/etc/apt/sources.list.d/<distro>.sources`. When the value
        of `sources_list` does not appear to be deb822 format, or stable
        distribution releases disable deb822 format,
        :file:`/etc/apt/sources.list` will be written instead.

        .. 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-------a�        # cloud-init version 23.4 will generate a deb822 formatted sources
        # file at /etc/apt/sources.list.d/<distro>.sources instead of
        # /etc/apt/sources.list when  `sources_list` content is deb822
        # format.
        apt:
            sources_list: |
              Types: deb
              URIs: http://archive.ubuntu.com/ubuntu/
              Suites: $RELEASE
              Components: main
            )�id�name�title�description�distrosZexamples�	frequencyZactivate_by_schema_keysz/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�amd64Zi386Zs390xZarm64ZarmhfZpowerpcZppc64elZriscv64cCsB|dkrtj|�}|tkr"tj�S|tkr2tj�Std|��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�target�r$�&/usr/lib/python3.6/cc_apt_configure.py�get_default_mirrors�s
r&)r�cfg�cloud�args�returncCsPd}t|�}|jdi�}t|t�s6tdjt|�d���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})Zconfig_type)	�convert_to_v3_apt_format�get�
isinstance�dictr!�format�type�apply_debconf_selections�	apply_apt)rr'r(r)r#�apt_cfgr$r$r%�handle�s

r5cCs(tj�rdStjd�ptjd�s$d	Sd
S)NF�system is snappy.zapt-getr+�no apt commands.T�Apt is available.)Fr6)Fr7)Tr8)rZsystem_is_snappyr
�whichr$r$r$r%�_should_configure_on_empty_apt�s
r:cCs�|s"t�\}}|s"tjd|�dStjd|�tj|d�d}tj|�}t|||d�}tjd|�d}|jdt�}	|	r�t	j
|	�j}t|||�tj
|jdd	��r�t|||�t||||�t|||�yt|tt�Wn"ttfk
r�tjd
�YnXd|k�r2|}
||
d<|d
|
d
<t|d|||
|d�tjdddddddg|dddgd�\}}t	jd|�}
dd�|
D�}|�r�tjd|�x|D]}tj|tj��q�WdS)Nz#Nothing to do: No apt config and %szhandling apt config: %s)r#�codename)r"zApt Mirror info: %s�add_apt_repo_match�preserve_sources_listFz)Failed to apply proxy or apt config info:�sources�RELEASE�MIRROR)r#�template_params�
aa_repo_matchZpsz-ozppid,pidz-CZdirmngrz	gpg-agentTr�)r#�capture�rcsz(?P<ppid>\d+)\s+(?P<pid>\d+)cSs$g|]}|ddkrt|d��qS)r�1rC)�int)�.0�pidr$r$r%�
<listcomp>szapply_apt.<locals>.<listcomp>z&Killing gpg-agent and dirmngr pids: %s)r:�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_sourcesr
�findall�os�kill�signal�SIGKILL)r'r(r#Z
should_config�msg�releaser"�mirrorsZmatcherZmatchcfg�paramsZgpg_process_outZ_errZgpg_pidsZ
root_gpg_pidsZgpg_pidr$r$r%r3�sX



r3cCs*|jd�s|d7}tjdg||dd�dS)N�
zdebconf-set-selectionsT)�datar#rD)�endswithr
)�
selectionsr#r$r$r%�debconf_set_selections#s
rkcCs�g}g}xB|D]:}|tkr>tjd|�t||�|j|�q|j|�qWt|�r`tjd|�t|�r�tjddgt|�d|dd�dS)Nzunconfiguring %szSThe following packages were installed and preseeded, but cannot be unconfigured: %szdpkg-reconfigurez--frontend=noninteractiveT)rhr#rD)�CONFIG_CLEANERSrKrL�append�len�warningr
�list)Zpackagesr#Z	unhandledZ	to_config�pkgr$r$r%�dpkg_reconfigure.s&
rrc
s�|jd���stjd�dSdj�fdd�t�j��D��}t|j�|d�t�}xJ�j	�D]>\}}x4|j
�D](}|jd�r~qntj
d	d
|�}|j|�qnWq\Wtj|�}tjd|�|j|�}	t|	�dkr�tjd
�dSt|	|d�dS)z2apply_debconf_selections - push content to debconfZdebconf_selectionsz(debconf_selections was not set in configN�
csg|]}�|�qSr$r$)rH�key)�selsetsr$r%rJZsz,apply_debconf_selections.<locals>.<listcomp>)r#�#z[:\s].*�z
pkgs_cfgd: %srzno need for reconfig)r-rKrL�join�sorted�keysrk�encode�set�items�
splitlines�
startswithrO�sub�addrZget_installed_packages�intersectionrnrr)
r'r#rjZ	pkgs_cfgdZ_keyZcontent�linerqZpkgs_installedZ
need_reconfigr$)rur%r2Os(

 



r2cCs:tjtj|d��}tjd|�x|D]}tj|�q$WdS)z%clean out any local cloud-init configz/etc/cloud/cloud.cfg.d/*dpkg*z#cleaning cloud-init config from: %sN)�globr
�target_pathrKrLr_�unlink)r#�flistZdpkg_cfgr$r$r%�clean_cloud_initrs

r�cCsL|}|jd�r|dd�}|jd�}|dkr<||dd�}|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 _�/rrCz://�N�_���)ri�find�replace)�mirror�string�posr$r$r%�mirrorurl_to_apt_fileprefix}s

r�c

Cs�t|�}tj|t�}x�|j�D]�\}}|j|�}|s6q|tjjt	|�}|tjjt	|�}	||	krhqt
|�}
xltjd|�D]Z}d|	||
d�f}tj
d||�ytj||�Wq�tk
r�tjddd�Yq�Xq�WqWdS)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_LISTSr}r-r_�path�sepr�rnr�rKrL�renamer[ro)
Znew_mirrorsr#r"Zdefault_mirrorsZprerZomirrorZnmirrorZoprefixZnprefixZolen�filenameZnewnamer$r$r%rV�s$
rVcCs:dddddd�}y||}Wntk
r4|}YnX|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�securityZproposedrd)�KeyError)�suite�mappingZretsuiter$r$r%�map_known_suites�s
r�)�deb822_entryr*cCs<tjd|�s8tjdd|�}tjt�d|�}dt|d�S|S)z0If no active Suites, disable this deb822 source.z\nSuites:[ \t]+([\w-]+)z\nSuites:.*rwz7## Entry disabled by cloud-init, due to disable_suites
z# disabled by cloud-init: )rOr^r��DISABLE_SUITES_REDACT_PREFIXr)r�r$r$r%�%disable_deb822_section_without_suites�sr�)r*c	s*g}�fdd�|D��tjd|��d}x�|j�D]�}|jd�r`|rT||�d�7}q2|j|�q2|sn|j�r�|r�|jt|��d}|j|�q2|}|jd�s�||d7}q2�r�|j�dd	�}�fd
d�|D�}||kr�|t�|�d�7}ddj	|���}||d7}q2W|�r |jt|��dj	|�S)
z:reads the deb822 format config and comment disabled suitescs g|]}tjt|�d�i��qS)r?)r�
render_stringr�)rHr�)rdr$r%rJ�sz)disable_suites_deb822.<locals>.<listcomp>zDisabling suites %s as %srwrvrszSuites:rCNcsg|]}|�kr|�qSr$r$)rHr�)�disabled_suite_namesr$r%rJ�szSuites: � )
rKrLr~rrm�isspacer��splitr�rx)	�disabled�srcrdZnew_srcZnew_deb822_entryr�Znew_lineZorig_suitesZ
new_suitesr$)r�rdr%�disable_suites_deb822�sB






r�cCs�|s|S|}t|�r t|||�Sx�|D]�}t|�}tj|d|i�}tjd||�d}x�|jd�D]�}|jd�rx||7}q`|j	�}t
|�dkr�d}	|djd�r�x(|dd	�D]}
|	d7}	|
jd
�r�Pq�W||	|kr�d|}||7}q`W|}q&W|S)zRreads the config for suites to be disabled and removes those
    from the templater?zDisabling suite %s as %srwTrvrC��[N�]z"# suite disabled by cloud-init: %s)�is_deb822_sources_formatr�r�rr�rKrLr~rr�rnri)r�r�rdZretsrcr�ZreleasesuiteZnewsrcr�ZcolsZpcol�colr$r$r%�disable_suites�s6


r�cCs8x2dD]*}x$|j|g�D]}t||||d�qWqWdS)z=Adds any keys included in the primary/security mirror clauses�primaryr�)�	file_nameN)r�r�)r-�add_apt_key)r'r(r#rtr�r$r$r%rT!s
rT)�apt_src_contentr*cCs6tjd|tj�rdStjd|tj�r(dStjd�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.)rOr^�MrKro)r�r$r$r%r�(sr�zetc/aptzsources.listzsources.list.d)zDir::EtczDir::Etc::sourcelistzDir::Etc::sourcepartsz@(Dir::Etc|Dir::Etc::sourceparts|Dir::Etc::sourcelist) \"([^\"]+)cCs0yJddl}|j�|jjdtd�}|jjdtd�}|jjdtd�}Wn�tk
�r
ytjddg�\}}WnNtjk
r�td}td}td}d|�d|��d|�d|�d�d	�SXtj	t
|�}t|�}|jdtd�}|jdtd�}|jdtd�}YnXd|�d|��d|�d|�d�d	�S)
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 commmand absent or
    output unparsable.
    rNzDir::EtczDir::Etc::sourcelistzDir::Etc::sourcepartsz
apt-config�dumpr�)�
sourcelist�sourceparts)�apt_pkgZinit_config�configr-�DEFAULT_APT_CFG�ImportErrorr
�ProcessExecutionErrorrOr^�
APT_CFG_REr/)r�Zetcr�r�Zapt_dumpr�Zmatched_cfgZapt_cmd_configr$r$r%�get_apt_cfgLs4r�cCsBt�}|d}|d�|jj�d�}tjr0|}n|}||d�}x(|D] }	||	||	<||	||	j�<qDW|jdd�}
|
s�tjd�tjr�dnd	}|j	d
|jj�|���}|s�|j	d�}|s�tj
d|�dStj|�}
t
j|
|�}
|
�rt|
��r||k�rtjd
|�|}ntjd|�|}t|jd�|
|�}tj||dd�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?r;�sources_listNz1No custom template provided, fall back to builtinz.deb822rwz
sources.list.zsources.listz#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�)�mode)r��distrorrZAPT_DEB822_SOURCE_LIST_FILE�lowerr-rK�infoZget_template_filenamerorZ	load_filerr�r�rLr��
write_file)r'rdrer(r4Zapt_sources_listZapt_sources_deb822Zaptsrc_filerf�kZtmplZtmpl_fmtZtemplate_fnZrenderedr�r$r$r%rU�sH






rUFcCsPtjd|�ytj|�j}td|||d�Stjk
rJtjd��YnXdS)zM
    actual adding of a key as defined in key argument
    to the system
    zAdding key:
'%s'r�)�output_filerh�hardenedz(failed to add apt GPG Key to apt keyringN)	rKrL�pathlibZPathZstem�apt_keyr
r�r\)rtr�r�r#rr$r$r%�add_apt_key_raw�s
r�c
Cs�g}t�}tj|jdd��r^x@d
D]8}|j|�r"x(||D]}ddhj|�r:|jd�q:Wq"W|jdi�}xB|j�D]6}ddhj|�r�|jd�||jd	d
��rt|jd�qtWx$|D]}	tj|	�s�|j	t
|	�q�W|r�|jjt
|��dS)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�r�rt�keyidr	r>�sourcerwzadd-apt-repositoryN)r�r�)r|rrSr-r�r��values�shutilr9rm�PACKAGE_DEPENDENCY_BY_COMMANDr�Zinstall_packagesry)
r'rBr(Zmissing_packagesZ
required_cmdsZ
mirror_keyZmirror_itemZapt_sources_dict�ent�commandr$r$r%rR�s&




rRcCs^d|kr8d|kr8t}d|kr$|d}tj|d|�|d<d|krZt|d|pR|d|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
    r�rt�	keyserverr�)r�N)�DEFAULT_KEYSERVERr	Z
getkeybyidr�)r�r(r#r�r�r�r$r$r%r��sr�cCs|jj�dS)N)r�Zupdate_package_sources)r(r$r$r%�update_packages�sr�c
Cs|dkri}|dkrtd��t|t�s2td|���x�|D�]�}||}tjd|�d|kr�|r�|j|�r�|t|�d�|d<n||d<d|kr�d|dkr�t|||dd	�}||d
<nt|||�d|kr�q:|d}t	j
||�}|djd��stjj
d|d�|d<|djd
��s&|dd
7<||��rpytjdd|g|d�Wq:tjk
�rltjd��Yq:Xq:tj||d�}	y:d|}
d}d|k�r�|d�r�d}tj|	|
|d�Wq:tk
�r�}ztjd|	|��WYdd}~Xq:Xq:Wt|�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_FILET)r�ZKEY_FILEr�z/etc/apt/sources.list.d/z.listzadd-apt-repositoryz--no-update)r#zadd-apt-repository failed.z%s
�arm�w)�omodezfailed write to file %s: %s)r!r.r/�	TypeErrorrKrLrrnr�rr�r_r�rxrir
r�r\r�rr�rZr�)
�srcdictr(r#rArBr�r��key_filer�Zsourcefn�contentsr�Zdetailr$r$r%r]�s^



r]cCs�i}tjdddd�t|t�rftjd�xT|D]2}d|krPd|d<tj|d�}n|d}|||<q.Wnt|t�rv|}ntd��|S)	z1convert v1 apt format to v2 (dict in apt_sources)zConfig key 'apt_sources'z22.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.rprKrLZ
rand_dict_keyr/r!)Zsrclistr�Zsrcentrtr$r$r%�convert_v1_to_v2_apt_formatXs"



r�cCs,|j|d�dk	r(|j|�||<||=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�newkeyr$r$r%�convert_keyts
r�cCsNd
ddg}d}dd	gi}x"|D]\}}t||||�rd
}qW|rJ|g|d<dS)zBconvert old apt_mirror keys into the new more advanced mirror spec�
apt_mirror�uri�apt_mirror_searchrQ�apt_mirror_search_dns�
search_dnsF�arches�defaultTr�N)r�r�)r�rQ)r�r�)r�)r�r�ZkeymapZ	convertedZnewmcfgr�r�r$r$r%�convert_mirror~s
r�cCsnddddddddddd	d
�}g}x2|D]*}||kr&||dkrF||=q&|j|�q&W|s\|Stjd|��d
d�|jdd�}|dk	r�tjdd
d�x^|D]V}||}||}||=|dks�|j|d�dkr�q�|||kr�td||||f��q�W|Si}x.|D]&}||dk	�rt|||||��qWt||�x,|D]$}|j|d�dk	�r:td|���q:W||d<|S)z:convert old to new keys and adapt restructured mirror specr>N�proxy�
http_proxy�https_proxy�	ftp_proxyr=r�r<)�apt_sourcesr�r�r�Z	apt_proxyZapt_http_proxyZ
apt_ftp_proxyZapt_https_proxyZapt_preserve_sources_listZapt_custom_sources_listr<rwzThe following config key(s): z22.1)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)Nrw)rmrr�r-r!r�r�)r�Z
mapoldkeysZ
needtoconvertr�Z	newaptcfgr�Zverifyr�r$r$r%�convert_v2_to_v3_apt_format�s`




r�cCs,|jdd�}|dk	r 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,�s
r,c
Cs�d}|r�d}g}|dkrd}n|dkr,d}ntd��tj||�j}dj|jd�d	d��}|rl|jd
|�|jd�g}	|jj	}
d|
|d
|
f}x|D]}|	j||�q�Wtj
|	�}|S)zG
    Try to resolve a list of predefines DNS names to pick mirrors
    Nrwr�r�r�zsecurity-mirrorzunknown mirror type�.rCz.%s�.localdomainzhttp://%s-%s%s/%sz%s)r�rw)r!rZget_hostname_fqdn�fqdnrxr�rm�extendr�r�search_for_mirror)
Z
configured�
mirrortyper'r(r�ZmydomZdomsZ	mirrordnsr�Zmirror_listr�Z	mirrorfmtZpostr$r$r%�search_for_mirror_dns�s.

r�cCsX|dk	r|dkr|}||d�S|jj�}|rP|j�}|d|d<|d|d<|St|�S)z^sets security mirror to primary if not defined.
    returns defaults if no mirrors are definedN)rrr�rr�r)Z
datasourceZget_package_mirror_inforr&)�pmirror�smirrorr"r(�mirror_info�mr$r$r%�update_mirror_infos

r�cCsT|j|d�}|dkrdSd}x2|D]*}|jd�p2g}||kr@|Sd|kr"|}q"W|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�cCs`t|||�}|dkrdS|jdd�}|dkr>tj|jdd��}|dkr\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 returnedNr�rQr�)r�r-rr�r�)r'r�r"r(Zmcfgr�r$r$r%�
get_mirror=sr�cCsn|dkrtj�}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
    Nz!got arch for mirror selection: %sr�zgot primary mirror: %sr�zgot security mirror: %srr@)rrrKrLr�r�)r'r(r"r�r�r�r$r$r%rMWsrMcs�d}�fdd	�|D�}t|�rBtjd
|�tj|dj|�d�n"tjj|�rdtj	|�tjd|��j
d
d�r�tjd|�tj|�j
d
��n"tjj|�r�tj	|�tjd|�dS)zHapply_apt_config
    Applies any apt*proxy config from if specified
    r��Acquire::http::Proxy "%s";r�r��Acquire::ftp::Proxy "%s";r��Acquire::https::Proxy "%s";cs(g|] \}}�j|�r|�j|��qSr$)r-)rHrZfmt)r'r$r%rJ{sz$apply_apt_config.<locals>.<listcomp>zwrite apt proxy info to %srsz#no apt proxy configured, removed %sZconfNzwrite apt config info to %sz$no apt config configured, removed %s�r�r�r�r�r�r�r�r)rrrr)rnrKrLrr�rxr_r��isfileZdel_filer-)r'Zproxy_fnameZconfig_fnameZcfgsZproxiesr$)r'r%rWos"

rWTcsVdd�����fdd�}��fdd�}|dkr4|�S|dksD|d	krJ|�Std
��dS)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)
    cSsNtjjt�rtgng}x*tjt�D]}|jd�r"|jt|�q"W|rJ|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
        �.gpg�.ascrw)rr	)r_r�r�APT_LOCAL_KEYS�listdir�APT_TRUSTED_GPG_DIRrirm)Z	key_files�filer$r$r%�_get_key_files�s

zapt_key.<locals>._get_key_filescs�d}�stjtdj���n�y2�r&tnt}tj��}dj|��}tj||�WnLt	j
k
rvtjtdj���Yn&tk
r�tjtdj���YnX|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ZlogexcrKr0�CLOUD_INIT_GPG_DIRrr	Zdearmorr�r
r��UnicodeDecodeError)r�Zkey_dir�stdout)rhr�r�r$r%�apt_key_add�s 
zapt_key.<locals>.apt_key_addcsjg}xZ��D]P}y|jtj|�d��Wqtjk
rZ}ztjd||�WYdd}~XqXqWdj|�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": %sNrs)rmr	rpr
r�rKrorx)Zkey_listr��error)rrr$r%�apt_key_list�s$zapt_key.<locals>.apt_key_listr�Zfingerrpz@apt_key() commands add, list, and finger are currently supportedN)r!)r�r�rhr�rrrr$)rrhr�rr�r%r��sr�z
cloud-init)NN)N)N)N)FN)NFN)NNN)N)NNFT)\�__doc__r�Zloggingr_r�rOr�ra�textwraprrZtypingrrrrZ	cloudinitrr	r
rrZcloudinit.cloudr
Zcloudinit.configrZcloudinit.config.schemarrZcloudinit.settingsrZ	getLogger�__name__rKrNr
rrr�rrr��str�metar�rYrXr�rr rrr&rpr5r:r3rkrrr2r�r�rVr�r�r�r�rT�boolr�r�r�r�rUr�rRr�r�r]r�r�r�r�r,r�r�r�r�rMrWr�rlr$r$r$r%�<module>	s�
A

	<

!
#/(44
"

\
J)

Q

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 128 B 0644
__init__.cpython-36.pyc File 128 B 0644
cc_ansible.cpython-36.opt-1.pyc File 8.63 KB 0644
cc_ansible.cpython-36.pyc File 8.63 KB 0644
cc_apk_configure.cpython-36.opt-1.pyc File 4.51 KB 0644
cc_apk_configure.cpython-36.pyc File 4.51 KB 0644
cc_apt_configure.cpython-36.opt-1.pyc File 30.42 KB 0644
cc_apt_configure.cpython-36.pyc File 30.42 KB 0644
cc_apt_pipelining.cpython-36.opt-1.pyc File 2.44 KB 0644
cc_apt_pipelining.cpython-36.pyc File 2.44 KB 0644
cc_bootcmd.cpython-36.opt-1.pyc File 2.51 KB 0644
cc_bootcmd.cpython-36.pyc File 2.51 KB 0644
cc_byobu.cpython-36.opt-1.pyc File 3.04 KB 0644
cc_byobu.cpython-36.pyc File 3.04 KB 0644
cc_ca_certs.cpython-36.opt-1.pyc File 7.05 KB 0644
cc_ca_certs.cpython-36.pyc File 7.05 KB 0644
cc_chef.cpython-36.opt-1.pyc File 9.13 KB 0644
cc_chef.cpython-36.pyc File 9.13 KB 0644
cc_disable_ec2_metadata.cpython-36.opt-1.pyc File 1.72 KB 0644
cc_disable_ec2_metadata.cpython-36.pyc File 1.72 KB 0644
cc_disk_setup.cpython-36.opt-1.pyc File 23.1 KB 0644
cc_disk_setup.cpython-36.pyc File 23.1 KB 0644
cc_fan.cpython-36.opt-1.pyc File 2.74 KB 0644
cc_fan.cpython-36.pyc File 2.74 KB 0644
cc_final_message.cpython-36.opt-1.pyc File 3.07 KB 0644
cc_final_message.cpython-36.pyc File 3.07 KB 0644
cc_growpart.cpython-36.opt-1.pyc File 15.91 KB 0644
cc_growpart.cpython-36.pyc File 15.91 KB 0644
cc_grub_dpkg.cpython-36.opt-1.pyc File 4.92 KB 0644
cc_grub_dpkg.cpython-36.pyc File 4.92 KB 0644
cc_install_hotplug.cpython-36.opt-1.pyc File 3.25 KB 0644
cc_install_hotplug.cpython-36.pyc File 3.25 KB 0644
cc_keyboard.cpython-36.opt-1.pyc File 1.98 KB 0644
cc_keyboard.cpython-36.pyc File 1.98 KB 0644
cc_keys_to_console.cpython-36.opt-1.pyc File 3.11 KB 0644
cc_keys_to_console.cpython-36.pyc File 3.11 KB 0644
cc_landscape.cpython-36.opt-1.pyc File 4.71 KB 0644
cc_landscape.cpython-36.pyc File 4.71 KB 0644
cc_locale.cpython-36.opt-1.pyc File 1.58 KB 0644
cc_locale.cpython-36.pyc File 1.58 KB 0644
cc_lxd.cpython-36.opt-1.pyc File 13.04 KB 0644
cc_lxd.cpython-36.pyc File 13.04 KB 0644
cc_mcollective.cpython-36.opt-1.pyc File 4.24 KB 0644
cc_mcollective.cpython-36.pyc File 4.24 KB 0644
cc_migrator.cpython-36.opt-1.pyc File 2.92 KB 0644
cc_migrator.cpython-36.pyc File 2.92 KB 0644
cc_mounts.cpython-36.opt-1.pyc File 14.08 KB 0644
cc_mounts.cpython-36.pyc File 14.08 KB 0644
cc_ntp.cpython-36.opt-1.pyc File 13.15 KB 0644
cc_ntp.cpython-36.pyc File 13.15 KB 0644
cc_package_update_upgrade_install.cpython-36.opt-1.pyc File 3.78 KB 0644
cc_package_update_upgrade_install.cpython-36.pyc File 3.78 KB 0644
cc_phone_home.cpython-36.opt-1.pyc File 4.1 KB 0644
cc_phone_home.cpython-36.pyc File 4.1 KB 0644
cc_power_state_change.cpython-36.opt-1.pyc File 6.24 KB 0644
cc_power_state_change.cpython-36.pyc File 6.24 KB 0644
cc_puppet.cpython-36.opt-1.pyc File 9.46 KB 0644
cc_puppet.cpython-36.pyc File 9.46 KB 0644
cc_reset_rmc.cpython-36.opt-1.pyc File 3.59 KB 0644
cc_reset_rmc.cpython-36.pyc File 3.59 KB 0644
cc_resizefs.cpython-36.opt-1.pyc File 7.02 KB 0644
cc_resizefs.cpython-36.pyc File 7.02 KB 0644
cc_resolv_conf.cpython-36.opt-1.pyc File 4.27 KB 0644
cc_resolv_conf.cpython-36.pyc File 4.27 KB 0644
cc_rh_subscription.cpython-36.opt-1.pyc File 12.06 KB 0644
cc_rh_subscription.cpython-36.pyc File 12.06 KB 0644
cc_rightscale_userdata.cpython-36.opt-1.pyc File 2.77 KB 0644
cc_rightscale_userdata.cpython-36.pyc File 2.77 KB 0644
cc_rsyslog.cpython-36.opt-1.pyc File 10.34 KB 0644
cc_rsyslog.cpython-36.pyc File 10.34 KB 0644
cc_runcmd.cpython-36.opt-1.pyc File 2.43 KB 0644
cc_runcmd.cpython-36.pyc File 2.43 KB 0644
cc_salt_minion.cpython-36.opt-1.pyc File 4.36 KB 0644
cc_salt_minion.cpython-36.pyc File 4.36 KB 0644
cc_scripts_per_boot.cpython-36.opt-1.pyc File 1.4 KB 0644
cc_scripts_per_boot.cpython-36.pyc File 1.4 KB 0644
cc_scripts_per_instance.cpython-36.opt-1.pyc File 1.57 KB 0644
cc_scripts_per_instance.cpython-36.pyc File 1.57 KB 0644
cc_scripts_per_once.cpython-36.opt-1.pyc File 1.51 KB 0644
cc_scripts_per_once.cpython-36.pyc File 1.51 KB 0644
cc_scripts_user.cpython-36.opt-1.pyc File 1.58 KB 0644
cc_scripts_user.cpython-36.pyc File 1.58 KB 0644
cc_scripts_vendor.cpython-36.opt-1.pyc File 2.04 KB 0644
cc_scripts_vendor.cpython-36.pyc File 2.04 KB 0644
cc_seed_random.cpython-36.opt-1.pyc File 4.07 KB 0644
cc_seed_random.cpython-36.pyc File 4.07 KB 0644
cc_set_hostname.cpython-36.opt-1.pyc File 4 KB 0644
cc_set_hostname.cpython-36.pyc File 4 KB 0644
cc_set_passwords.cpython-36.opt-1.pyc File 8.4 KB 0644
cc_set_passwords.cpython-36.pyc File 8.4 KB 0644
cc_snap.cpython-36.opt-1.pyc File 5.94 KB 0644
cc_snap.cpython-36.pyc File 5.94 KB 0644
cc_spacewalk.cpython-36.opt-1.pyc File 2.87 KB 0644
cc_spacewalk.cpython-36.pyc File 2.87 KB 0644
cc_ssh.cpython-36.opt-1.pyc File 11.02 KB 0644
cc_ssh.cpython-36.pyc File 11.02 KB 0644
cc_ssh_authkey_fingerprints.cpython-36.opt-1.pyc File 3.54 KB 0644
cc_ssh_authkey_fingerprints.cpython-36.pyc File 3.54 KB 0644
cc_ssh_import_id.cpython-36.opt-1.pyc File 3.85 KB 0644
cc_ssh_import_id.cpython-36.pyc File 3.85 KB 0644
cc_timezone.cpython-36.opt-1.pyc File 1.24 KB 0644
cc_timezone.cpython-36.pyc File 1.24 KB 0644
cc_ubuntu_advantage.cpython-36.opt-1.pyc File 12.42 KB 0644
cc_ubuntu_advantage.cpython-36.pyc File 12.42 KB 0644
cc_ubuntu_autoinstall.cpython-36.opt-1.pyc File 3.89 KB 0644
cc_ubuntu_autoinstall.cpython-36.pyc File 3.89 KB 0644
cc_ubuntu_drivers.cpython-36.opt-1.pyc File 3.63 KB 0644
cc_ubuntu_drivers.cpython-36.pyc File 3.63 KB 0644
cc_update_etc_hosts.cpython-36.opt-1.pyc File 4.3 KB 0644
cc_update_etc_hosts.cpython-36.pyc File 4.3 KB 0644
cc_update_hostname.cpython-36.opt-1.pyc File 3.01 KB 0644
cc_update_hostname.cpython-36.pyc File 3.01 KB 0644
cc_users_groups.cpython-36.opt-1.pyc File 7.58 KB 0644
cc_users_groups.cpython-36.pyc File 7.58 KB 0644
cc_wireguard.cpython-36.opt-1.pyc File 8.39 KB 0644
cc_wireguard.cpython-36.pyc File 8.39 KB 0644
cc_write_files.cpython-36.opt-1.pyc File 5.61 KB 0644
cc_write_files.cpython-36.pyc File 5.61 KB 0644
cc_write_files_deferred.cpython-36.opt-1.pyc File 1.73 KB 0644
cc_write_files_deferred.cpython-36.pyc File 1.73 KB 0644
cc_yum_add_repo.cpython-36.opt-1.pyc File 6.03 KB 0644
cc_yum_add_repo.cpython-36.pyc File 6.03 KB 0644
cc_zypper_add_repo.cpython-36.opt-1.pyc File 5.66 KB 0644
cc_zypper_add_repo.cpython-36.pyc File 5.66 KB 0644
modules.cpython-36.opt-1.pyc File 7.31 KB 0644
modules.cpython-36.pyc File 7.31 KB 0644
schema.cpython-36.opt-1.pyc File 39.45 KB 0644
schema.cpython-36.pyc File 39.45 KB 0644