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/states/__pycache__/etcd_mod.cpython-310.pyc
o

�N�g�+�@s�dZdZddiZzddlZejjjsejjjrdZ	ndZ	Wne
y(dZ	YnwdZd	d
�Zdd�dd
�Z
ddd�Zddd�Zddd�Zddd�Zddd�Zdd�ZdS)a�
Manage etcd Keys
================

.. versionadded:: 2015.8.0

:depends:  - python-etcd or etcd3-py

This state module supports setting and removing keys from etcd.

Configuration
-------------

To work with an etcd server you must configure an etcd profile. The etcd config
can be set in either the Salt Minion configuration file or in pillar:

.. code-block:: yaml

    my_etd_config:
      etcd.host: 127.0.0.1
      etcd.port: 4001

It is technically possible to configure etcd without using a profile, but this
is not considered to be a best practice, especially when multiple etcd servers
or clusters are available.

.. code-block:: yaml

    etcd.host: 127.0.0.1
    etcd.port: 4001

In order to choose whether to use etcd API v2 or v3, you can put the following
configuration option in the same place as your etcd configuration.  This option
defaults to true, meaning you will use v2 unless you specify otherwise.

.. code-block:: yaml

    etcd.require_v2: True

When using API v3, there are some specific options available to be configured
within your etcd profile.  They are defaulted to the following...

.. code-block:: yaml

    etcd.encode_keys: False
    etcd.encode_values: True
    etcd.raw_keys: False
    etcd.raw_values: False
    etcd.unicode_errors: "surrogateescape"

``etcd.encode_keys`` indicates whether you want to pre-encode keys using msgpack before
adding them to etcd.

.. note::

    If you set ``etcd.encode_keys`` to ``True``, all recursive functionality will no longer work.
    This includes ``tree`` and ``ls`` and all other methods if you set ``recurse``/``recursive`` to ``True``.
    This is due to the fact that when encoding with msgpack, keys like ``/salt`` and ``/salt/stack`` will have
    differing byte prefixes, and etcd v3 searches recursively using prefixes.

``etcd.encode_values`` indicates whether you want to pre-encode values using msgpack before
adding them to etcd.  This defaults to ``True`` to avoid data loss on non-string values wherever possible.

``etcd.raw_keys`` determines whether you want the raw key or a string returned.

``etcd.raw_values`` determines whether you want the raw value or a string returned.

``etcd.unicode_errors`` determines what you policy to follow when there are encoding/decoding errors.

.. note::

    The etcd configuration can also be set in the Salt Master config file,
    but in order to use any etcd configurations defined in the Salt Master
    config, the :conf_master:`pillar_opts` must be set to ``True``.

    Be aware that setting ``pillar_opts`` to ``True`` has security implications
    as this makes all master configuration settings available in all minion's
    pillars.

Etcd profile configuration can be overridden using following arguments: ``host``,
``port``, ``username``, ``password``, ``ca``, ``client_key`` and ``client_cert``.
The v3 specific arguments can also be used for overriding if you are using v3.

.. code-block:: yaml

    my-value:
      etcd.set:
        - name: /path/to/key
        - value: value
        - host: 127.0.0.1
        - port: 2379
        - username: user
        - password: pass

Available Functions
-------------------

- ``set``

  This will set a value to a key in etcd. Changes will be returned if the key
  has been created or the value of the key has been updated. This
  means you can watch these states for changes.

  .. code-block:: yaml

      /foo/bar/baz:
        etcd.set:
          - value: foo
          - profile: my_etcd_config

- ``wait_set``

  Performs the same functionality as ``set`` but only if a watch requisite is ``True``.

  .. code-block:: yaml

      /some/file.txt:
        file.managed:
          - source: salt://file.txt

      /foo/bar/baz:
        etcd.wait_set:
          - value: foo
          - profile: my_etcd_config
          - watch:
            - file: /some/file.txt

- ``rm``

  This will delete a key from etcd. If the key exists then changes will be
  returned and thus you can watch for changes on the state, if the key does
  not exist then no changes will occur.

  .. code-block:: yaml

      /foo/bar/baz:
        etcd.rm:
          - profile: my_etcd_config

- ``wait_rm``

  Performs the same functionality as ``rm`` but only if a watch requisite is ``True``.

  .. code-block:: yaml

      /some/file.txt:
        file.managed:
          - source: salt://file.txt

      /foo/bar/baz:
        etcd.wait_rm:
          - profile: my_etcd_config
          - watch:
            - file: /some/file.txt
Zetcd�set_�set�NTFz7No profile found, using a profile is always recommendedcCstrtSdS)z1
    Only return if python-etcd is installed
    )FzUnable to import etcd_util)�HAS_LIBS�__virtualname__�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/etcd_mod.py�__virtual__�sr)�valuecKs@ztd|��d|||d�|��}W|Styd}Y|Sw)Nzetcd.)�key�profiler	r)�__salt__�	Exception)�actionr
