+
    ˜qgjk,  ã                   óú   € R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	 ^ RI
Ht ^ RIHtHtHt ^ RIHt ^ RIHt Rt]P*                  ! ]4      tRR	 ltR
 tR R ltR R ltR tR t]R8X  d
   ]! 4        R# R# )aT  Query standardized instance metadata provided to machine, returning a JSON
structure.

Some instance-data values may be binary on some platforms, such as userdata and
vendordata. Attempt to decompress and decode UTF-8 any binary values.

Any binary values in the instance metadata will be base64-encoded and prefixed
with "ci-b64:" in the output. userdata and, where applicable, vendordata may
be provided to the machine gzip-compressed (and therefore as binary data).
query will attempt to decompress these to a string before emitting the JSON
output; if this fails, they are treated as binary.
N)ÚEACCES)Úatomic_helperÚutil)Úread_cfg_paths)Úconvert_jinja_instance_dataÚget_jinja_variable_aliasÚrender_jinja_payload)ÚREDACT_SENSITIVE_VALUE)ÚJinjaSyntaxParsingExceptionÚqueryc           	     ó  € V '       g!   \         P                  ! \        \        R7      p V P	                  RRRRRR7       V P	                  RR	\
        R
\        4       P                  R4       2R7       V P	                  RRRRRR7       V P	                  RR\
        RR7       V P	                  RR\
        RR7       V P	                  R\
        RRR7       V P	                  RRRRRRR7       V P	                  RR \
        R!R"R#7       V # )$a  Build or extend an arg parser for query utility.

@param parser: Optional existing ArgumentParser instance representing the
    query subcommand which will be extended to support the args of
    this utility.

@returns: ArgumentParser with proper argument configuration.
)ÚprogÚdescriptionz-dz--debugÚ
store_trueFz+Add verbose messages during template render)ÚactionÚdefaultÚhelpz-iz--instance-dataz,Path to instance-data.json file. Default is Úinstance_data)Útyper   z-lz--list-keyszBList query keys available at the provided instance-data <varname>.z-uz--user-datazHPath to user-data file. Default is /var/lib/cloud/instance/user-data.txtz-vz--vendor-datazLPath to vendor-data file. Default is /var/lib/cloud/instance/vendor-data.txtÚvarnameÚ?zÇA dot-delimited specific variable to query from instance-data. For example: v1.local_hostname. If the value is not JSON serializable, it will be base64-encoded and will contain the prefix "ci-b64:". )r   Únargsr   z-az--allÚdump_allz Dump all available instance-data)r   r   Údestr   z-fz--formatÚformatzŸOptionally specify a custom output format string. Any instance-data variable can be specified between double-curly braces. For example -f "{{ v2.cloud_name }}")r   r   r   )ÚargparseÚArgumentParserÚNAMEÚ__doc__Úadd_argumentÚstrr   Úget_runpath©Úparsers   &Ú5/usr/lib/python3/dist-packages/cloudinit/cmd/query.pyÚ
get_parserr%   &   sX  € ÷ Ü×(Ò(¬dÄÔHˆØ
×ÑØØØØØ:ð ô ð ×ÑØØÜà:ÜÓ×+Ñ+¨OÓ<Ð=ð?ð ô ð ×ÑØØØØðð ô 	ð ×ÑØØÜð5ð ô ð ×ÑØØÜð7ð ô ð ×ÑØÜØð3ð ô 
ð ×ÑØØØØØØ/ð ô ð ×ÑØØÜØð<ð ô 
ð €Mó    c                óª   € \         P                  ! V RR7      p VP                  R4      #   \         d    \         P                  ! TRRR7      u # i ; i)zìAttempt to return a string of user-data from ud_file_path

Attempt to decode or decompress if needed.
If unable to decode the content, raw bytes will be returned.

@returns: String of uncompressed userdata if possible, otherwise bytes.
T)Úquietzutf-8F)r(   Údecode)r   Úload_binary_filer)   ÚUnicodeDecodeErrorÚdecomp_gzip)Úud_file_pathÚbdatas   & r$   Úload_userdatar/   ~   sQ   € ô ×!Ò! ,°dÔ;€EðAØ�|‰|˜GÓ$Ð$øÜô AÜ×Ò ¨U¸4Ô@Ò@ðAús   š+ «$AÁAc                ó$   € V ^8„  d   QhR\         /# )é   Úreturn)Údict)r   s   "r$   Ú__annotate__r4   �   s   € ÷ Mñ MÄ$ñ Mr&   c                ó|  € \         P                  ! 4       p\        4       pV '       d   T pMmVP                  R4      pV^ 8X  dT   VP                  R4      p\         P                  P                  V4      '       d   TpM\        P                  RVV4       TpMTpV'       d   TpM*\         P                  P                  VP                  R4      pV'       d   Tp	M*\         P                  P                  VP                  R4      p	VP                  R4      p
 \        P                  ! V4      p\        P"                  ! T4      p  \        P"                  ! \        P                  ! T
