Supporting body both as dict and str

This commit is contained in:
Fabio Manganiello 2017-11-03 16:48:48 +01:00
parent 99a93012ce
commit bdcc6bcf1c

View file

@ -69,15 +69,21 @@ def _init_plugin(plugin, reload=False):
def _exec_func(body, retry=True): def _exec_func(body, retry=True):
try: args = {}
logging.info('Received push addressed to me: {}'.format(body)) logging.info('Received push addressed to me: {}'.format(body))
args = json.loads(body['args']) if 'args' in body else {}
if 'plugin' not in body: if 'plugin' not in body:
logging.warn('No plugin specified') logging.warn('No plugin specified')
return return
plugin_name = body['plugin'] plugin_name = body['plugin']
if 'args' in body:
args = json.loads(body['args']) \
if isinstance(body['args'], str) \
else body['args']
try:
try: try:
plugin = _init_plugin(plugin_name) plugin = _init_plugin(plugin_name)
except RuntimeError as e: # Module/class not found except RuntimeError as e: # Module/class not found