HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/__pycache__/user_data.cpython-310.pyc
o

�Ad�9�@sddlZddlmZddlmZddlmZddlmZddl	m
Z
mZddl	mZ
ddl	mZdd	lmZmZe
�e�ZejZejZejZd
ZddgZd
dgZdgZdZdZdZgd�ZdZ dgZ!dd�Z"dd�Z#d dd�Z$Gdd�d�Z%dd�Z&efdd�Z'dS)!�N)�MIMEBase)�
MIMEMultipart)�MIMENonMultipart)�MIMEText)�features�handlers)�log)�util)�UrlError�read_file_or_urlzContent-Typez
text/plainztext/x-not-multipartztext/x-include-urlztext/x-include-once-urlztext/cloud-config-archiveztext/cloud-configzapplication/octet-stream)zapplication/gzipzapplication/gzip-compressedzapplication/gzippedzapplication/x-compresszapplication/x-compressedzapplication/x-gunzipzapplication/x-gzipzapplication/x-gzip-compressedzNumber-AttachmentscCs||=|||<dS�N�)�msg�key�valuer
r
�5/usr/lib/python3/dist-packages/cloudinit/user_data.py�_replace_header<srcCs|d=|jddt|�d�dS)NzContent-Disposition�
attachment)�filename)�
add_header�str)rrr
r
r�
_set_filenameAsrcCstjrt|�|�t�|�dSr)r�ERROR_ON_USER_DATA_FAILURE�	Exception�LOG�warning)�
error_message�source_exceptionr
r
r�
_handle_errorFs
rc@s^eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zdd�ZdS)�UserDataProcessorcCs||_t�|�|_dSr)�pathsr	�fetch_ssl_details�ssl_details)�selfr r
r
r�__init__NszUserDataProcessor.__init__cCsBt�}t|t�r|D]
}|�t|�|�q
|S|�t|�|�|Sr)r�
isinstance�list�_process_msg�convert_string)r#�blob�accumulating_msg�br
r
r�processRs
�zUserDataProcessor.processcCs�dd�}|��D]�}t|�rqd}|��}t�|�}d}|tvrOz
tj|dd�}d}d}Wn!tjyN}	zd�|t	|�|	�}
t
|
|	�WYd}	~	qd}	~	ww|sSt}|tdgvr^||�}|durd|}|r�|�
dd	�\}}t||�}
|
�|�|��r�t|
|���d
D]}||vr�t|
|t||��q�|
}||kr�t|t|�|tvr�|�||�q|tvr�|�||�qt|t|�|�||�qdS)NcSs
t�|�Sr)r�type_from_starts_with)�payloadr
r
r�
find_ctype\s
z2UserDataProcessor._process_msg.<locals>.find_ctypeF)�quietTz<Failed decompressing payload from {} of length {} due to: {}ztext/x-shellscript�/�)�Launch-Index)�walk�is_skippable�get_content_typer	�fully_decoded_payload�DECOMP_TYPES�decomp_gzip�DecompressionError�format�lenr�
UNDEF_TYPE�TYPE_NEEDED�splitr�set_payload�get_filenamerrr�CONTENT_TYPE�
INCLUDE_TYPES�_do_include�
ARCHIVE_TYPES�_explode_archive�_attach_part)r#�base_msg�
append_msgr/�part�ctype�
ctype_origr.�was_compressed�er�maintype�subtype�n_part�hr
r
rr'[sf

��
��

