403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.46
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.6/site-packages/cloudinit/cmd/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.6/site-packages/cloudinit/cmd/__pycache__/query.cpython-36.opt-1.pyc
3

��b�)�@s�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZddlm
Z
mZmZddlmZmZmZdZeje�Zdd	d
�Zdd�Zed
�dd�Zeeeed�dd�Zdd�Zdd�Ze dkr�e�dS)aTQuery 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)�log�util)�addLogHandlerCLI�read_cfg_paths)�convert_jinja_instance_data�get_jinja_variable_alias�render_jinja_payload)�INSTANCE_JSON_FILE�INSTANCE_JSON_SENSITIVE_FILE�REDACT_SENSITIVE_VALUEZquerycCs�|stjttd�}|jdddddd�|jdd	td
td�|jdd
dddd�|jddtdd�|jddtdd�|jdtddd�|jddddddd�|jddtd d!d"�|S)#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 /run/cloud-init/%s)�typerz-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�nargsrz-az--all�dump_allz Dump all available instance-data)rr�destrz-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 }}")rrr)�argparse�ArgumentParser�NAME�__doc__�add_argument�strr
)�parser�r!�/usr/lib/python3.6/query.py�
get_parser&sb	
r#cCs>tj|dd�}y
|jd�Stk
r8tj|ddd�SXdS)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.
    F)�decodezutf-8T)�quietr$N)r�	load_filer$�UnicodeDecodeErrorZdecomp_gzip)Zud_file_pathZbdatar!r!r"�
load_userdata|s

r()�returncCs`d}tj�}t|||g�s t�}|r*|}nRtjj|jt�}|dkrxtjj|jt�}tjj	|�rd|}q|t
jd||�|}n|}|r�|}ntjj|jd�}|r�|}	ntjj|jd�}	yt
j|�}
WnNttfk
�r}z,|jtkr�t
jd|�nt
jd|��WYdd}~XnXt
j|
�}|dk�rDdt|f|d	<dt|	f|d
<nt|�|d	<t|	�|d
<|S)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.
    Nrz4Missing root-readable %s. Using redacted %s instead.z
user-data.txtzvendor-data.txtz$No read permission on '%s'. Try sudozMissing instance-data file: %sz<%s> file:%sZuserdataZ
vendordata)�os�getuid�allr�path�joinZrun_dirr
r�exists�LOGZwarningZ
instance_linkrr&�IOError�OSError�errnor�errorZ	load_jsonrr()�
instance_data�	user_data�vendor_data�pathsZuidZinstance_data_fnZredacted_data_fnZsensitive_data_fnZuser_data_fnZvendor_data_fnZ
instance_json�er!r!r"�_read_instance_data�sT



r:)�jinja_vars_without_aliases�jinja_vars_with_aliasesr�	list_keysc
Cs�d}|}x�|jd�D]�}y||}WnJtk
rn}z.|rJdj||d�}n
dj|�}t|�|�WYdd}~XnX||kr�||}n$x"|D]}	t|	�|kr�||	}Pq�W|r�|d7}||7}qW|S)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}')ZleafZkey_pathz Undefined instance-data key '{}'N)�split�KeyErrorr�
ValueErrorr)
r;r<rr=Zwalked_key_path�responseZ
key_path_partr9�msg�keyr!r!r"�(_find_instance_data_leaf_by_varname_path�s*


rFcCsztt|jrtjntj�t|j|j|j	|j
g�sHtjd�t�j
�dSyt|j|j|j�}Wnttfk
rvdSX|j	r�dj	|j	d�}t|d||jr�dndd�}|r�t|�d	SdSt|�}|j�r t|dd
�}yt|||j|jd�}Wn0ttfk
�r}ztj|�dSd}~XnX|j�rXt|t��sFtjd
|j�dSdjt|j���}t|t��snt j!|�}t|�d	S)z3Handle calls to 'cloud-init query' as a subcommand.zDExpected one of the options: --all, --format, --list-keys or varname�z## template: jinja
{fmt})Zfmtzquery commandlineTF)�payloadZ
payload_fnr5�debugr)Zinclude_key_aliases)r;r<rr=Nz+--list-keys provided but '%s' is not a dict�
)"rr0rIr�DEBUGZWARNING�anyr=rrrr4r#Z
print_helpr:r5r6r7r1r2r	�printrrFrArB�
isinstance�dictr.�sorted�keysrrZ
json_dumps)�name�argsr5rHZrendered_payloadrCr<r9r!r!r"�handle_args�sZ




rTcCst�}tjtt|j���dS)z,Tool to query specific instance-data values.N)r#�sys�exitrTr�
parse_args)r r!r!r"�main8srX�__main__)N)!rrr*rUr3rZ	cloudinitrrZcloudinit.cmd.develrrZ!cloudinit.handlers.jinja_templaterrr	Zcloudinit.sourcesr
rrrZ	getLoggerr0r#r(rOr:r�boolrFrTrX�__name__r!r!r!r"�<module>s*

VF'=

Youez - 2016 - github.com/yon3zu
LinuXploit