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/pillar/__pycache__/postgres.cpython-310.pyc
o

�N�gE�@szdZddlZddlmZddlmZe�e�Zzddl	Z	dZ
Wney*dZ
Ynwdd�ZGd	d
�d
e�Z
dd�ZdS)
a1
Retrieve Pillar data by doing a postgres query

.. versionadded:: 2017.7.0

:maturity: new
:depends: psycopg2
:platform: all

Complete Example
================

.. code-block:: yaml

    postgres:
      user: 'salt'
      pass: 'super_secret_password'
      db: 'salt_db'

    ext_pillar:
      - postgres:
          fromdb:
            query: 'SELECT col1,col2,col3,col4,col5,col6,col7
                      FROM some_random_table
                     WHERE minion_pattern LIKE %s'
            depth: 5
            as_list: True
            with_lists: [1,3]
�N)�contextmanager)�SqlBaseExtPillarTFcCstsdSdS)NFT)�HAS_POSTGRES�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/postgres.py�__virtual__/srcs@eZdZdZedd��Zdd�Zedd��Z�fdd	�Z	�Z
S)
�POSTGRESExtPillarzL
    This class receives and processes the database rows from POSTGRES.
    cCsdS)NZPOSTGRESr)�clsrrr�_db_name:szPOSTGRESExtPillar._db_namecCs\dddddd�}i}t�di�}|D]}||vr%t�d|�||||<q||||<q|S)zC
        Returns options used for the POSTGRES connection.
        Z	localhost�salti8)�host�user�pass�db�portZpostgreszUsing default for POSTGRES %s)Z__opts__�get�log�debug)�self�defaults�_optionsZ_opts�attrrrr�_get_options>s�zPOSTGRESExtPillar._get_optionsc
cs��|��}tj|d|d|d|d|dd�}|��}z3z
|Vt�d�WntjyB}z
t�d|j�WYd	}~nd	}~wwW|�	�d	SW|�	�d	S|�	�w)
z)
        Yield a POSTGRES cursor
        rr
rrr)rr
�passwordZdbnamerzConnected to POSTGRES DBz Error in ext_pillar POSTGRES: %sN)
r�psycopg2�connect�cursorrrZ
DatabaseError�	exception�args�close)rr�connr�errrrr�_get_cursorSs*������zPOSTGRESExtPillar._get_cursorcst��||�S)z�
        This function normalizes the config block into a set of queries we
        can use.  The return is a list of consistently laid out dicts.
        )�super�extract_queries)rr�kwargs��	__class__rrr$isz!POSTGRESExtPillar.extract_queries)�__name__�
__module__�__qualname__�__doc__�classmethodr
rrr"r$�
__classcell__rrr&rr5s

rcOst�j||g|�Ri|��S)zF
    Execute queries against POSTGRES, merge and return as a dict
    )rZfetch)Z	minion_idZpillarrr%rrr�
ext_pillarqsr.)r+�logging�
contextlibrZsalt.pillar.sql_baser�	getLoggerr(rrr�ImportErrorrrr.rrrr�<module>s
�<