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__/mysql.cpython-310.pyc
o

�N�g�@s�dZddlZddlmZddlmZe�e�Zzddl	Z	ddl
Z	ddlZ	Wn+eyPzddl
Z
e
��ddl	Z	ddl
Z	ddlZ	WneyMdZ	YnwYnwdd�ZGdd�de�Zd	d
�ZdS)a�
Retrieve Pillar data by doing a MySQL query

MariaDB provides Python support through the MySQL Python package.
Therefore, you may use this module with both MySQL or MariaDB.

This module is a concrete implementation of the sql_base ext_pillar for MySQL.

:maturity: new
:depends: python-mysqldb
:platform: all

Configuring the mysql ext_pillar
================================

Use the 'mysql' key under ext_pillar for configuration of queries.

MySQL configuration of the MySQL returner is being used (mysql.db, mysql.user,
mysql.pass, mysql.port, mysql.host) for database connection info.

Required python modules: MySQLdb

Complete example
================

.. code-block:: yaml

    mysql:
      user: 'salt'
      pass: 'super_secret_password'
      db: 'salt_db'
      port: 3306
      ssl:
        cert: /etc/mysql/client-cert.pem
        key: /etc/mysql/client-key.pem

    ext_pillar:
      - mysql:
          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)�SqlBaseExtPillarcCstt�tdur
dfSdfS)z:
    Confirm that a python mysql client is installed.
    Nz!No python mysql client installed.�)�bool�MySQLdb�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/mysql.py�__virtual__Jsr	cs@eZdZdZedd��Zdd�Zedd��Z�fdd	�Z	�Z
S)
�MySQLExtPillarzI
    This class receives and processes the database rows from MySQL.
    cCsdS)NZMySQLr)�clsrrr�_db_nameVszMySQLExtPillar._db_namecCs^dddddid�}i}t�di�}|D]}||vr&t�d|�||||<q||||<q|S)z@
        Returns options used for the MySQL connection.
        Z	localhost�salti�)�host�user�pass�db�port�sslZmysqlzUsing default for MySQL %s)Z__opts__�get�log�debug)�self�defaults�_optionsZ_opts�attrrrr�_get_optionsZs �zMySQLExtPillar._get_optionsc
cs��|��}tj|d|d|d|d|d|dd�}|��}z.z|VWntjy@}z
t�d|j�WYd	}~nd	}~wwW|��d	SW|��d	S|��w)
z&
        Yield a MySQL cursor
        rrrrrr)rr�passwdrrrzError in ext_pillar MySQL: %sN)	rr�connect�cursorZ
DatabaseErrorr�	exception�args�close)rr�connr�errrrr�_get_cursorps*��
����zMySQLExtPillar._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&�szMySQLExtPillar.extract_queries)�__name__�
__module__�__qualname__�__doc__�classmethodrrrr$r&�
__classcell__rrr(rr
Qs

r
cOst�j||g|�Ri|��S)zC
    Execute queries against MySQL, merge and return as a dict
    )r
Zfetch)Z	minion_idZpillarr r'rrr�
ext_pillar�sr0)r-�logging�
contextlibrZsalt.pillar.sql_baser�	getLoggerr*rrZMySQLdb.convertersZMySQLdb.cursors�ImportErrorZpymysqlZinstall_as_MySQLdbr	r
r0rrrr�<module>s0/
���
=