HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/slsutil.cpython-310.pyc
o

�N�g�L�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZdZd*dd�Zd+d
d�Z
d+dd
�Zd,dd�Zdd�Zdd�Zdd�Z								d-dd�Zd.dd�Zd/dd �Zd0d"d#�Zd0d$d%�Zd0d&d'�Zd0d(d)�ZdS)1z0
Utility functions for use with or in SLS files
�NZslsutilTFcCstjj�||||�S)a3
    Merge ``upd`` recursively into ``dest``

    If ``merge_lists=True``, will aggregate list object types instead of
    replacing. This behavior is only activated when ``recursive_update=True``.

    CLI Example:

    .. code-block:: shell

        salt '*' slsutil.update '{foo: Foo}' '{bar: Bar}'

    )�salt�utils�
dictupdate�update)�destZupdZrecursive_update�merge_lists�r�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/slsutil.pyrsr�smart�yamlcCstjj�|||||�S)a
    Merge a data structure into another by choosing a merge strategy

    Strategies:

    * aggregate
    * list
    * overwrite
    * recurse
    * smart

    CLI Example:

    .. code-block:: shell

        salt '*' slsutil.merge '{foo: Foo}' '{bar: Bar}'
    �rrr�merge)Zobj_aZobj_b�strategy�rendererrrrr	r
$sr
cCs(i}|D]
}tjj�|||||�}q|S)av
    .. versionadded:: 2019.2.0

    Merge a list of objects into each other in order

    :type lst: Iterable
    :param lst: List of objects to be merged.

    :type strategy: String
    :param strategy: Merge strategy. See utils.dictupdate.

    :type renderer: String
    :param renderer:
        Renderer type. Used to determine strategy when strategy is 'smart'.

    :type merge_lists: Bool
    :param merge_lists: Defines whether to merge embedded object lists.

    CLI Example:

    .. code-block:: shell

        $ salt-call --output=txt slsutil.merge_all '[{foo: Foo}, {foo: Bar}]'
        local: {u'foo': u'Bar'}
    r)�lstrrr�ret�objrrr	�	merge_all9sr�
jinja|yamlcKs�|s
|s
tj�d��|r|rtj�d��tj�tt�}|r)td||�dd�d�}|r1d}||d<tjj	|||td	td
fi|��}t
d|�rM|��S|S)aZ
    Parse a string or file through Salt's renderer system

    .. versionchanged:: 2018.3.0
       Add support for Salt fileserver URIs.

    This is an open-ended function and can be used for a variety of tasks. It
    makes use of Salt's "renderer pipes" system to run a string or file through
    a pipe of any of the loaded renderer modules.

    :param path: The path to a file on Salt's fileserver (any URIs supported by
        :py:func:`cp.get_url <salt.modules.cp.get_url>`) or on the local file
        system.
    :param string: An inline string to be used as the file to send through the
        renderer system. Note, not all renderer modules can work with strings;
        the 'py' renderer requires a file, for example.
    :param default_renderer: The renderer pipe to send the file through; this
        is overridden by a "she-bang" at the top of the file.
    :param kwargs: Keyword args to pass to Salt's compile_template() function.

    Keep in mind the goal of each renderer when choosing a render-pipe; for
    example, the Jinja renderer processes a text file and produces a string,
    however the YAML renderer processes a text file and produces a data
    structure.

    One possible use is to allow writing "map files", as are commonly seen in
    Salt formulas, but without tying the renderer of the map file to the
    renderer used in the other sls files. In other words, a map file could use
    the Python renderer and still be included and used by an sls file that uses
    the default 'jinja|yaml' renderer.

    For example, the two following map files produce identical results but one
    is written using the normal 'jinja|yaml' and the other is using 'py':

    .. code-block:: jinja

        #!jinja|yaml
        {% set apache = salt.grains.filter_by({
            ...normal jinja map file here...
        }, merge=salt.pillar.get('apache:lookup')) %}
        {{ apache | yaml() }}

    .. code-block:: python

        #!py
        def run():
            apache = __salt__.grains.filter_by({
                ...normal map here but as a python dict...
            }, merge=__salt__.pillar.get('apache:lookup'))
            return apache

    Regardless of which of the above map files is used, it can be accessed from
    any other sls file by calling this function. The following is a usage
    example in Jinja:

    .. code-block:: jinja

        {% set apache = salt.slsutil.renderer('map.sls') %}

    CLI Example:

    .. code-block:: bash

        salt '*' slsutil.renderer salt://path/to/file
        salt '*' slsutil.renderer /path/to/file
        salt '*' slsutil.renderer /path/to/file.jinja default_renderer='jinja'
        salt '*' slsutil.renderer /path/to/file.sls default_renderer='jinja|yaml'
        salt '*' slsutil.renderer string='Inline template! {{ saltenv }}'
        salt '*' slsutil.renderer string='Hello, {{ name }}.' name='world'
    zMust pass either path or stringz"Must not pass both path and stringz
