HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/saltclass.cpython-310.pyc
o

�N�g�7�@s�ddlZddlZddlZddlZddlZddlmZmZddlZ	ddl
Z	ddlZ	e�e
�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zd%dd�Zdd�Zdd�Zdd�Zd%dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdS)&�N)�Environment�FileSystemLoadercCs\tttj�|��d�}|j�|d|d|d|d|dd��|�tj�|���	�}|S)N)�loader�__opts__�__salt__�
__grains__�
__pillar__�	minion_id)rrrrr	)
rr�os�path�dirname�globals�updateZget_template�basenameZrender)�_file�	salt_dataZj_envZj_render�r�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/saltclass.py�render_jinjas��	rcCstjj�t||��S�N)�salt�utilsZyamlZ	safe_loadr)rrrrr�render_yaml!srcCs�g}|d}t||�\}}}tjjjtj�|d�dd�D]\}}}	|	D]}
|�tj�||
��q#q||vr:t||�S||vrCt||�S||vrLt||�St	�
d|�iS)Nr�classesT��followlinksz%s: Class definition not found)�get_class_pathsrrr�os_walkr
�join�appendr�log�warning)�_classrZl_files�saltclass_path�straight�sub_init�sub_straight�root�dirs�filesZl_filerrr�	get_class&s"��


r*c
Cs\tj�|d|�d��}tj�|dd�|�dtj���}tj�|d|�dtj�d�}|||fS)a
    Converts the dotted notation of a saltclass class to its possible file counterparts.

    :param str _class: Dotted notation of the class
    :param str saltclass_path: Root to saltclass storage
    :return: 3-tuple of possible file counterparts
    :rtype: tuple(str)
    r�.ymlz{}.yml�.zinit.yml)r
rr�format�replace�sep)r"r#r$r&r%rrrr?s	��
rcCsX|ttj�|d��ttj�d�}|dd�}|�tjd�}|�d�r*|dd�}|S)a�
    Converts the absolute path to a saltclass file back to the dotted notation.

    .. code-block:: python

       print(get_class_from_file('/srv/saltclass/classes/services/nginx/init.yml', '/srv/saltclass'))
       # services.nginx

    :param str _file: Absolute path to file
    :param str saltclass_path: Root to saltclass storage
    :return: class name in dotted notation
    :rtype: str
    rN���r,z.init���)�lenr
rrr/r.�endswith)rr#rrr�get_class_from_fileRs$
r4cCs"d}|D]
}d|vr|d}q|S)N��environmentr)Z
exp_dict_listr6Zs_classrrr�get_env_from_dictms�r7cCs�|durg}|D]h}||vrjt||t�r<t||t�r<||ddkr2||�d�||||<q||�||�qt||t�rZt||t�rZt|||||t|�g�q||||krcq||||<q||||<q|S)Nr�^)�
isinstance�list�pop�extend�dict�
dict_merge�str)�a�br�keyrrrr>vs  r>cCs�|��D]E\}}t|t�rt|||||�t|t�rAd}|D]!}t|t�r/t|||||�t|t�r<||kr<|||<|d}q||krI|||<q|S)Nr�)�itemsr9r=�dict_search_and_replacer:r?)�d�old�new�expanded�k�v�x�irrrrE�s 




�rEcCsJ|}|dd��d�D]}|dur|S||vr|�|�}q|S|S)N�����:)�split�get)rLrKr@rMrrr�find_value_to_expand�srSc
Cs�t�d|�}|r||D]q}t|���}|�d�r-|�||�d��}t||||�}|�|�q
|�d�sTt	||dd��}	|�|dd�|	�}t||||�}|}|�|�q
t	||�}	t
|t�re|�||	�}n|�||	�}t||||�}|}|}|�|�q
|S)Nz(^|.)\$\{.*?\}�\�$rC)�re�finditerr?�group�
startswithr.�lstriprErrSr9)
�_strrKrJrArIZvreZre_vZre_strZv_newZ
v_expandedrrr�find_and_process_re�s.



r\c	Cs�|dur
|��}g}|��D]K\}}t|t�r$t||||t|�g�qt|t�rL|D] }t|t�r>t||||t|�g�t|t�rKt|||||�}q+t|t�rYt|||||�}q|Sr)�copyrDr9r=�expand_variablesr?r:r\)r@rArIrrJrKrMrrrr^�s"



