관리-도구
편집 파일: user_data.cpython-39.pyc
a ����'�Dg�9����������������������@���s����d�dl�Z�d�dlZd�dlmZ�d�dlmZ�d�dlmZ�d�dlm Z �d�dl mZmZm Z �d�dlmZmZ�e��e�ZejZejZejZdZd d gZddgZd gZd ZdZdZg�d�ZdZdgZ dd��Z!dd��Z"ddd�Z#G�dd��d�Z$dd��Z%efdd�Z&dS�)�����N)�MIMEBase)� MIMEMultipart)�MIMENonMultipart)�MIMEText)�features�handlers�util)�UrlError�read_file_or_urlzContent-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-Attachmentsc�����������������C���s���|�|=�||�|<�d�S��N��)�msg�key�valuer���r����7/usr/lib/python3.9/site-packages/cloudinit/user_data.py�_replace_header;���s����r���c�����������������C���s���|�d=�|�j�ddt|�d��d�S�)NzContent-DispositionZ attachment)�filename)� add_header�str)r ���r���r���r���r���� _set_filename@���s����r���c�����������������C���s ���t�jrt|��|�n t�|���d�S�r���)r���ZERROR_ON_USER_DATA_FAILURE�RuntimeError�LOGZwarning)� error_messageZsource_exceptionr���r���r���� _handle_errorE���s����r���c�������������������@���s^���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z ddd�Zdd��ZdS�)�UserDataProcessorc�����������������C���s���||�_�t�|�|�_d�S�r���)�pathsr���Zfetch_ssl_details�ssl_details)�selfr���r���r���r����__init__M���s����zUserDataProcessor.__init__c�����������������C���s@���t���}t|t�r,|D�]}|��t|�|��qn|��t|�|��|S�r���)r���� isinstance�list�_process_msg�convert_string)r���ZblobZaccumulating_msg�br���r���r����processQ���s���� zUserDataProcessor.processc�����������������C���s���dd��}|����D��]�}t|�r qd�}|���}t�|�}d}|tv�r�ztj|dd�}d�}d}W�nN�tjy��} �z4d�|t |�| �} t | | ��W�Y�d�} ~ qW�Y�d�} ~ n d�} ~ 0�0�|s�t}|tdg�v�r�||�}|d�u�r�|}|�rF|� dd �\}}t||�} | �|��|����rt| |�����d D�]$}||v��rt| |t||�����q| }||k�r\t|t|��|tv��rt|��||��q|tv��r�|��||��qt|t|��|��||��qd�S�)Nc�����������������S���s ���t��|��S�r���)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���Zfully_decoded_payload�DECOMP_TYPES�decomp_gzipZDecompressionError�format�lenr���� UNDEF_TYPE�TYPE_NEEDED�splitr����set_payload�get_filenamer���r���r����CONTENT_TYPE� INCLUDE_TYPES�_do_include� ARCHIVE_TYPES�_explode_archive�_attach_part)r���Zbase_msg� append_msgr'����partZctypeZ ctype_origr&���Zwas_compressed�er����maintype�subtypeZn_part�hr���r���r���r!���Z���s\���� �� " zUserDataProcessor._process_msgc�������������� ���C���s����|��dd��}d�}|���tv�rTz$t�|jdd��}|r>|��d�}W�n�tyR���Y�n0�|d�ur`|}|d�u�rl|}|d�ur�z|�dtt |����W�n�t tfy����Y�n0�d�S�)Nr+���T��decode�launch-index)�getr.����EXAMINE_FOR_LAUNCH_INDEXr���� load_yamlZget_payload� Exceptionr���r����int� ValueError� TypeError)r���r ���Z header_idxZpayload_idxr&���r���r���r����_attach_launch_index����s$����z&UserDataProcessor._attach_launch_indexc�����������������C���s&���t��|dd�}tj�|�j�d�d|�S�)NZmd5�@����dataZurlcache)r���Z hash_blob�os�path�joinr���Z get_ipath_cur)r����entryZentry_fnr���r���r����_get_include_once_filename����s�����z,UserDataProcessor._get_include_once_filenamec�����������������C���s$���|����st|t|���|��|��d�S�r���)r7���r����PART_FN_TPLrN���)r���r ���Zattached_idr���r���r����_process_before_attach����s����z(UserDataProcessor._process_before_attachc�����������������C���s���d}|����D��]�}|���}|�d�r>|td�d������}d}n"|�d�r`|td�d������}d}|�d�rlq|���}|szqd�}d�}|r�|��|�}|r�tj� |�r�t �|�}n�zZt|dd|�j d�}|r�|���r�t j||jd d ��|���r�|j}nd�||j�} t| ��W�n��t�yV�} �z6t| �}||v�r8|d�|�7�}t|| ��W�Y�d�} ~ nDd�} ~ 0��t�y��}�z"d �||�} t| |��W�Y�d�}~n d�}~0�0�|d�urt|�} |��| |��qd�S�)NFz #include-onceTz#include�#����� ���)�timeoutZretriesr���i���)�modez6Fetching from {} resulted in a invalid http code of {}z for url: {0}zFetching from {} resulted in {})� splitlines�lower� startswithr2����lstrip�striprU���rQ���rR����isfiler���Zload_text_filer ���r����okZ write_file�contentsr1����coder���r ���r����IOErrorr"���r!���)r����contentr>���Zinclude_once_on�lineZlc_lineZinclude_urlZinclude_once_fnZrespr���Zurle�messageZioeZnew_msgr���r���r���r:�������sf���� ���� � zUserDataProcessor._do_includec�����������������C���sL��t�j|g�ttfd�}|D��],}t|t�r0d|i}t|t�s<q|�dd�}|�d�}|stt}t|t �rht }t�||�}|� dd�\}} |dkr�t|t �r�|���}t|| d�} nt|| �} | �|��d |v�r�t| |d ���d |v�r�| �dt|d ����t|����D�]:}|���dd dd dt���t���fv��r(q�| �|||���q�|��|| ��qd�S�) N)�default�allowedrg������typer)���r*����text)Z_subtyper���rF���r+���zcontent-disposition)r���rI���r ����setr���r����dictrG����ARCHIVE_UNDEF_TYPE�bytes�ARCHIVE_UNDEF_BINARY_TYPEr���r%���r5���rE���r���r���r6���r���r����keysr^����ATTACHMENT_FIELDr8���r=���)r����archiver>����entriesZentrg���Zmtyperj���rA���rB���r ����headerr���r���r���r<�����sJ���� � z"UserDataProcessor._explode_archiveNc�������������� ���C���sj���t�|vrd|t�<�|dur(t|t�t|���d}zt|�t���}W�n&�ttfyd���t|t�t|���Y�n0�|S�)z Return the number of attachments to this MIMEMultipart by looking at its 'Number-Attachments' header. �0Nr���)ru���r���r���rK���rG���rL���rM���)r���� outer_msgZ new_countZ fetched_countr���r���r����_multi_part_countF��s����z#UserDataProcessor._multi_part_countc�����������������C���s8���|���|�}|��||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. r*���N)r{���rW���Zattach)r���rz���r?���Z part_countr���r���r���r=���X��s���� zUserDataProcessor._attach_part)N) �__name__� __module__�__qualname__r���r$���r!���rN���rU���rW���r:���r<���r{���r=���r���r���r���r���r���L���s��� PE4 r���c�����������������C���s ���|�����p d}|���dkrdS�dS�)Nrl���Z multipartTF)Zget_content_maintyper^���)r?���Z part_maintyper���r���r���r-���d��s����r-���c�����������������C���sl���|�sd}�dd��}t�|�t�r&|��d�}n|�}tj|dd�}d|dd �����v�r^t�|�d��}n |||�}|S�) zJconvert a string (more likely bytes) or a message into a mime message.�����c�����������������S���s(���|��dd�\}}t||�}|�|���|S�)Nr)���r*���)r5���r���r6���)rP����content_typerA���rB���r ���r���r���r���� create_binmsgs��s���� z%convert_string.<locals>.create_binmsgzutf-8FrD���s ���mime-version:r���i���)r���r����encoder���r0���r^���Zmessage_from_stringrE���)�raw_datar����r����Zbdatar ���r���r���r���r"���m��s���� r"���)N)'ZloggingrQ���Zemail.mime.baser���Zemail.mime.multipartr���Zemail.mime.nonmultipartr���Zemail.mime.textr���Z cloudinitr���r���r���Zcloudinit.url_helperr ���r ���Z getLoggerr|���r���ZNOT_MULTIPART_TYPErV���Z OCTET_TYPEr8���r4���r9���r;���r3���rq���rs���r/���ru���rH���r���r���r���r���r-���r"���r���r���r���r����<module>���s:��� ��