Ë
    x[h�  ã                   ó²  — U d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZ d dlmZmZmZmZ d d	lmZmZ ee   ed
<   	 d dlmZ d dlm Z   ejF                  e$«      Z% G d„ de«      Z& G d„ de«      Z' G d„ de
jP                  «      Z)	 dd„Z*dd„Z+de,dee,   fd„Z-	 dd„Z.y# e!$ r eZ ejD                  d«      Z Y Œrw xY w)é    N)ÚEACCES)ÚOptionalÚType)Úhandlers)Úb64dÚ
json_dumps)ÚPaths)Ú
PER_ALWAYS)ÚMISSING_JINJA_PREFIXÚJinjaSyntaxParsingExceptionÚdetect_templateÚrender_string)Ú	load_jsonÚload_text_fileÚJUndefinedError)ÚUndefinedError)Úoperator_rez[-.]c                   ó   — e Zd Zy)ÚJinjaLoadErrorN©Ú__name__Ú
__module__Ú__qualname__© ó    úC/usr/lib/python3/dist-packages/cloudinit/handlers/jinja_template.pyr   r   "   ó   „ Ør   r   c                   ó   — e Zd Zy)ÚNotJinjaErrorNr   r   r   r   r   r   &   r   r   r   c                   ó$   — e Zd ZdgZdefd„Zd„ Zy)ÚJinjaTemplatePartHandlerz## template: jinjaÚpathsc                 óâ   — t         j                  j                  | t        d¬«       || _        i | _        |j                  dg «      D ]&  }|j                  «       D ]  }|| j
                  |<   Œ Œ( y )Né   )ÚversionÚsub_handlers)r   ÚHandlerÚ__init__r
   r"   r&   ÚgetÚ
list_types)Úselfr"   Ú_kwargsÚhandlerÚctypes        r   r(   z!JinjaTemplatePartHandler.__init__.   sn   € Ü×Ñ×!Ñ! $¬
¸AÐ!Ô>ØˆŒ
ØˆÔØ—{‘{ >°2Ó6ò 	3ˆGØ ×+Ñ+Ó-ò 3�Ø+2�×!Ñ! %Ò(ñ3ñ	3r   c                 ó  — |t         j                  v ry | j                  j                  d«      }	 t	        |||«      }|sy t        j                  |«      }
| j                  j                  |
«      }|st        j                  d||
«       y |j                  dk(  r|j                  ||||||«       y |j                  dk(  r|j                  |||||«       y y # t
        $ r*}	t        j                  d|t        |	«      «       Y d }	~	y d }	~	ww xY w)NÚinstance_data_sensitivez=Ignoring jinja template for %s. Failed to render template. %szPIgnoring jinja template for %s. Could not find supported sub-handler for type %sr$   é   )r   ÚCONTENT_SIGNALSr"   Úget_runpathÚrender_jinja_payload_from_filer   ÚLOGÚwarningÚstrÚtype_from_starts_withr&   r)   Úhandler_versionÚhandle_part)r+   Údatar.   ÚfilenameÚpayloadÚ	frequencyÚheadersÚjinja_json_fileÚrendered_payloadÚeÚsubtypeÚsub_handlers               r   r:   z$JinjaTemplatePartHandler.handle_part6   s  € Ø”H×,Ñ,Ñ,ØØŸ*™*×0Ñ0Ð1JÓKˆð	Ü=Ø˜ ?ó Ðñ  ØÜ×0Ñ0Ð1AÓBˆØ×'Ñ'×+Ñ+¨GÓ4ˆÙÜ�K‰Kð+àØô	ð Ø×&Ñ&¨!Ò+Ø×#Ñ#Ø�e˜XÐ'7¸ÀGõð ×(Ñ(¨AÒ-Ø×#Ñ#Ø�e˜XÐ'7¸õð .øô3 +ò 	Ü�K‰Kð0àÜ�A“ô	ô ûð	ús   °C Ã	D	Ã DÄD	N)r   r   r   Úprefixesr	   r(   r:   r   r   r   r!   r!   *   s   „ à$Ð%€Hð3˜eó 3ó$r   r!   c                 ó†  — t        | «      d   dk7  rt        d«      ‚i }d}t        j                  j	                  |«      st        d|z  «      ‚	 t        t        |«      «      }t        | |||«      }|sy|S # t        $ rA}d}t        |t        t        f«      r|j                  t        k(  rd|z  }t        |«      |‚d}~ww xY w)aK  Render a jinja template sourcing variables from jinja_vars_path.

    @param payload: String of jinja template content. Should begin with
        ## template: jinja\n.
    @param payload_fn: String representing the filename from which the payload
        was read used in error reporting. Generally in part-handling this is
        'part-##'.
    @param instance_data_file: A path to a json file containing variables that
        will be used as jinja template variables.

    @return: A string of jinja-rendered content with the jinja header removed.
        Returns None on error.
    r   ÚjinjazPayload is not a jinja templateNzFCannot render jinja template vars. Instance data not yet present at %sz"Loading Jinja instance data failedzGCannot render jinja template vars. No read permission on '%s'. Try sudo)r   r   ÚosÚpathÚexistsr   r   r   Ú	ExceptionÚ