�
�r^cCsvt||�\}}}g}g}|�t�|��|�t�|��|�t�|��|s,t�d|�|D]
}|�t||��q.|S)a-
    Takes a class name possibly including `*` or `?` wildcards (or any other wildcards supportet by `glob.glob`) and
    returns a list of expanded class names without wildcards.

    .. code-block:: python

       classes = match_class_glob('services.*', '/srv/saltclass')
       print(classes)
       # services.mariadb
       # services.nginx...


    :param str _class: dotted class name, globbing allowed.
    :param str saltclass_path: path to the saltclass root directory.

    :return: The list of expanded class matches.
    :rtype: list(str)
    z,%s: Class globbing did not yield any results)rr<�globr r!rr4)r"r#r$r%r&r�matches�matchrrr�match_class_glob�srbcCsJg}g}|d}|D]
}|�t||��q
|D]}||vr"|�|�q|S)a
    Expand the list of `classes` to no longer include any globbing.

    :param iterable(str) classes: Iterable of classes
    :param dict salt_data: configuration data
    :return: Expanded list of classes with resolved globbing
    :rtype: list(str)
    r)r<rbr)rrZall_classes�expanded_classesr#r"rrr�expand_classes_globs	
�rdc		Cs�tjj��}|sd|vr|d}t||�}|D]T}||vrk|�|�tjj�|t||�i�}||dur8i||<||�di�}|rIt|d|�d||vrft	i||||�di��}|�
|�|�|�|�
|�q|rw|�
|d|i�|S)ad
    Expand the list of `classes_to_expand` and return them in the order found

    The return order is `[C, B, A, M, B, L, MINION_ID]` when:

    - minion node include classes `A` and `L`
    - `A` include class `B`
    - `B` include class `C`
    - `L` include class `M` and `B`

    :param dict minion_dict: definition of minion node
    :param dict salt_data: configuration data
    :param iterable(str) seen_classes: classes already processed
    :param iterable(str) classes_to_expand: classes to recursivly expand
    :return: Expanded classes in proper order
    :rtype: salt.utils.odict.OrderedDict
    rN�pillarsrr	)rrZodict�OrderedDictrdrr*rRr>�expand_classes_in_orderr�move_to_end)	Zminion_dictrZseen_classesZclasses_to_expandrc�klassZ
klass_dictZnew_pillarsZnested_classesrrrrgs:

��


�rgcs6d}|d}tjjjtj�|d�dd�D]\}}}|D]}||�d�kr+tj�||�}qqi}|r9t||�||<n
t�d|�i||<t	|dt
�||��d	i��t
|||gg�}	i}
g}t|	���dd
�}t|	���}
|
D]}d	|vr}t	|
|�d|vr�|�|d�qrt���fdd
�|D�}|
|
||fS)Nr5rZnodesTrr+z%s: Node definition not foundrrerO�statescs"g|]
}|�vs��|�s|�qSr)�add)�.0�state�Z
state_seenrr�
<listcomp>�s
�z-expanded_dict_from_minion.<locals>.<listcomp>)rrrrr
rrr r!r>r]�deepcopyrRrgr:�keys�valuesr<�set)r	rrr#r'r(r)Zminion_fileZ	node_dictrc�pillars_dict�states_list�classes_listZclasses_valuesZexp_dictrrnr�expanded_dict_from_minionZsD����
�
�rwcCs�t||�\}}}}t|�}d|vrt|dig�}ntiig�}i}i|d<||dd<||dd<||dd<||dd<|�|�|S)NreZ
__saltclass__rjrr6�nodename)rwr7r^r)r	rrcrtrvrur6Zpillars_dict_expandedrrr�get_pillars�s$�
rycCs*t||�\}}}}t|�}i}|||<|Sr)rwr7)r	rrcrtrvrur6Z	tops_dictrrr�get_tops�s�rzr) r]r_�loggingr
rVZjinja2rrZsalt.utils.odictrZsalt.utils.pathZsalt.utils.yaml�	getLogger�__name__r rrr*rr4r7r>rErSr\r^rbrdrgrwryrzrrrr�<module>s6

	
 @3#