fix: safer call to webhook

This commit is contained in:
Simone Margaritelli 2019-10-25 19:32:11 +02:00
parent 4aa29f1b79
commit c0252c9830
2 changed files with 14 additions and 3 deletions

View File

@ -16,7 +16,19 @@ def on(event_name, *args, **kwargs):
cb_name = 'on_%s' % event_name
for plugin_name, plugin in loaded.items():
if cb_name in plugin.__dict__:
# print("calling %s %s(%s)" %(cb_name, args, kwargs))
try:
plugin.__dict__[cb_name](*args, **kwargs)
except Exception as e:
logging.error("error while running %s.%s : %s" % (plugin_name, cb_name, e))
logging.error(e, exc_info=True)
def one(plugin_name, event_name, *args, **kwargs):
global loaded
if plugin_name in loaded:
plugin = loaded[plugin_name]
cb_name = 'on_%s' % event_name
if cb_name in plugin.__dict__:
try:
plugin.__dict__[cb_name](*args, **kwargs)
except Exception as e:

View File

@ -166,8 +166,7 @@ class Handler(BaseHTTPRequestHandler):
if plugin_from_path:
plugin_name = plugin_from_path.groups()[0]
right_path = plugin_from_path.groups()[1] if len(plugin_from_path.groups()) == 2 else None
if plugin_name in plugins.loaded and hasattr(plugins.loaded[plugin_name], 'on_webhook'):
plugins.loaded[plugin_name].on_webhook(self, right_path)
plugins.one(plugin_name, 'webhook', right_path)
else:
self.send_response(404)