cp.get_url�saltenv�base)rz:string:Z
input_dataZrenderer_blacklistZrenderer_whitelistzstringio.is_readable)r�
exceptions�SaltInvocationError�loaderZrender�__opts__�__salt__�get�templateZcompile_templateZ	__utils__�read)�path�stringZdefault_renderer�kwargsZ	renderersZpath_or_stringrrrr	r[s,G���rcCs^tj�t�}t||d�}t||d�}|stj�d|�d���|s-tj�d|�d|�d���|S)NzSerializer 'z' not found.z' does not implement �.)rr�serializersr�getattrr�CommandExecutionError)�
serializerZfn_namer#Zfns�fnrrr	�_get_serialize_fn�s
��r(cK�*tjjjdi|��}t|d�|fi|��S)af
    Serialize a Python object using one of the available
    :ref:`all-salt.serializers`.

    CLI Example:

    .. code-block:: bash

        salt '*' --no-parse=obj slsutil.serialize 'json' obj="{'foo': 'Foo!'}

    Jinja Example:

    .. code-block:: jinja

        {% set json_string = salt.slsutil.serialize('json',
            {'foo': 'Foo!'}) %}
    �	serializeNr�rr�argsZclean_kwargsr()r&r�
mod_kwargsr!rrr	r*�sr*cKr))a�
    Deserialize a Python object using one of the available
    :ref:`all-salt.serializers`.

    CLI Example:

    .. code-block:: bash

        salt '*' slsutil.deserialize 'json' '{"foo": "Foo!"}'
        salt '*' --no-parse=stream_or_string slsutil.deserialize 'json' \
            stream_or_string='{"foo": "Foo!"}'

    Jinja Example:

    .. code-block:: jinja

        {% set python_object = salt.slsutil.deserialize('json',
            '{"foo": "Foo!"}') %}
    �deserializeNrr+)r&Zstream_or_stringr-r!rrr	r.�sr.�H�#cCsz|durd}|durd}|��}|��}	|d}
