܍~c96ddlZddlmZddlmZddlmZddlmZddl m Z m Z ddl m Z ddl mZdd lmZmZe jeZe jZe jZe jZd Zd d gZd dgZdgZd ZdZdZgdZdZ dgZ!dZ"dZ#ddZ$GddZ%dZ&efdZ'dS)N)MIMEBase) MIMEMultipart)MIMENonMultipart)MIMEText)featureshandlers)log)util)UrlErrorread_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-Attachmentsc||=|||<dSN)msgkeyvalues 5/usr/lib/python3/dist-packages/cloudinit/user_data.py_replace_headerr<s CCHHHcV|d=|ddt|dS)NzContent-Disposition attachment)filename) add_headerstr)rrs r _set_filenamerAs0 !"NN(,XNOOOOOrcrtjrt||t|dSr)rERROR_ON_USER_DATA_FAILURE ExceptionLOGwarning) error_messagesource_exceptions r _handle_errorr#Fs6*# &&,<< M"""""rcLeZdZdZdZdZdZdZdZdZ dZ d d Z d Z d S) UserDataProcessorcF||_tj||_dSr)pathsr fetch_ssl_details ssl_details)selfr's r__init__zUserDataProcessor.__init__Ns" 1%88rct}t|tr)|D]%}|t ||&n#|t |||Sr)r isinstancelist _process_msgconvert_string)r*blobaccumulating_msgbs rprocesszUserDataProcessor.processRs(?? dD ! ! F G G!!."3"35EFFFF G   nT224D E E Erc Hd}|D]}t|rd}|}tj|}d}|t vrl tj|d}d}d}nP#tj$r>} d|t|| } t| | Yd} ~ d} ~ wwxYw|st}|tdgzvr ||}||}|r| dd\} } t| | } | ||r"t#| |d D]*}||vr$t%| |t'||+| }||krt%|t(||t*vr||||t.vr|||t%|t(|||| dS) Nc*tj|Sr)rtype_from_starts_with)payloads r find_ctypez2UserDataProcessor._process_msg..find_ctype\s1':: :rF)quietTz>>*AAADyy'3tAw<<@@@ ""lE::: %%  *555 %%%%gz::: HlE : : :   j$ / / / /WK 0K 0s!A<<C  4CC c|dd}d}|tvrQ tj|d}|r|d}n#t $rYnwxYw||}||}|K |dtt|dS#ttf$rYdSwxYwdS)Nr=Tdecode launch-index) getr@EXAMINE_FOR_LAUNCH_INDEXr load_yaml get_payloadrrrint ValueError TypeError)r*r header_idx payload_idxr8s r_attach_launch_indexz&UserDataProcessor._attach_launch_indexs WW^T22     ! !%= = = .)E)EFF>")++n"="=K      !$K  $K  " ~s3{3C3C/D/DEEEEE *     # "s#?A55 BB0CCCctj|dd}tj|jdd|S)Nmd5@dataurlcache)r hash_blobospathjoinr' get_ipath_cur)r*entryentry_fns r_get_include_once_filenamez,UserDataProcessor._get_include_once_filenamesD>%33w|| J $ $V , ,j(   rc|st|t|z||dSr)rKr PART_FN_TPLrj)r*r attached_ids r_process_before_attachz(UserDataProcessor._process_before_attachsE!! < #{k: ; ; ; !!#&&&&&rcd}|D]Z}|}|dr,|tdd}d}n@|dr+|tdd}d}|dr|}|sd}d}|r||}|r5tj |rtj |}n t|dd|j }|r0|rtj||jd |r|j}n*d ||j} t'| n#t($rE} t+| } || vr| d |z } t'| | Yd} ~ n@d} ~ wt,$r0} d || } t'| | Yd} ~ nd} ~ wwxYw|%t/|} || |\dS)NFz #include-onceTz#include# )timeoutretriesr)i)modez6Fetching from {} resulted in a invalid http code of {}z for url: {0}zFetching from {} resulted in {}) splitlineslower startswithrFlstripstriprwrqrrisfiler load_filer r)ok write_filecontentsrEcoder#r rIOErrorr0r/)r*contentrSinclude_once_onlinelc_line include_urlinclude_once_fnrespr!urlemessageioenew_msgs rrNzUserDataProcessor._do_includes &&((> 7> 7DjjllG!!/22 (C00223::<<#'##J// (C OO--.5577#(s## **,,K "OG O"&"A"A+"N"N# 627>>/#B#B# 6.99 6+# ! "$($4 D '47799+T]wwyy 5"&-99? +TY::& &m444111!$iiG#'11?#9#9+#F#FF!'400000000666$E$L$L#S%%M"-55555555 6 "(11!!':666}> 7> 7s%/BG I ;H  I&IIc Rtj|gttf}|D]}t |t rd|i}t |t s2|dd}|d}|s8t}t |trt}tj ||}| dd\}} |dkr;t |tr|}t|| } n%t!|| } | |d |vrt%| |d d |vr)| d t |d t|D]j} | dd dd d t,t.fvrN| | || k||| dS) N)defaultallowedrtyper;r<text)_subtyperr`r=zcontent-disposition)r rcr.setr-rdictraARCHIVE_UNDEF_TYPEbytesARCHIVE_UNDEF_BINARY_TYPErr7rIr_rrrJrrkeysrATTACHMENT_FIELDrLrQ) r*archiverSentriesentrmtyperrYrZrheaders rrPz"UserDataProcessor._explode_archives%."tSkJJJ0 /0 /C#s## ' #&cD** ggi,,GGGFOOE I,gu--87G 6wHH % C 3 3 Hg6!!gu--/%nn..Gw999x11(((S  c3z?333$$~s3~3F/G/GHHHsxxzz** 4 4<<>>")$**,, &&((&vs6{3333   j# . . . .a0 /0 /rNc@t|vr d|t<|#t|tt|d} t|t}n:#t t f$r&t|tt|YnwxYw|S)z Return the number of attachments to this MIMEMultipart by looking at its 'Number-Attachments' header. 0Nr)rrrrerarfrg)r* outer_msg new_count fetched_counts r_multi_part_countz#UserDataProcessor._multi_part_countHs 9 , ,*-I& '  I'7Y H H H  M .> ? ?@@MMI& M M M I'7]9K9K L L L L L Ms'A$$4BBc||}|||dz|||||dzdS)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)rr{attach)r*rrT part_counts rrQzUserDataProcessor._attach_partZse ++I66  ##D*q.999 y*q.99999rr) __name__ __module__ __qualname__r+r4r/rjrwr{rNrPrrQrrrr%r%Ms999   O0O0O0b0   ''' C7C7C7J2/2/2/h$ : : : : :rr%cf|pd}|dkrdSdS)Nr multipartTF)get_content_maintyper)rT part_maintypes rr?r?fs9--//52M ++t 5rc>|sd}d}t|tr|d}n|}tj|d}d|ddvr(tj|d}n |||}|S) zJconvert a string (more likely bytes) or a message into a mime message.rc|dd\}}t||}|||S)Nr;r<)rIrrJ)rn content_typerYrZrs r create_binmsgz%convert_string..create_binmsgusB(..sA66'x))  rzutf-8Fr^s mime-version:ri)r-rencoder rCrmessage_from_stringr_)raw_datarrbdatars rr0r0os  (C  ((  U5 1 1 1E54=..0000&u||G'<'<==mE<00 Jrr)(rqemail.mime.baseremail.mime.multipartremail.mime.nonmultipartremail.mime.textr cloudinitrrr loggingr cloudinit.url_helperr r getLoggerrrNOT_MULTIPART_TYPEry OCTET_TYPErLrHrMrOrGrrrBrrbrrr#r%r?r0rrrrs $$$$$$......444444$$$$$$(((((((($$$$$$;;;;;;;;g!!0"   34 %'@A ,-  (6    (00 PPP ####V:V:V:V:V:V:V:V:r+=r