4      4      pT^ 8w  d6   R
\$        : RT: 2T R&   R
\$        : RT	: 2T R&   R
\$        : RT
: 2T R&   T # \'        T4      T R&   \'        T	4      T R&   YÐR&   T #   \        \        3 dI   pTP                  \        8X  d   \        P!                  RT4       h \        P!                  RT4       h R	p?ii ; i  \        \        3 d    R	p LÏi ; i)a~  Return a dict of merged instance-data, vendordata and userdata.

The dict will contain supplemental userdata and vendordata keys sourced
from default user-data and vendor-data files.

Non-root users will have redacted INSTANCE_JSON_FILE content and redacted
vendordata and userdata values.

:raise: IOError/OSError on absence of instance-data.json file or invalid
    access perms.
r   Úinstance_data_sensitivez4Missing root-readable %s. Using redacted %s instead.zuser-data.txtzvendor-data.txtÚcombined_cloud_configz$No read permission on '%s'. Try sudozMissing instance-data file: %sNÚ<z> file:ÚuserdataÚ
vendordata)ÚosÚgetuidr   r!   ÚpathÚexistsÚLOGÚwarningÚjoinÚinstance_linkr   Úload_text_fileÚIOErrorÚOSErrorÚerrnor   ÚerrorÚ	load_jsonr	   r/   )r   Ú	user_dataÚvendor_dataÚuidÚpathsÚinstance_data_fnÚredacted_data_fnÚsensitive_data_fnÚuser_data_fnÚvendor_data_fnÚcombined_cloud_config_fnÚinstance_jsonÚer7   s   &&&           r$   Ú_read_instance_datarU   �   s  € ô �)Š)‹+€CÜÓ€EßØ(Ñà ×,Ñ,¨_Ó=ÐØ�!Œ8Ø %× 1Ñ 1Ð2KÓ LÐÜ�w‰w�~‰~Ð/×0Ò0Ø#4Ñ ä—‘ØJØ%Ø$ôð
 $4Ñ à/ÐßØ ‰ä—w‘w—|‘| E×$7Ñ$7¸ÓIˆßØ$‰äŸ™Ÿ™ e×&9Ñ&9Ð;LÓMˆØ$×0Ñ0Ð1HÓIÐðÜ×+Ò+Ð,<Ó=ˆô —N’N =Ó1€Mð%Ü $§¢Ü×ÒÐ 8Ó9ó!
Ðð ˆa…xç"Úð%
ˆ�jÒ!÷
 #Úð'
ˆ�lÒ#÷
 #Ú$ð2
ˆÐ-Ñ.ð Ðô %2°,Ó$?ˆ�jÑ!Ü&3°NÓ&Cˆ�lÑ#Ø1FÐ-Ñ.ØÐøôE ”WÐô Ø�7‰7”fÔÜ�I‰IÐ<Ð>NÔOð 	ô �I‰IÐ6Ð8HÔIØûðûô ”WÐô %ð !%Òð%ús+   ÄG	 Å*H% Ç	H"ÇAHÈH"È%H;È:H;c                óH   € V ^8„  d   QhR\         R\         R\        R\        /# )r1   Újinja_vars_without_aliasesÚjinja_vars_with_aliasesr   Ú	list_keys)r3   r    Úbool)r   s   "r$   r4   r4   Ý   s0   € ÷ (ñ (Ü $ð(ä!ð(ô ð(ô ñ	(r&   c                ó|  € RpT pVP                  R4       FW  p W,          pYe9   d
   YV,          pM#T F  p	\	        T	4      T8X  g   K  YY,          p M	  T'       d
   TR,          pYF,          pKY  	  V#   \         d>   pT'       d   RP                  YdR7      pMRP                  T4      p\        T4      ThRp?ii ; i)a›  Return the value of the dot-delimited varname path in instance-data

Split a dot-delimited jinja variable name path into components, walk the
path components into the instance_data and look up a matching jinja
variable name or cloud-init's underscore-delimited key aliases.

:raises: ValueError when varname represents an invalid key name or path or
    if list-keys is provided by varname isn't a dict object.
Ú Ú.z*instance-data '{key_path}' has no '{leaf}')ÚleafÚkey_pathz Undefined instance-data key '{}'N)ÚsplitÚKeyErrorr   Ú
ValueErrorr   )
rW   rX   r   rY   Úwalked_key_pathÚresponseÚkey_path_partrT   ÚmsgÚkeys
   &&&&      r$   Ú(_find_instance_data_leaf_by_varname_pathrh   Ý   sÌ   € ð €OØ)€HØ Ÿ™ sÖ+ˆð	)ð '>Õ&LÐ#ð Ô$ØÕ.‰Hã�Ü+¨CÓ0°MÖAØ'�}�HÙñ  ÷ Ø˜sÕ"ˆOØÕ(Šñ- ,ð. €Oøô% ô 	)ßØB×IÑIØ&ð Jó ‘ð 9×?Ñ?ÀÓH�Ü˜S“/ qÐ(ûð	)ús   šA3Á3B;Á>8B6Â6B;c                óþ  € \        VP                  VP                  VP                  VP                  .4      '       g0   \
        P                  R4       \        4       P                  4        ^#  \        VP                  VP                  VP                  4      pTP                  '       dX   RP                  TP                  R7      p \        TRTTP                   '       d   RMRR7      pT'       d   \'        T4       ^ # ^# \)        T4      pTP                  '       d2   \)        TRR
