mirror of https://github.com/MISP/misp-modules
Make misp-modules really asynchronous
parent
d6388e1c52
commit
c822c2df9c
|
@ -22,8 +22,6 @@
|
|||
import os
|
||||
import signal
|
||||
import sys
|
||||
from tornado.ioloop import IOLoop
|
||||
import tornado.web
|
||||
import importlib
|
||||
import json
|
||||
import logging
|
||||
|
@ -31,6 +29,11 @@ import fnmatch
|
|||
import argparse
|
||||
import re
|
||||
|
||||
import tornado.web
|
||||
from tornado.ioloop import IOLoop
|
||||
from tornado.concurrent import run_on_executor
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
try:
|
||||
from .modules import *
|
||||
HAS_PACKAGE_MODULES = True
|
||||
|
@ -166,23 +169,23 @@ class ListModules(tornado.web.RequestHandler):
|
|||
self.write(json.dumps(ret))
|
||||
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def async_module(request, write_fct):
|
||||
jsonpayload = request.body.decode('utf-8')
|
||||
x = json.loads(jsonpayload)
|
||||
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
|
||||
ret = mhandlers[x['module']].handler(q=jsonpayload)
|
||||
write_fct(json.dumps(ret))
|
||||
|
||||
|
||||
class QueryModule(tornado.web.RequestHandler):
|
||||
executor = ThreadPoolExecutor(None)
|
||||
|
||||
@run_on_executor
|
||||
def run_request(self, jsonpayload):
|
||||
x = json.loads(jsonpayload)
|
||||
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
|
||||
return mhandlers[x['module']].handler(q=jsonpayload)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def post(self):
|
||||
global mhandlers
|
||||
try:
|
||||
yield async_module(self.request, self.write)
|
||||
jsonpayload = self.request.body.decode('utf-8')
|
||||
response = yield self.run_request(jsonpayload)
|
||||
self.write(json.dumps(response))
|
||||
except Exception:
|
||||
log.exception("Someting bad happened.")
|
||||
log.exception('Something went wrong:')
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Reference in New Issue