+
    ik,                         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?zA 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formatzOptionally 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)zAttempt 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U4@@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&   YR&   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 Li ; 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 12K Lww~~/00#4 J%$
 $4 / ww||E$7$7I$e&9&9;LM$001HI++,<= NN=1M% $ 89!
 ax"%
j!
 #'
l#
 #$2
-.  %2,$?j!&3N&Cl#1F-.E W 77fII<>NO 	 II68H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0M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   dkk4==IJJ		&	
 	!+0@0@

 {{{-444E	3/+"jjjde	  "# +=9H|||"=t#
		?+3(?..	H ~~~(D))II=t|| 99VHMMO45h$$ ++H5	(Og W  + 	II5A 	6 *% 	IIaL	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HH[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&   