File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/sdb/__pycache__/couchdb.cpython-310.pyc
o
�N�g_ � @ s� d Z ddlZddlmZ ddlmZ zddlZdZW n ey% dZY nw e� e
�ZddiZd d
� Z
edd� �Zd
d� Zddd�Zddd�Zdd� ZdS )a�
CouchDB sdb Module
:maintainer: SaltStack
:maturity: New
:depends: python2-couchdb
:platform: all
This allow interaction between Salt and a CouchDB [couchdb.apache.org]
database. It uses salt's `sdb` system to allow for inserts and retrevals
using the `sdb://` prefix in salt configuration files.
To use the couchbase sdb module, it must first be configured in the salt
master or minion config. The following arguments are required:
.. code-block:: yaml
couchdb_sdb:
driver: couchdb
host: localhost
port: 5984
database: salt_sdb
One could then query the CouchDB instance via an `sdb://` URI such as the
following:
.. code-block:: yaml
password: sdb://couchdb_sdb/mykey
To use this interface, you must track IDs on your own or have another source
to do the map-reduce logic necessary to calculate the ID you wish to fetch.
Additional contributions to build true map-reduce functionality into this module
would be welcome.
� N)�uuid4)�memoizeTF�set_�setc C s t S )z/
Require the python2-couchdb libraries
)� HAS_COUCH� r r �D/opt/saltstack/salt/lib/python3.10/site-packages/salt/sdb/couchdb.py�__virtual__; s r c C s dj di | ��S )z�
Examine configuration and return
a uri for the couchdb server in the following format:
.. code-block:: bash
http://localhost:5984/
zhttp://{host}:{port}Nr )�format)�profiler r r �_construct_uriB s
r c C s2 t | �pd}t�� }| d |vr|�| d � |S )z%
Get a connection to CouchDB
zhttp://localhost:5984Zdatabase)r �couchdbZServer�create)r ZDEFAULT_BASE_URL�serverr r r � _get_connO s
r c C s t |�}|�dt� j| |i�S )z)
Set a key/value pair in couchdb
Z_id)�_get_dbZsaver �hex)�key�valuer �dbr r r r [ s c C s t |�}|�| �S )z(
Get a value from couchdb by id
)r �get)r r r r r r r c s
r c C s t | �}t| �}|S )z*
Wraps _get_conn() to return a db
)r r )r r r r r r r k s r )N)�__doc__�loggingZuuidr Zsalt.utils.decoratorsr r
r �ImportError� getLogger�__name__�logZ__func_alias__r r r r r r r r r r �<module> s&