Example #1
0
    def post(self):
        """ Handles raw query POST,
            such as stenoread's "curl -d 'QUERY_STRING'"
            or curl -d '{ "query" : "QUERY_STRING" }'
        """
        Config.logger.info("RAW request: {}".format(_get_request_nfo()))

        low = space_low()
        if low:
            from tasks import cleanup
            cleanup.apply_async(queue='io', kwargs={'force': True})
            Config.logger.error(low)
            return low

        q = Query()
        q.query = ''
        for k, v in request.form.lists():
            if k == 'query':
                q.query += v
                break
            elif not v or v == [u'']:
                q.query += k

        Config.logger.info("Raw query: {}".format(q.query))
        return q.enqueue()
Example #2
0
    def get(self, path):
        """ get  - build a query based on uri and enqueue it for processing
                 - return the ID, URL needed for a future get ID/MERGED_NAME.pcap request
        """
        Config.logger.info("URI request: {}".format(_get_request_nfo()))
        low = space_low()
        if low:
            from tasks import cleanup
            cleanup.apply_async(queue='io', kwargs={'force': True})
            Config.logger.error(low)
            return low, 413

        try:
            fields = parse_uri(path)
            q = Query(fields=fields)
        except BadRequest as e:
            return str(e), 400
        except ValueError as e:
            return str(e), 400

        result = q.enqueue()

        r = Response(response=dumps(result, default=json_serial),
                     status=302,
                     mimetype='application/json')
        statusUrl = '{}/#/status/{}'.format(Config.get('UI_WEB_ROOT', ''),
                                            result['id'])
        r.headers['Location'] = '{}'.format(statusUrl)
        return r
Example #3
0
    def get(self, query):
        Config.logger.info("RAW request: {}".format(_get_request_nfo()))

        low = space_low()
        if low:
            from tasks import cleanup
            cleanup.apply_async(queue='io', kwargs={'force': True})
            Config.logger.error(low)
            return low

        from urllib import unquote_plus
        q = Query(unquote_plus(query))
        Config.logger.info("Raw query: {}".format(q.query))
        return q.enqueue()
Example #4
0
    def post(self):
        """ post - build a query based on submitted form or json
                 - enqueue it for processing
                 - return the ID, URL needed for a future get ID/MERGED_NAME.pcap request
        """
        Config.logger.info("query request: {}".format(_get_request_nfo()))
        low = space_low()
        if low:
            from tasks import cleanup
            cleanup.apply_async(queue='io', kwargs={'force': True})
            Config.logger.error(low)
            return low, 413

        try:
            fields = parse_json()
            q = Query(fields=fields)
        except BadRequest as e:
            return str(e), 400
        except ValueError as e:
            return str(e), 400
        return q.enqueue()