HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/cache/__pycache__/etcd_cache.cpython-310.pyc
o

�N�g=�@s�dZddlZddlZddlZddlZddlmZzddlZdZ	Wne
y+dZ	YnwdZe	r7ej�
ej�e�e�ZdadadadZd	d
iZdd�Zd
d�Zdd�Zdd�Zddd�Zdd�Zdd	�Zdd�Zdd�ZdS)a
Minion data cache plugin for Etcd key/value data store.

.. versionadded:: 2018.3.0
.. versionchanged:: 3005

It is up to the system administrator to set up and configure the Etcd
infrastructure. All is needed for this plugin is a working Etcd agent
with a read-write access to the key-value store.

The related documentation can be found in the `Etcd documentation`_.

To enable this cache plugin, the master will need the python client for
Etcd installed. This can be easily installed with pip:

.. code-block:: bash

    pip install python-etcd

.. note::

    While etcd API v3 has been implemented in other places within salt,
    etcd_cache does not support it at this time due to fundamental differences in
    how the versions are designed and v3 not being compatible with the cache API.

Optionally, depending on the Etcd agent configuration, the following values
could be set in the master config. These are the defaults:

.. code-block:: yaml

    etcd.host: 127.0.0.1
    etcd.port: 2379
    etcd.protocol: http
    etcd.allow_reconnect: True
    etcd.allow_redirect: False
    etcd.srv_domain: None
    etcd.read_timeout: 60
    etcd.username: None
    etcd.password: None
    etcd.cert: None
    etcd.ca_cert: None

Related docs could be found in the `python-etcd documentation`_.

To use the etcd as a minion data cache backend, set the master ``cache`` config
value to ``etcd``:

.. code-block:: yaml

    cache: etcd

In Phosphorus, ls/list was changed to always return the final name in the path.
This should only make a difference if you were directly using ``ls`` on paths
that were more or less nested than, for example: ``1/2/3/4``.

.. _`Etcd documentation`: https://github.com/coreos/etcd
.. _`python-etcd documentation`: http://python-etcd.readthedocs.io/en/latest/

�N)�SaltCacheErrorTFz/salt_cachez.tstamp�etcd�ls�listcCstsdStS)z8
    Confirm that python-etcd package is installed.
    )Fz@Please install python-etcd package to use etcd data cache driver)�HAS_ETCD�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/cache/etcd_cache.py�__virtual__^sr
cCstdurdSt�dd�t�dd�t�dd�t�dd	�t�d
d�t�dd�t�d
d�t�dd�t�dd�t�dd�t�dd�d�}t�dt�at�dt�atdkrXd�t�d��at�	d|�t
jdi|��azt�t�WdSt
j
y�t�	dt�tjtdd	d�YdSw)z Setup client and init datastore.Nz	etcd.hostz	127.0.0.1z	etcd.portiK	z
etcd.protocol�httpzetcd.allow_reconnectTzetcd.allow_redirectFzetcd.srv_domainzetcd.read_timeout�<z
etcd.usernamez
etcd.passwordz	etcd.certzetcd.ca_cert)�host�port�protocolZallow_reconnectZallow_redirectZ
srv_domainZread_timeout�username�password�certZca_certzetcd.timestamp_suffixzetcd.path_prefix�z/{}�/z'etcd: Setting up client with params: %rzetcd: Creating dir %r)�dirr)�clientZ__opts__�get�_tstamp_suffix�_DEFAULT_PATH_PREFIX�path_prefix�format�strip�log�inforZClient�read�EtcdKeyNotFound�write)Zetcd_kwargsrrr	�_init_clientks4










�
�r"c
Cs�t�t�d|�d|��}t�d|�d|t��}ztj�|�}t�|t�	|��t�|t
t����WdStyK}z
t
d|�d|����d}~ww)z
    Store a key value.
    rz$There was an error writing the key, �: N)r"rr�salt�payload�dumpsrr!�base64�	b64encode�int�time�	Exceptionr)�bank�key�data�etcd_keyZetcd_tstamp_key�value�excrrr	�store�s��r2c
Cs~t�t�d|�d|��}zt�|�j}tj�t�	|��WSt
jy)iYSty>}z
t
d|�d|����d}~ww)z
    Fetch a key value.
    r�$There was an error reading the key, r#N)r"rrrr0r$r%�loadsr'�	b64decoderr r+r)r,r-r/r0r1rrr	�fetch�s��r6c
Cs�t�|durt�d|��}d}nt�d|�d|��}t�d|�d|t��}zt�|�Wntjy9YdSwz|rBt�|�tj|dd�WdStya}z
t	d|�d|����d}~ww)zF
    Remove the key from the cache bank with all the key content.
    NrT)�	recursivez%There was an error removing the key, r#)
r"rrrrrr �deleter+r)r,r-r/�
tstamp_keyr1rrr	�flush�s&�
��r:cCsT|js|j�t�rgS|j�dd�dgSg}t�|j�jD]	}|�t	|��q|S)zV
    Recursively walk dirs. Return flattened list of keys.
    r: etcd.EtcdResult
    r����)
rr-�endswithr�rsplitrr�children�extend�_walk)�r�keys�crrr	rA�srAc
Csjt�t�d|��}ztt�|��WStjygYSty4}ztd|�d|���|�d}~ww)z\
    Return an iterable object containing all entries stored in the specified
    bank.
    rz$There was an error getting the key "z": N)	r"rrArrrr r+r)r,�pathr1rrr	r�s����c
Cs�t�d�t||p
d�}zt�|�}|dur|jWS|jduWStjy*YdSty?}z
t	d|�d|����d}~ww)zB
    Checks if the specified bank contains the specified key.
    z{}/{}/{}rNFz$There was an error getting the key, r#)
r"rrrrrrr r+r)r,r-r/rBr1rrr	�contains�s
��rFc
Csvt�t�d|�d|t��}zt�|�j}t|�WStjy%YdSt	y:}z
t
d|�d|����d}~ww)zM
    Return Unix Epoch based timestamp of when the bank/key was updated.
    rNr3r#)r"rrrrr0r)rr r+r)r,r-r9r0r1rrr	�updated�s
��rG)N) �__doc__r'�loggingr*Zsalt.payloadr$Zsalt.exceptionsrrr�ImportErrorr�_log�setLevel�INFO�	getLogger�__name__rrrrrZ__func_alias__r
r"r2r6r:rArrFrGrrrr	�<module>s<<