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

�N�g��@s�dZddlZddlZddlZddlmZzddlZdZWne	y'dZYnwe�
e�Zda
dadZdd	iZd
d�Zdd
�Zdd�Zddd�Zdd�Zdd�Zdd�ZdS)a�
Minion data cache plugin for Consul key/value data store.

.. versionadded:: 2016.11.2

.. versionchanged:: 3005

    Timestamp/cache updated support added.

:depends: python-consul >= 0.2.0

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

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

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

.. code-block:: bash

    pip install python-consul

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

.. code-block:: yaml

    consul.host: 127.0.0.1
    consul.port: 8500
    consul.token: None
    consul.scheme: http
    consul.consistency: default
    consul.dc: dc1
    consul.verify: True
    consul.timestamp_suffix: .tstamp  # Added in 3005.0

In order to bring the cache APIs into conformity, in 3005.0 timestamp
information gets stored as a separate ``{key}.tstamp`` key/value. If your
existing functionality depends on being able to store normal keys with the
``.tstamp`` suffix, override the ``consul.timestamp_suffix`` default config.

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

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

.. code-block:: yaml

    cache: consul


.. _`Consul documentation`: https://www.consul.io/docs/index.html
.. _`python-consul documentation`: https://python-consul.readthedocs.io/en/latest/#consul

�N)�SaltCacheErrorTFz.tstamp�consul�list_�listc
Cs�tsdSt�dd�t�dd�t�dd�t�dd	�t�d
d�t�dd�t�d
d�d�}zt�dt�atjdi|��aWtStyEYdSw)z9
    Confirm this python-consul package is installed
    )FzDPlease install python-consul package to use consul data cache driverzconsul.hostz	127.0.0.1zconsul.porti4!zconsul.tokenNz
consul.scheme�httpzconsul.consistency�defaultz	consul.dcz
consul.verifyT)�host�port�token�schemeZconsistencyZdcZverifyzconsul.timestamp_suffix)FzZFailed to invoke consul.Consul, please make sure you have python-consul >= 0.2.0 installed�)	�
HAS_CONSULZ__opts__�get�_tstamp_suffixrZConsul�api�AttributeError�__virtualname__)Z
consul_kwargsrr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/cache/consul.py�__virtual__Ts"






�
��rc
Cs�|�d|��}|�d|�t��}ztj�|�}tj�||�tj�|tj�tt�����WdSt	yE}z
t
d|�d|����d}~ww)z
    Store a key value.
    �/z$There was an error writing the key, �: N)r�salt�payload�dumpsr�kv�put�int�time�	Exceptionr)�bank�key�data�c_key�
tstamp_keyZc_data�excrrr�storevs$��r%c
Csl|�d|��}ztj�|�\}}|duriWStj�|d�WSty5}z
td|�d|����d}~ww)z
    Fetch a key value.
    rN�Value�$There was an error reading the key, r)rrrrr�loadsrr�rr r"�_�valuer$rrr�fetch�s��r,c
Cs�|dur	|}d}n|�d|��}|�d|�t��}z|r"tj�|�tjj||dud�WStyB}z
td|�d|����d}~ww)zF
    Remove the key from the cache bank with all the key content.
    Nr)Zrecursez%There was an error removing the key, r)rrr�deleterr)rr r"r#r$rrr�flush�s��r.c
Cs�ztjj|dddd�\}}Wnty%}z
td|�d|����d}~ww|dur.g}|St�}|D]}|�|t|�dd��d��q3dd	�|D�}|S)
zX
    Return an iterable object containing all entries stored in the specified bank.
    rT)�keys�	separatorz$There was an error getting the key "z": N�cSsg|]	}|�t�s|�qSr)�endswithr)�.0�orrr�
<listcomp>�szlist_.<locals>.<listcomp>)	rrrrr�set�add�len�rstrip)rr*r/r$�outr rrrr�s���"c
Cs\zd�||pd�}tjj|dd�\}}W|duSty-}z
td|�d|����d}~ww)zB
    Checks if the specified bank contains the specified key.
    z{}/{}�T)r/z$There was an error getting the key, rN)�formatrrrrrr)rrr�contains�s���r=c
Csp|�d|�t��}ztj�|�\}}|durWdStj�|d�WSty7}z
td|�d|����d}~ww)zp
    Return the Unix Epoch timestamp of when the key was last updated. Return
    None if key is not found.
    rNr&r'r)	rrrrrrr(rrr)rrr�updated�s��r>)N)�__doc__�loggingrZsalt.payloadrZsalt.exceptionsrrr
�ImportError�	getLogger�__name__�logrrrZ__func_alias__rr%r,r.rr=r>rrrr�<module>s.:�
"