HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //proc/self/root/lib/python3.9/site-packages/ansible/parsing/__pycache__/dataloader.cpython-39.pyc
a

�)g�M�@s
ddlmZmZmZeZddlZddlZddlZddl	Z	ddl
Z
ddlmZ
ddlmZmZddlmZddlmZmZddlmZmZmZddlmZdd	lmZdd
lmZm Z m!Z!m"Z"m#Z#ddl$m%Z%ddl&m'Z'e'�Z(e	�)d
ej*j+ej*j+f�Z,Gdd�d�Z-dS)�)�absolute_import�division�print_functionN)�	constants)�AnsibleFileNotFound�AnsibleParserError)�
is_executable)�binary_type�	text_type)�to_bytes�	to_native�to_text)�unquote)�	from_yaml)�VaultLib�b_HEADER�is_encrypted�is_encrypted_file�parse_vaulttext_envelope)�unfrackpath)�Displayz(?:^|%s)+tasks%s?$c@s�eZdZdZdd�Zdd�Zd4d	d
�Zd5dd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zd6dd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd7d$d%�Zd8d&d'�Zd(d)�Zd9d*d+�Zd,d-�Zd.d/�Zd:d0d1�Zd2d3�ZdS);�
DataLoadera 
    The DataLoader class is used to load and parse YAML or JSON content,
    either from a given file name or from a string that was previously
    read in through other means. A Vault password can be specified, and
    any vault-encrypted files will be decrypted.

    Data read from files will also be cached, so the file will never be
    read from disk more than once.

    Usage:

        dl = DataLoader()
        # optionally: dl.set_vault_password('foo')
        ds = dl.load('...')
        ds = dl.load_from_file('/path/to/file')
    cCs2d|_t�|_t�|_i|_t�|_|�d�dS)N�.)	�_basedir�dict�_FILE_CACHE�set�
_tempfilesZ_vaultsr�_vault�set_vault_secrets��self�r"�>/usr/lib/python3.9/site-packages/ansible/parsing/dataloader.py�__init__5szDataLoader.__init__cCs||j_dS�N)r�secrets)r!Z
vault_secretsr"r"r#rKszDataLoader.set_vault_secrets�<string>TFcCst||||jj|d�S)zBackwards compat for now)�	json_only)rrr&)r!�data�	file_name�show_contentr(r"r"r#�loadNszDataLoader.loadc	Cs~|�|�}t�d|�|r2||jvr2|j|}n6|�|�\}}t|dd�}|j||||d�}||j|<|rp|St�|�SdS)zA Loads data from a file, which can contain either JSON or YAML.  zLoading data from %s�surrogate_or_strict��errors)r)r*r+r(N)	�	path_dwim�display�debugr�_get_file_contentsr
r,�copy�deepcopy)	r!r*�cacheZunsafer(Zparsed_dataZb_file_datar+Z	file_datar"r"r#�load_from_fileRs

zDataLoader.load_from_filecCs|�|�}tj�t|dd��S�Nr-r.)r0�os�path�existsr�r!r:r"r"r#�path_existsls
zDataLoader.path_existscCs(|�|�}tj�t|dd��p&|tjkSr8)r0r9r:�isfiler�devnullr<r"r"r#�is_fileps
zDataLoader.is_filecCs|�|�}tj�t|dd��Sr8)r0r9r:�isdirrr<r"r"r#�is_directoryts
zDataLoader.is_directorycCs|�|�}t�|�Sr%)r0r9�listdirr<r"r"r#�list_directoryxs
zDataLoader.list_directorycCs|�|�}t|�S)zis the given path executable?)r0rr<r"r"r#r|s
zDataLoader.is_executableNc	Cs@t|�sd}||fSt|�\}}}}|jj||d�}d}||fS)zMDecrypt b_vault_data if encrypted and return b_data and the show_content flagT��filenameF)rrr�decrypt)	r!Zb_vault_data�b_file_namer+Zb_ciphertextZ	b_versionZcipher_nameZvault_idZb_datar"r"r#�_decrypt_if_vault_data�sz!DataLoader._decrypt_if_vault_datac
Cs�|rt|ttf�s"tdt|���t|�|��}|�|�sFtd|d��zDt	|d��&}|�
�}|�||�Wd�WS1s~0YWn@tt
fy�}z$td|t|�f|d��WYd}~n
d}~00dS)a	
        Reads the file contents from the given file name

        If the contents are vault-encrypted, it will decrypt them and return
        the decrypted data

        :arg file_name: The name of the file to read.  If this is a relative
            path, it will be expanded relative to the basedir
        :raises AnsibleFileNotFound: if the file_name does not refer to a file
        :raises AnsibleParserError: if we were unable to read the file
        :return: Returns a byte string of the file contents
        �Invalid filename: '%s'z Unable to retrieve file contents�r*�rbN�8an error occurred while trying to read the file '%s': %s�Zorig_exc)�
