File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/mongodb.cpython-310.pyc
Back
o ;j�v � @ s� d Z ddlZddlZddlZddlmZ ddlm Z zddl Z dZW n ey- dZY nw e� e�Zdd� Z d7d d�Zdd � Zd8dd�Zd8dd�Zd8dd�Zdd� Z d7dd�Z d7dd�Z d7dd�Z d7dd�Z d9dd�Z d7d d!�Z d8d"d#�Z d8d$d%�Z d8d&d'�Z d7d(d)�Z d7d*d+�Z! d7d,d-�Z" d7d.d/�Z# d7d0d1�Z$ d:d2d3�Z% 4 d;d5d6�Z&dS )<a� Module to provide MongoDB functionality to Salt :configuration: This module uses PyMongo, and accepts configuration details as parameters as well as configuration settings:: mongodb.host: 'localhost' mongodb.port: 27017 mongodb.user: '' mongodb.password: '' This data can also be passed into pillar. Options passed into opts will overwrite options passed into pillar. � N)�get_error_message)�VersionTFc C s t rdS dS )z7 Only load this module if pymongo is installed Zmongodb)FzTThe mongodb execution module cannot be loaded: the pymongo library is not available.)�HAS_MONGODB� r r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/mongodb.py�__virtual__! s r �adminc C s� | st d d�} |st d d�}|st d d�}|s t d d�}|s$|}z#tj||d�}tj�||�}| rB|rE|j| ||d� W |S W |S W |S tjjyY t� d|� Y d S w ) zv Returns a tuple of (user, host, port) with config, pillar, or default values assigned to missing values. z config.optionzmongodb.userzmongodb.passwordzmongodb.hostzmongodb.port)�host�port)�sourcezError connecting to database %sF) Z__salt__�pymongoZMongoClient�database�DatabaseZauthenticate�errors�PyMongoError�log�error)�user�passwordr r r �authdb�conn�mdbr r r �_connect/ s0 ����r c C sL zt | t�rtjj�| �} W | S W | S ty% } zt�d|� � d}~ww )zF Potentially interprets a string as JSON for usage with mongo zCould not parse objects: %sN) � isinstance�str�salt�utils�json�loads� ValueErrorr r )�objects�errr r r �_to_dictM s ����r"