File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/pillar.cpython-310.pyc
Back
o ;j-U � @ s d Z ddlZddlZddlZddlmZ ddlmZ ddlZ ddl Z ddlZ ddlZ ddl Z ddlZ ddlmZmZ ddlmZ dgZe�e�Zeddeddfd d �Zdd� Ze jj�ed �Zdd� Zdd� Zdd� Z dd� Z!d!dd�Z"d!dd�Z#efdd�Z$d!dd�Z%eZ&d"dd �Z'dS )#z) Extract the pillar data for this minion � N)�OrderedDict)�Mapping)�DEFAULT_TARGET_DELIM�NOT_SET)�CommandExecutionError�*Fc sj � t krt� t�d�s� tu rd� |du rt�dd�n|}tdd� ||fD ��r*tnt||d�}|r�t� t�rat j j�|| i |�} t| t �rUt�� �� t j jj� | |d �S t�d � | t| �j� n=t� t�r�t j j�|| g |�} t| t�r�t�� �� � �� fdd�| D �� � S t�d � | t| �j� n t�d� t� �j� t j j�|| � |�} | tu r�td| � ���| S )a� .. versionadded:: 0.14.0 Attempt to retrieve the named value from :ref:`in-memory pillar data <pillar-in-memory>`. If the pillar key is not present in the in-memory pillar, then the value specified in the ``default`` option (described below) will be returned. If the merge parameter is set to ``True``, the default will be recursively merged into the returned pillar data. The value can also represent a value in a nested dict using a ":" delimiter for the dict. This means that if a dict in pillar looks like this:: {'pkg': {'apache': 'httpd'}} To retrieve the value associated with the ``apache`` key in the ``pkg`` dict this key can be passed as:: pkg:apache key The pillar key to get value from default The value specified by this option will be returned if the desired pillar key does not exist. If a default value is not specified, then it will be an empty string, unless :conf_minion:`pillar_raise_on_missing` is set to ``True``, in which case an error will be raised. merge : ``False`` If ``True``, the retrieved values will be merged into the passed default. When the default and the retrieved value are both dictionaries, the dictionaries will be recursively merged. .. versionadded:: 2014.7.0 .. versionchanged:: 2016.3.7,2016.11.4,2017.7.0 If the default and the retrieved value are not of the same type, then merging will be skipped and the retrieved value will be returned. Earlier releases raised an error in these cases. merge_nested_lists If set to ``False``, lists nested within the retrieved pillar dictionary will *overwrite* lists in ``default``. If set to ``True``, nested lists will be *merged* into lists in ``default``. If unspecified (the default), this option is inherited from the :conf_minion:`pillar_merge_lists` minion config option. .. note:: This option is ignored when ``merge`` is set to ``False``. .. versionadded:: 2016.11.6 delimiter Specify an alternate delimiter to use when traversing a nested dict. This is useful for when the desired key contains a colon. See CLI example below for usage. .. versionadded:: 2014.7.0 pillarenv If specified, this function will query the master to generate fresh pillar data on the fly, specifically from the requested pillar environment. Note that this can produce different pillar data than executing this function without an environment, as its normal behavior is just to return a value from minion's pillar data in memory (which can be sourced from more than one pillar environment). Using this argument will not affect the pillar data in memory. It will however be slightly slower and use more resources on the master due to the need for the master to generate and send the minion fresh pillar data. This tradeoff in performance however allows for the use case where pillar data is desired only from a single environment. .. versionadded:: 2017.7.0 saltenv Included only for compatibility with :conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored. .. versionadded:: 2017.7.0 CLI Example: .. code-block:: bash salt '*' pillar.get pkg:apache salt '*' pillar.get abc::def|ghi delimiter='|' Zpillar_raise_on_missing� NZpillar_merge_listsFc s � � | ]}|d u V qd S �N� ��.0�xr r �G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pillar.py� <genexpr>� � � zget.<locals>.<genexpr>��saltenv� pillarenv)Zmerge_listsznpillar.get: Default (%s) is a dict, but the returned pillar value (%s) is of type '%s'. Merge will be skipped.c s g | ]}|� vr|�qS r r r ��defaultr r � <listcomp>� s zget.<locals>.<listcomp>znpillar.get: Default (%s) is a list, but the returned pillar value (%s) is of type '%s'. Merge will be skipped.zapillar.get: Default (%s) is of type '%s', must be a dict or list to merge. Merge will be skipped.�Pillar key not found: )r �KeyError�__opts__�get�all� __pillar__�items� isinstance�dict�salt�utils�data�traverse_dict_and_listr �copy�deepcopyZ dictupdate�update�log�error�type�__name__�list�extend) �keyr �mergeZmerge_nested_lists� delimiterr r Zopt_merge_lists�pillar_dict�retr r r r sh d ��� � � �� � � �r c O s� | rt | � S |�d�}|du r#t�dd�r|�d�ptd }ntd }|�d�}|�d�}|rU|rUztjjj||dttd d �}W n tyT } ztd|� ���d}~ww tj j ttt�td ||d �}|� � S )aQ Calls the master for a fresh pillar and generates the pillar data on the fly Contrast with :py:func:`raw` which returns the pillar data that is currently loaded into the minion. pillar If specified, allows for a dictionary of pillar data to be made available to pillar and ext_pillar rendering. these pillar variables will also override any variables of the same name in pillar or ext_pillar. .. versionadded:: 2015.5.0 pillar_enc If specified, the data passed in the ``pillar`` argument will be passed through this renderer to decrypt it. .. note:: This will decrypt on the minion side, so the specified renderer must be set up on the minion for this to work. Alternatively, pillar data can be decrypted master-side. For more information, see the :ref:`Pillar Encryption <pillar-encryption>` documentation. Pillar data that is decrypted master-side, is not decrypted until the end of pillar compilation though, so minion-side decryption will be necessary if the encrypted pillar data must be made available in an decrypted state pillar/ext_pillar rendering. .. versionadded:: 2017.7.0 pillarenv Pass a specific pillar environment from which to compile pillar data. If not specified, then the minion's :conf_minion:`pillarenv` option is not used, and if that also is not specified then all configured pillar environments will be merged into a single pillar dictionary and returned. .. versionadded:: 2016.11.2 saltenv Included only for compatibility with :conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored. CLI Example: .. code-block:: bash salt '*' pillar.items r NZpillarenv_from_saltenvFr �pillar� pillar_encTZdecrypt_pillar_renderers)Ztranslate_newlines�optsZ valid_rendz#Failed to decrypt pillar override: �id)�pillar_overrider )�itemr r r! r"