rr	�kwargs�retrrr�_etcd_action�s����rcKs�d}|ddid�}tdd||d�|��}|dur&|dur&t|d<d|d	<|S|s*d}tdd
|||d�|��}|rM||krM|rCd|d<nd
|d<||i|d<|S)a�
    Set a key in etcd

    name
        The etcd key name, for example: ``/foo/bar/baz``.
    value
        The value the key should contain.

    profile
        Optional, defaults to ``None``. Sets the etcd profile to use which has
        been defined in the Salt Master config.

        .. code-block:: yaml

            my_etd_config:
              etcd.host: 127.0.0.1
              etcd.port: 4001

    FzKey contains correct valueT��name�comment�result�changes�get)rr
rNrrr)rr
r	rzNew key createdzKey value updatedrr)r�NO_PROFILE_MSG)rr	rr�created�rtn�currentrrrrr�s0���
cK�|iddd�S)a�
    Set a key in etcd only if the watch statement calls it. This function is
    also aliased as ``wait_set``.

    name
        The etcd key name, for example: ``/foo/bar/baz``.
    value
        The value the key should contain.
    profile
        The etcd profile to use that has been configured on the Salt Master,
        this is optional and defaults to ``None``.

        .. code-block:: yaml

            my_etd_config:
              etcd.host: 127.0.0.1
              etcd.port: 4001

    T��rrrrr)rr	rrrrr�wait_set��rcKs�d}|ddid�}tdd||dd�|��}|dur'|dur't|d<d|d	<|S|s+d}td
|dfd|d�|��}|rK||krK|rKd|d<|d
i|d<|S)au
    Create a directory in etcd.

    name
        The etcd directory name, for example: ``/foo/bar/baz``.
    profile
        Optional, defaults to ``None``. Sets the etcd profile to use which has
        been defined in the Salt Master config.

        .. code-block:: yaml

            my_etd_config:
              etcd.host: 127.0.0.1
              etcd.port: 4001
    FzDirectory existsTrr�rr
r�recurseNrrzetcd.set)�	directoryrzNew directory created�Createdrr�rrr)rrrrrrrrrrr#s&��r#cKs�|did�}tdd||dd�|��}|dur$|dur$t|d<d|d<|S|s,d	|d<|Std
|f||d�|��rEd|d<|d
i|d<|Sd|d<|S)a�
    Deletes a key from etcd

    name
        The etcd key name to remove, for example ``/foo/bar/baz``.

    recurse
        Optional, defaults to ``False``. If ``True`` performs a recursive delete.

    profile
        Optional, defaults to ``None``. Sets the etcd profile to use which has
        been defined in the Salt Master config.

        .. code-block:: yaml

            my_etd_config:
              etcd.host: 127.0.0.1
              etcd.port: 4001
    T)rrrrr!NrFrzKey does not existzetcd.rm)r"rzKey removedZDeletedrzUnable to remove keyrr%)rr"rrrrrrr�rm>s&���r&cKr)as
    Deletes a key from etcd only if the watch statement calls it.
    This function is also aliased as ``wait_rm``.

    name
        The etcd key name to remove, for example ``/foo/bar/baz``.
    recurse
        Optional, defaults to ``False``. If ``True`` performs a recursive
        delete, see: https://python-etcd.readthedocs.io/en/latest/#delete-a-key.
    profile
        Optional, defaults to ``None``. Sets the etcd profile to use which has
        been defined in the Salt Master config.

        .. code-block:: yaml

            my_etd_config:
              etcd.host: 127.0.0.1
              etcd.port: 4001
    Trrr)rr"rrrrr�wait_rmkr r'cKs\|�d�dvrt||�d�|�d�d�S|�d�dvr$t||�d�d�S|id�|�dd	�S)
az
    The etcd watcher, called to invoke the watch command.
    When called, execute a etcd function based on a watch call requisite.

    .. note::
        This state exists to support special handling of the ``watch``
        :ref:`requisite <requisites>`. It should not be called directly.

        Parameters for this function should be set by the state being triggered.
    Zsfun)Zwait_set_keyrr	r)r)Zwait_rm_keyr'z_etcd.{0[sfun]} does not work with the watch requisite, please use etcd.wait_set or etcd.wait_rmF)rrrr)rrr&�format)rrrrr�	mod_watch�s
�r))N)FN)�__doc__rZ__func_alias__Zsalt.utils.etcd_util�salt�utilsZ	etcd_utilZHAS_ETCD_V2ZHAS_ETCD_V3r�ImportErrorrrrrrr#r&r'r)rrrr�<module>s.���	


6

+
-