def returner(ret):
    '''
    Take in the return and shove it into the couchdb database.
    '''

    options = _get_options(ret)

    # Check to see if the database exists.
    _response = _request("GET",
                         options['url'] + "_all_dbs",
                         user=options['user'],
                         passwd=options['passwd'])
    if options['db'] not in _response:

        # Make a PUT request to create the database.
        _response = _request("PUT",
                             options['url'] + options['db'],
                             user=options['user'],
                             passwd=options['passwd'])

        # Confirm that the response back was simple 'ok': true.
        if 'ok' not in _response or _response['ok'] is not True:
            log.error('Nothing logged! Lost data. Unable to create database "%s"', options['db'])
            log.debug('_response object is: %s', _response)
            return
        log.info('Created database "%s"', options['db'])

    if boltons_lib:
        # redact all passwords if options['redact_pws'] is True
        if options['redact_pws']:
            ret_remap_pws = remap(ret, visit=_redact_passwords)
        else:
            ret_remap_pws = ret

        # remove all return values starting with '__pub' if options['minimum_return'] is True
        if options['minimum_return']:
            ret_remapped = remap(ret_remap_pws, visit=_minimize_return)
        else:
            ret_remapped = ret_remap_pws
    else:
        log.info('boltons library not installed. pip install boltons. https://github.com/mahmoud/boltons.')
        ret_remapped = ret

    # Call _generate_doc to get a dict object of the document we're going to shove into the database.
    doc = _generate_doc(ret_remapped)

    # Make the actual HTTP PUT request to create the doc.
    _response = _request("PUT",
                         options['url'] + options['db'] + "/" + doc['_id'],
                         'application/json',
                         salt.utils.json.dumps(doc))

    # Sanity check regarding the response..
    if 'ok' not in _response or _response['ok'] is not True:
        log.error('Nothing logged! Lost data. Unable to create document: "%s"', _response)
def returner ( ret ) : options = _get_options ( ret ) _response = _request ( "GET" , options [ 'url' ] + "_all_dbs" , user = options [ 'user' ] , passwd = options [ 'passwd' ] ) if options [ 'db' ] not in _response : _response = _request ( "PUT" , options [ 'url' ] + options [ 'db' ] , user = options [ 'user' ] , passwd = options [ 'passwd' ] ) if 'ok' not in _response or _response [ 'ok' ] is not True : log . error ( 'Nothing logged! Lost data. Unable to create database "%s"' , options [ 'db' ] ) log . debug ( '_response object is: %s' , _response ) return log . info ( 'Created database "%s"' , options [ 'db' ] ) if boltons_lib : if options [ 'redact_pws' ] : ret_remap_pws = remap ( ret , visit = _redact_passwords ) else : ret_remap_pws = ret if options [ 'minimum_return' ] : ret_remapped = remap ( ret_remap_pws , visit = _minimize_return ) else : ret_remapped = ret_remap_pws else : log . info ( 'boltons library not installed. pip install boltons. https://github.com/mahmoud/boltons.' ) ret_remapped = ret doc = _generate_doc ( ret_remapped ) _response = _request ( "PUT" , options [ 'url' ] + options [ 'db' ] + "/" + doc [ '_id' ] , 'application/json' , salt . utils . json . dumps ( doc ) ) if 'ok' not in _response or _response [ 'ok' ] is not True : log . error ( 'Nothing logged! Lost data. Unable to create document: "%s"' , _response )
Take in the return and shove it into the couchdb database.