d|	}|t|
�t|�}|dkr0tj�d��||dd�|t|�t|	�|	}
|d|t|�d|}tj|d	�}t�}|durd|�	|�|�	|
�|�	|�|�
|�D]}|�	|
|�|�|�qs|�	|�|�
|�D]}|�	|
|d|t|�|�q�|�	|
�|dur�|�	|�tj
�|�}|r�|tj
S|S)
a
    Create a standardized comment block to include in a templated file.

    A common technique in configuration management is to include a comment
    block in managed files, warning users not to modify the file. This
    function simplifies and standardizes those comment blocks.

    :param width: The width, in characters, of the banner. Default is 72.
    :param commentchar: The character to be used in the starting position of
        each line. This value should be set to a valid line comment character
        for the syntax of the file in which the banner is being inserted.
        Multiple character sequences, like '//' are supported.
        If the file's syntax does not support line comments (such as XML),
        use the ``blockstart`` and ``blockend`` options.
    :param borderchar: The character to use in the top and bottom border of
        the comment box. Must be a single character.
    :param blockstart: The character sequence to use at the beginning of a
        block comment. Should be used in conjunction with ``blockend``
    :param blockend: The character sequence to use at the end of a
        block comment. Should be used in conjunction with ``blockstart``
    :param title: The first field of the comment block. This field appears
        centered at the top of the box.
    :param text: The second filed of the comment block. This field appears
        left-justified at the bottom of the box.
    :param newline: Boolean value to indicate whether the comment block should
        end with a newline. Default is ``False``.

    **Example 1 - the default banner:**

    .. code-block:: jinja

        {{ salt['slsutil.banner']() }}

    .. code-block:: none

        ########################################################################
        #                                                                      #
        #              THIS FILE IS MANAGED BY SALT - DO NOT EDIT              #
        #                                                                      #
        # The contents of this file are managed by Salt. Any changes to this   #
        # file may be overwritten automatically and without warning.           #
        ########################################################################

    **Example 2 - a Javadoc-style banner:**

    .. code-block:: jinja

        {{ salt['slsutil.banner'](commentchar=' *', borderchar='*', blockstart='/**', blockend=' */') }}

    .. code-block:: none

        /**
         ***********************************************************************
         *                                                                     *
         *              THIS FILE IS MANAGED BY SALT - DO NOT EDIT             *
         *                                                                     *
         * The contents of this file are managed by Salt. Any changes to this  *
         * file may be overwritten automatically and without warning.          *
         ***********************************************************************
         */

    **Example 3 - custom text:**

    .. code-block:: jinja

        {{ set copyright='This file may not be copied or distributed without permission of VMware, Inc.' }}
        {{ salt['slsutil.banner'](title='Copyright 2019 VMware, Inc.', text=copyright, width=60) }}

    .. code-block:: none

        ############################################################
        #                                                          #
        #              Copyright 2019 VMware, Inc.                 #
        #                                                          #
        # This file may not be copied or distributed without       #
        # permission of VMware, Inc.                               #
        ############################################################

    Nz*THIS FILE IS MANAGED BY SALT - DO NOT EDITz}The contents of this file are managed by Salt. Any changes to this file may be overwritten automatically and without warning.� rz#Width is too small to render banner��)�width)�rstrip�strip�lenrrZArgumentValueError�textwrap�TextWrapper�list�append�wrap�center�os�linesep�join)r4ZcommentcharZ
bordercharZ
blockstartZblockend�title�text�newlineZledgeZredgeZlgutterZrgutterZ	textwidthZborder_lineZspacer_line�wrapper�block�line�resultrrr	�banner�sBZ�&�



$


