File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/__pycache__/http_yaml.cpython-310.pyc
o
�N�gI � @ sF d Z ddlZddlZddlZe�e�Zdd� Z ddd�Z dS ) a�
A module that adds data to the Pillar structure retrieved by an http request
Configuring the HTTP_YAML ext_pillar
====================================
Set the following Salt config to setup an http endpoint as the external pillar source:
.. code-block:: yaml
ext_pillar:
- http_yaml:
url: http://example.com/api/minion_id
username: username
password: password
header_dict: None
auth: None
You can pass additional parameters, they will be added to the http.query call
:py:func:`utils.http.query function <salt.utils.http.query>`:
If the with_grains parameter is set, grain keys wrapped in can be provided (wrapped
in <> brackets) in the url in order to populate pillar data based on the grain value.
.. code-block:: yaml
ext_pillar:
- http_yaml:
url: http://example.com/api/<nodename>
with_grains: True
.. versionchanged:: 2018.3.0
If %s is present in the url, it will be automatically replaced by the minion_id:
.. code-block:: yaml
ext_pillar:
- http_json:
url: http://example.com/api/%s
Module Documentation
====================
� Nc C s dS )NT� r r r �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/http_yaml.py�__virtual__6 s r Fc C s� |� dtj�| ��}d}|rCt�||�D ].} | �d�}
td |
d�}|s/t� d| |
� i S tj�t
|��}t�d|
� d�||�}qt�d |� td
|dd||||d
�}d|v r^|d S t� d| |� |D ]}
t� d|
||
� qgi S )a�
Read pillar data from HTTP response.
:param str url: Url to request.
:param bool with_grains: Whether to substitute strings in the url with their grain values.
:param dict header_dict: Extra headers to send
:param str username: username for auth
:param str pasword: password for auth
:param auth: special auth if needed
:return: A dictionary of the pillar data to add.
:rtype: dict
z%sz<(?P<grain_name>.*?)>�
grain_namez
grains.getNz#Unable to get minion '%s' grain: %s�<�>zGetting url: %sz
http.queryTZyaml)�url�decodeZdecode_type�header_dict�auth�username�password�dictz/Error on minion '%s' http query: %s
More Info:
z%s: %s)
�replace�urllib�parse�quote�re�finditer�groupZ__salt__�log�error�str�sub�debug)Z minion_idZpillarr Zwith_grainsr
r r r
Z
grain_pattern�matchr Zgrain_value�data�keyr r r �
ext_pillar: s6
�
r )FNNNN)
�__doc__�loggingr �urllib.parser � getLogger�__name__r r r r r r r �<module> s .