isinstancer	r
rrrr0r=r�open�readrI�IOError�OSError)r!r*rH�fr)�er"r"r#r3�s

0zDataLoader._get_file_contentscCs|jS)z returns the current basedir )rr r"r"r#�get_basedir�szDataLoader.get_basedircCs|durt|�|_dS)zK sets the base directory, used to find files when a relative path is given N)r
r)r!�basedirr"r"r#�set_basedir�szDataLoader.set_basedircCs^t|�}t|dd�}|�ttjj��s0|�d�r6|}nt|jdd�}tj�||�}t|dd�S)z=
        make relative paths work like folks expect.
        r-r.�~F��follow)	rr
�
startswithr9r:�sepr�joinr)r!Zgivenr:rWr"r"r#r0�szDataLoader.path_dwimc	Cs,t|dd�}tj�|�}tt|dd�dd�}tj�|d�tj�|d�tj�|d�f}tj�|d�tj�|d	�tj�|d
�tj�|d�tj�|d�tj�|d
�tj�|d�tj�|d	�tj�|d
�tj�|d�tj�|d�tj�|d
�f}ttjj|�}ttjj|�}t�	|��rt
|��s$t
|��r(dSdS)zR imperfect role detection, roles are still valid w/o tasks|meta/main.yml|yaml|etc r-r.FrZsmain.ymls	main.yamlsmainstasks/main.ymlstasks/main.yamls
tasks/mains
meta/main.ymlsmeta/main.yamls	meta/mainT)rr9r:�dirnamerr^�mapr;�RE_TASKS�search�any)	r!r:�b_pathZb_path_dirname�b_upathZuntasked_pathsZtasked_pathsZexists_untaskedZ
exists_taskedr"r"r#�_is_role�s2�� zDataLoader._is_rolec	Cs�g}t|dd�}|�ttjj��s,|�d�rB|�t|dd���n|�tj�|||��t|dd�}|sr|�|�}|r�t	�
|�r�ttj�|�dd�}|j}|�
|�|�ttj�|||�dd��|�
|�|r�|�|�s�|�ttj�|d|�dd��|�ttj�||�dd��|�ttj�||�dd��|�|�tj�||���|�|�|��|D]"}tj�t|dd���r^�q��q^|S)z�
        find one file in either a role or playbook dir with or without
        explicitly named dirname subdirs

        Used in action plugins and lookups to find supplemental files that
        could be in either place.
        r-r.rYFrZZtasks)r
r\r9r:r]�appendrr^rfrarbr_rrX�endswithr0r;r)	r!r:r_�source�is_rolerbrWZcur_basedir�	candidater"r"r#�path_dwim_relative�s0	



zDataLoader.path_dwim_relativecCst|dd�}t|dd�}d}g}|dur6t�d��n�|rz|�d�sR|�tjj�rzt|dd�}	tj�t|	dd��rv|	}�n|t�	dd	�
|��|D]�}
t|
dd�}t|dd�}tj�|�}
|s�|�|
��r
|
�
d
��r
|�tj�
tj�|
�||��|�tj�
|
|��q�|�d�d|k�r4|�tj�
|||��|�tj�
||��q�|�d�d|k�r�|�tj�
t|��dd�||��|�tj�
t|��dd�|��t�	d
td�
|���|D]8}t�d|t|�f�tj�|��r�t|�}�q��q�|du�rt|dd�|D�d��|S)au
        find one file in first path in stack taking roles into account and adding play basedir as fallback

        :arg paths: A list of text strings which are the paths to look for the filename in.
        :arg dirname: A text string representing a directory.  The directory
            is prepended to the source to form the path to search for.
        :arg source: A text string which is the filename to search for
        :rtype: A text string
        :returns: An absolute path to the filename ``source`` if found
        :raises: An AnsibleFileNotFound Exception if the file is found to exist in the search paths
        r-r.Nz:Invalid request to find a file that matches a "null" valuerYFrZzevaluation_path:
	%sz
	s/tasks�/rzsearch_path:
	%ss
	zlooking for "%s" at "%s"cSsg|]}t|��qSr")r)�.0�pr"r"r#�
