File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/__pycache__/http_json.cpython-310.pyc
Back
o ;jm � @ sH 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_JSON ext_pillar ==================================== Set the following Salt config to setup http json result as external pillar source: .. code-block:: yaml ext_pillar: - http_json: url: http://example.com/api/minion_id namespace: 'subkey' 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>`: .. versionchanged:: 3006.0 If namespace is defined, the data will be added under the specified subkeys in the Pillar structure. 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_json: 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_json.py�__virtual__: 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 rf|rb|| d iS | d S t� d| |� | D ]}t� d|| | � qoi 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 auth: special auth if needed :param str username: username for auth :param str pasword: password for auth :param str namespace: (Optional) A pillar key to namespace the values under. .. versionadded:: 3006.0 :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.queryT�json)�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 � namespaceZ grain_pattern�matchr Zgrain_value�data�keyr r r � ext_pillar>