��zUserDataProcessor._process_msgc	Cs�|�dd�}d}|��tvr*zt�|jdd��}|r|�d�}Wn	ty)Ynw|dur0|}|dur6|}|durTz
|�dtt	|���WdSt
tfySYdSwdS)Nr3T��decode�launch-index)�getr6�EXAMINE_FOR_LAUNCH_INDEXr	�	load_yaml�get_payloadrrr�int�
ValueError�	TypeError)r#r�
header_idx�payload_idxr.r
r
r�_attach_launch_index�s,
����z&UserDataProcessor._attach_launch_indexcCs&t�|dd�}tj�|j�d�d|�S)N�md5�@�data�urlcache)r	�	hash_blob�os�path�joinr �
get_ipath_cur)r#�entry�entry_fnr
r
r�_get_include_once_filename�s�z,UserDataProcessor._get_include_once_filenamecCs$|��st|t|�|�|�dSr)rAr�PART_FN_TPLr_)r#r�attached_idr
r
r�_process_before_attach�sz(UserDataProcessor._process_before_attachcCs�d}|��D]�}|��}|�d�r|td�d���}d}n|�d�r/|td�d���}d}|�d�r5q|��}|s<qd}d}|rG|�|�}|rUtj�	|�rUt
�|�}npz-t|dd|j
d�}|rn|��rnt
j||jd	d
�|��rv|j}nd�||j�}	t|	�WnBty�}
zt|
�}||vr�|d�|�7}t||
�WYd}
~
n!d}
~
wty�}zd
�||�}	t|	|�WYd}~nd}~ww|dur�t|�}
|�|
|�qdS)NFz
#include-onceTz#include�#��
)�timeout�retriesr"i�)�modez6Fetching from {} resulted in a invalid http code of {}z
 for url: {0}zFetching from {} resulted in {})�
splitlines�lower�
startswithr<�lstrip�striprkrerf�isfiler	�	load_filerr"�ok�
write_file�contentsr;�coderr
r�IOErrorr(r')r#�contentrI�include_once_on�line�lc_line�include_url�include_once_fn�respr�urle�message�ioe�new_msgr
r
rrD�st



�����������zUserDataProcessor._do_includecCsHtj|gttfd�}|D]�}t|t�rd|i}t|t�sq|�dd�}|�d�}|s9t}t|t	�r3t
}t�||�}|�
dd�\}}	|dkrUt|t	�rN|��}t||	d�}
n
t||	�}
|
�|�d	|vrjt|
|d	�d
|vrx|
�dt|d
��t|���D]}|��dd	dd
dt��t��fvr�q~|
�|||�q~|�||
�qdS)
N)�default�allowedr���typer1r2�text)�_subtyperrUr3zcontent-disposition)r	rXr&�setr%r�dictrV�ARCHIVE_UNDEF_TYPE�bytes�ARCHIVE_UNDEF_BINARY_TYPErr-r?rTrrr@rr�keysrv�ATTACHMENT_FIELDrBrG)r#�archiverI�entries�entr��mtyper�rOrPr�headerr
r
rrFsL






�	�z"UserDataProcessor._explode_archiveNc	Csjt|vrd|t<|durt|tt|��d}z
t|�t��}W|Sttfy4t|tt|��Y|Sw)z
        Return the number of attachments to this MIMEMultipart by looking
        at its 'Number-Attachments' header.
        �0Nr)r�rrrZrVr[r\)r#�	outer_msg�	new_count�
fetched_countr
r
r�_multi_part_countGs��z#UserDataProcessor._multi_part_countcCs8|�|�}|�||d�|�|�|�||d�dS)z�
        Attach a message to an outer message. outermsg must be a MIMEMultipart.
        Modifies a header in the outer message to keep track of number of
        attachments.
        r2N)r�rn�attach)r#r�rJ�
part_countr
r
rrGYs

zUserDataProcessor._attach_partr)
�__name__�
__module__�__qualname__r$r,r'r_rkrnrDrFr�rGr
r
r
rrMs	PE
4rcCs |��pd}|��dkrdSdS)Nr��	multipartTF)�get_content_maintyperv)rJ�
part_maintyper
r
rr5esr5cCsn|sd}dd�}t|t�r|�d�}n|}tj|dd�}d|dd	���vr0t�|�d��}|S|||�}|S)
zJconvert a string (more likely bytes) or a message into
    a mime message.�cSs(|�dd�\}}t||�}|�|�|S)Nr1r2)r?rr@)rb�content_typerOrPrr
r
r�
create_binmsgts

z%convert_string.<locals>.create_binmsgzutf-8FrSs
mime-version:ri)r%r�encoder	r9rv�message_from_stringrT)�raw_datar�r��bdatarr
r
rr(ns

�r(r)(re�email.mime.baser�email.mime.multipartr�email.mime.nonmultipartr�email.mime.textr�	cloudinitrrr�loggingr	�cloudinit.url_helperr
r�	getLoggerr�r�NOT_MULTIPART_TYPErl�
OCTET_TYPErBr>rCrEr=r�r�r8r�rWrrrrr5r(r
r
r
r�<module>s>