7      p \+        TTTP                  TP                  R7      pTP                  '       da   \1        T\2        4      '       g#   \
        P                  RTP                  4       ^# RP5                  \7        TP9                  4       4      4      p\1        T\$        4      '       g   \:        P<                  ! T4      p\'        T4       ^ #   \        \        3 d     ^# i ; i  \"         d+   p\
        P                  R\%        T4      4        R	p?^# R	p?ii ; i  \,        \.        3 d!   p\
        P                  T4        R	p?^# R	p?ii ; i)z3Handle calls to 'cloud-init query' as a subcommand.zDExpected one of the options: --all, --format, --list-keys or varnamez## template: jinja
{fmt})Úfmtzquery command lineTF)ÚpayloadÚ
payload_fnr   Údebugz#Failed to render templated data. %sN)Úinclude_key_aliases)rW   rX   r   rY   z+--list-keys provided but '%s' is not a dictÚ
)ÚanyrY   r   r   r   r?   rG   r%   Ú
print_helprU   r   rI   rJ   rD   rE   r   rm   r
   r    Úprintr   rh   ra   rb   Ú
isinstancer3   rA   ÚsortedÚkeysr   Ú
json_dumps)ÚnameÚargsr   rk   Úrendered_payloadrT   rd   rX   s   &&      r$   Úhandle_argsrz     sð  € ä�—‘ §¡¨d¯k©k¸4¿=¹=ÐI×JÒJÜ�	‰	ð&ô	
ô 	‹×ÑÔ!ÙðÜ+Ø×Ñ §¡°×0@Ñ0@ó
ˆð
 ‡{‡{€{Ø-×4Ñ4¸¿¹Ð4ÓEˆð	Ü3ØØ/Ø+Ø"ŸjŸj˜j‘d¨eô	 Ð÷ ÜÐ"Ô#ÙÙô +¨=Ó9€HØ‡|‡|€|Ü"=Ø¨tô#
Ðð		Ü?Ø+3Ø(?ØŸ™ØŸ.™.ô	ˆHð ‡~‡~€~Ü˜(¤D×)Ò)Ü�I‰IØ=¸t¿|¹|ôñ Ø—9‘9œV H§M¡M£OÓ4Ó5ˆÜ�h¤×$Ò$Ü ×+Ò+¨HÓ5ˆÜ	ˆ(„OÙøôg ”WÐô Úðûô +ô 	Ü�I‰IØ5Ü�A“ôõ ûð	ûô6 œ*Ð%ô 	Ü�I‰I�aŒLÝûð	úsB   Á.+G; Ã#H Ä-#I Ç;HÈHÈIÈIÉIÉI<ÉI7É7I<c                 ó~   € \        4       p \        P                  ! \        \        V P                  4       4      4       R# )z,Tool to query specific instance-data values.N)r%   ÚsysÚexitrz   r   Ú
parse_argsr"   s    r$   Úmainr   K  s%   € ä‹\€FÜ‡H‚HŒ[œ˜v×0Ñ0Ó2Ó3Ö4r&   Ú__main__)N)r   r   Úloggingr;   r|   rF   r   Ú	cloudinitr   r   Úcloudinit.cmd.develr   Ú!cloudinit.handlers.jinja_templater   r   r   Úcloudinit.sourcesr	   Úcloudinit.templaterr
   r   Ú	getLoggerÚ__name__r?   r%   r/   rU   rh   rz   r   © r&   r$   Ú<module>rŠ      s‚   ðñ
ó Û Û 	Û 
Ý ç )Ý .÷ñ õ
 5Ý ;à€Ø×Ò˜Ó!€ôUòpAõMõ`(òV@òF5ð ˆzÔÙ†Fñ r&   