isinstanceÚIOErrorÚOSErrorÚerrnor   Úrender_jinja_payload)r=   Ú
payload_fnÚinstance_data_fileÚdebugÚinstance_datarA   rB   Úmsgs           r   r4   r4   ]   sä   € ô  �wÓ Ñ" gÒ-ÜÐ=Ó>Ð>Ø€MØÐÜ�7‰7�>‰>Ð,Ô-ÜðØ1ñ2ó
ð 	
ð
)Ü!¤.Ð1CÓ"DÓEˆô ,Ø�˜]¨EóÐñ ØØÐøô ò )Ø2ˆÜ�aœ'¤7Ð+Ô,Ø�w‰wœ&Ò ð&Ø(:ñ;ð ô ˜SÓ! qÐ(ûð)ús   ÁA6 Á6	C Á?<B;Â;C c                 óò  — t        ||j                  dg «      d¬«      }|rt        j                  dt	        |«      «       	 t        | |«      }t        j                  dt        z  |«      D �cg c]  }d|j                  t        d«      z  ‘Œ }}|r&t        j                  d	|d
j                  |«      «       |S # t        t        f$ r*}t        j                  d|t        |«      «       Y d }~y d }~ww xY wc c}w )Nzbase64-encoded-keysT)Údecode_pathsÚinclude_key_aliaseszConverted jinja variables
%sz"Ignoring jinja template for %s: %sz%s[^\s]+z'%s'Ú z:Could not render jinja template variables in file '%s': %sz, )Úconvert_jinja_instance_datar)   r5   rS   r   r   Ú	TypeErrorr   r6   r7   ÚreÚfindallr   ÚreplaceÚjoin)	r=   rQ   rT   rS   Úinstance_jinja_varsrA   rB   ÚvarÚwarningss	            r   rP   rP   Š   sö   € Ü5ØØ"×&Ñ&Ð'<¸bÓAØ ôÐñ
 Ü�	‰	Ø+¬ZÐ8KÓ-Lô	
ðÜ(¨Ð2EÓFÐô —:‘:ØÔ.Ñ.Ð0@ó
öàð 	�—‘Ô1°2Ó6Ó6ð€Hð ñ Ü�‰ØHØØ�I‰I�hÓô	
ð
 Ðøô ”Ð'ò Ü�‰Ð8¸*ÄcÈ!ÃfÔMÜûðüòs   ÁB8 Á, C4Â8C1Ã C,Ã,C1Ú	orig_nameÚreturnc                 óH   — t        j                  t        d| «      }|| k7  r|S y)a‹  Return a jinja variable alias, replacing any operators with underscores.

    Provide underscore-delimited key aliases to simplify dot-notation
    attribute references for keys which contain operators "." or "-".
    This provides for simpler short-hand jinja attribute notation
    allowing one to avoid quoting keys which contain operators.
    {{ ds.v1_0.config.user_network_config }} instead of
    {{ ds['v1.0'].config["user.network-config"] }}.

    :param orig_name: String representing a jinja variable name to scrub/alias.

    :return: A string with any jinja operators replaced if needed. Otherwise,
        none if no alias required.
    Ú_N)r\   Úsubr   )rc   Ú
alias_names     r   Úget_jinja_variable_aliasri   ¨   s'   € ô —‘œ S¨)Ó4€JØ�YÒØÐØr   c                 ó  — i }|D �cg c]  }|j                  dd«      ‘Œ }}t        | j                  «       «      D ]É  \  }}|rdj                  |||«      n|}	|	|v rt	        |«      }t        |t        «      r]t        ||	|||¬«      ||<   t        j                  d|«      r9||   j                  «       D ]  \  }
}t        j                  |«      ||
<   Œ n|||<   |sŒ¡t        |«      }|sŒ¯t        j                  ||   «      ||<   ŒË |S c c}w )z¢Process instance-data.json dict for use in jinja templates.

    Replace hyphens with underscores for jinja templates and decode any
    base64_encoded_keys.
    ú-rf   z	{0}{1}{2})ÚseprW   rX   zv\d+$)r^   ÚsortedÚitemsÚformatr   rL   ÚdictrZ   r\   ÚmatchÚcopyÚdeepcopyri   )r;   Úprefixrl   rW   rX   ÚresultrI   ÚkeyÚvalueÚkey_pathÚsubkeyÚsubvaluerh   s                r   rZ   rZ   ½   s  € ð €FØ7CÖD¨t�D—L‘L  cÕ*ÐD€LÐDÜ˜TŸZ™Z›\Ó*ò @‰
ˆˆUÙ;A�;×%Ñ% f¨c°3Ô7ÀsˆØ�|Ñ#Ü˜“KˆEÜ�eœTÔ"Ü5ØØØØ)Ø$7ôˆF�3‰Kô �x‰x˜ #Ô&à(.¨s©×(9Ñ(9Ó(;ò =Ñ$�F˜HÜ%)§]¡]°8Ó%<�F˜6’Nñ=ð  ˆF�3‰KÚÜ1°#Ó6ˆJÚÜ%)§]¡]°6¸#±;Ó%?��zÒ"ð+@ð, €Mùò/ Es   ‡D	)F)rY   ú/r   F)/rr   ÚloggingrH   r\   rO   r   Útypingr   r   Ú	cloudinitr   Úcloudinit.atomic_helperr   r   Úcloudinit.helpersr	   Úcloudinit.settingsr
   Úcloudinit.templaterr   r   r   r   Úcloudinit.utilr   r   rK   Ú__annotations__Újinja2.exceptionsr   r   Újinja2.lexerr   ÚImportErrorÚcompileÚ	getLoggerr   r5   r   r   r'   r!   r4   rP   r7   ri   rZ   r   r   r   ú<module>rŠ      sâ   ðô Û Û 	Û 	Ý ß !å ß 4Ý #Ý )÷ó ÷ 5à�i‘Ó  ð&ÝCÝ(ð €g×Ñ˜Ó!€ô	�Yô 	ô	�Iô 	ô0˜x×/Ñ/ô 0ðh 49ó*óZð<¨ð °¸±ó ð, DIô øðG ò &à€OØ�"—*‘*˜WÓ%‚Kð&ús   ÁB: Â:CÃC