rH�true�falsecCs|r|S|S)a
    Convert a boolean value into a string. This function is
    intended to be used from within file templates to provide
    an easy way to take boolean values stored in Pillars or
    Grains, and write them out in the appropriate syntax for
    a particular file template.

    :param value: The boolean value to be converted
    :param true: The value to return if ``value`` is ``True``
    :param false: The value to return if ``value`` is ``False``

    In this example, a pillar named ``smtp:encrypted`` stores a boolean
    value, but the template that uses that value needs ``yes`` or ``no``
    to be written, based on the boolean value.

    *Note: this is written on two lines for clarity. The same result
    could be achieved in one line.*

    .. code-block:: jinja

        {% set encrypted = salt[pillar.get]('smtp:encrypted', false) %}
        use_tls: {{ salt['slsutil.boolstr'](encrypted, 'yes', 'no') }}

    Result (assuming the value is ``True``):

    .. code-block:: none

        use_tls: yes

    r)�valuerIrJrrr	�boolstr�s rLcCspt}|dd�D]}||vri||<||}q|s|d|vr6|s#g}|s'i}|g|�|�R�||d<dSdS)a�
    Convenience function to set a value in the ``__context__`` dictionary.

    .. versionadded:: 3004

    :param keys: The list of keys specifying the dictionary path to set. This
                 list can be of arbitrary length and the path will be created
                 in the dictionary if it does not exist.

    :param function: A python function to be called if the specified path does
                     not exist, if the force parameter is ``True``.

    :param fun_args: A list of positional arguments to the function.

    :param fun_kwargs: A dictionary of keyword arguments to the function.

    :param force: If ``True``, force the ```__context__`` path to be updated.
                  Otherwise, only create it if it does not exist.
    N���)�__context__)�keys�functionZfun_argsZ
fun_kwargs�force�target�keyrrr	�_set_context�s
�rTrcC�,tt|dgtd|g�|tt|dvS)ap
    Return ``True`` if a file exists in the state tree, ``False`` otherwise.

    .. versionadded:: 3004

    :param str path: The fully qualified path to a file in the state tree.
    :param str saltenv: The fileserver environment to search. Default: ``base``

    CLI Example:

    .. code-block:: bash

        salt '*' slsutil.file_exists nginx/defaults.yaml
    Z	file_listzcp.list_master�rT�CONTEXT_BASErrN�rrrrr	�file_exists���rYcCrU)aq
    Return ``True`` if a directory exists in the state tree, ``False`` otherwise.

    :param str path: The fully qualified path to a directory in the state tree.
    :param str saltenv: The fileserver environment to search. Default: ``base``

    .. versionadded:: 3004

    CLI Example:

    .. code-block:: bash

        salt '*' slsutil.dir_exists nginx/files
    Zdir_listzcp.list_master_dirsrVrXrrr	�
dir_exists�rZr[cCst||�p	t||�S)a�
    Return ``True`` if a path exists in the state tree, ``False`` otherwise. The path
    could refer to a file or directory.

    .. versionadded:: 3004

    :param str path: The fully qualified path to a file or directory in the state tree.
    :param str saltenv: The fileserver environment to search. Default: ``base``

    CLI Example:

    .. code-block:: bash

        salt '*' slsutil.path_exists nginx/defaults.yaml
    )rYr[rXrrr	�path_existssr\cCs�|rt�|�}|rt||�stj�d|����t|t�r|g}t|t�s*tj�d��	|D]}tj	j
j|p6d|dd�}t||�rD|Sq-|sMtj�d��t
j
�|�}q+)al
    Find the first path matching a filename or list of filenames in a specified
    directory or the nearest ancestor directory. Returns the full path to the
    first file found.

    .. versionadded:: 3004

    :param str startpath: The fileserver path from which to begin the search.
        An empty string refers to the state tree root.
    :param filenames: A filename or list of filenames to search for. Searching for
        directory names is also supported.
    :param str saltenv: The fileserver environment to search. Default: ``base``

    Example: return the path to ``defaults.yaml``, walking up the tree from the
    state file currently being processed.

    .. code-block:: jinja

        {{ salt["slsutil.findup"](tplfile, "defaults.yaml") }}

    CLI Example:

    .. code-block:: bash

        salt '*' slsutil.findup formulas/shared/nginx map.jinja
    z+Starting path not found in the state tree: z6Filenames argument must be a string or list of stringsT�)Z
use_posixpathz*File pattern(s) not found in path ancestry)�	posixpath�normpathr\rrr�
isinstance�strr:rrr@r%r>�dirname)Z	startpath�	filenamesr�filename�fullnamerrr	�findups4
�

�
�
���rf)TF)r
rF)NNr)r/r0r0NNNNF)rIrJ)NNF)r)�__doc__r>r^r8Zsalt.exceptionsrZsalt.loaderZ
salt.templateZsalt.utils.argsZsalt.utils.dictupdateZsalt.utils.pathrWrr
rrr(r*r.rHrLrTrYr[r\rfrrrr	�<module>sD



"b
�

&
(