<listcomp>U�z7DataLoader.path_dwim_relative_stack.<locals>.<listcomp>)r*�paths)rr1�warningr\r9r:r]rr;r2r^r_rfrhrg�splitrVr
Zvvvvvr)r!rrr_rirjZ	b_dirnameZb_source�resultrbZ	test_pathr:ZupathreZ
b_pb_base_dirZb_candidater"r"r#�path_dwim_relative_stacksB" 

z#DataLoader.path_dwim_relative_stackc
Cs�tjtjd�\}}t�|d�}t|�}zRz|�|�Wn6tyl}zt�	|�t|��WYd}~n
d}~00W|�
�n
|�
�0|S)z. Create a tempfile containing defined content )�dir�wbN)�tempfileZmkstemp�CZDEFAULT_LOCAL_TMPr9�fdopenr�write�	Exception�remove�close)r!Zcontent�fdZcontent_tempfilerT�errr"r"r#�_create_content_tempfileYs
 z#DataLoader._create_content_tempfilec
Cs0|rt|ttf�s"tdt|���t|dd�}|�|�rB|�|�sLt|d��|�	|�}z�|r�t
t|�d��f}t|tt
�d�r�|��}|jjs�tdt|���|jj||d�}|�|�}|j�|�Wd	�n1s�0Y|WSttf�y*}z(td
t|�t|�f|d��WYd	}~n
d	}~00d	S)z�
        If the file is vault encrypted return a path to a temporary decrypted file
        If the file is not encrypted then the path is returned
        Temporary files are cleanup in the destructor
        rJr-r.rKrL)�countz:A vault password or secret must be specified to decrypt %srENrMrN)rOr	r
rrrr=r@rr0rPr�lenrrQrr&rGr�r�addrRrS)r!�	file_pathrGZb_file_pathZ	real_pathrTr)rUr"r"r#�
get_real_filegs&


*zDataLoader.get_real_filecCs$||jvr t�|�|j�|�dS)z�
        Removes any temporary files created from a previous call to
        get_real_file. file_path must be the path returned from a
        previous call to get_real_file.
        N)rr9�unlinkr~)r!r�r"r"r#�cleanup_tmp_file�s

zDataLoader.cleanup_tmp_filecCsZt|j�D]J}z|�|�Wq
tyR}zt�dt|��WYd}~q
d}~00q
dS)z�
        Removes all temporary files that DataLoader has created
        NOTE: not thread safe, forks also need special handling see __init__ for details.
        z Unable to cleanup temp files: %sN)�listrr�r}r1rsr
)r!rTrUr"r"r#�cleanup_all_tmp_files�s
z DataLoader.cleanup_all_tmp_filesc	Cs�ttj�||��}g}|dur*dgtj}|D]x}d|vrH|t|�}n|r`d�|t|�g�}n|}|�|�r.|�|�r�|r.|�|�	t
|�|��q�q.n
|�|�q�q.|S)z�
        Find vars files in a given path with specified name. This will find
        files in a dir named <name>/ or a file called <name> ending in known
        extensions.
        N�r�.)rr9r:r^rzZYAML_FILENAME_EXTENSIONSr=rB�extend�_get_dir_vars_filesr
rg)	r!r:�name�
extensionsZ	allow_dirrd�found�ext�	full_pathr"r"r#�find_vars_files�s$


zDataLoader.find_vars_filescCs�g}t|�|��D]|}|�d�s|�d�stj�|�d}tj�||�}|�|�rj|sj|�	|�
||��q|�|�r|r�t|�|vr|�
|�q|S)NrrY���)�sortedrDr\rhr9r:�splitextr^rBr�r�r@r
rg)r!r:r�r�Zspathr�Z
full_spathr"r"r#r��szDataLoader._get_dir_vars_files)r'TF)TFF)N)F)F)T)NT)�__name__�
__module__�__qualname__�__doc__r$rr,r7r=r@rBrDrrIr3rVrXr0rfrlrvr�r�r�r�r�r�r"r"r"r#r"s0



"
7
;
(

"r).Z
__future__rrr�typeZ
__metaclass__r4r9Zos.path�reryZansiblerrzZansible.errorsrrZansible.module_utils.basicrZansible.module_utils.sixr	r
Zansible.module_utils._textrrr
Zansible.parsing.quotingrZansible.parsing.utils.yamlrZansible.parsing.vaultrrrrrZansible.utils.pathrZansible.utils.displayrr1�compiler:r]rarr"r"r"r#�<module>s&