def run()

in core/actionProxy/actionproxy.py [0:0]


def run(message=None):
    def error():
        response = flask.jsonify({'error': 'The action did not receive a dictionary or array as an argument.'})
        response.status_code = 404
        return complete(response)

    # If we have a message use that, if not try using the request json if it exists (returns None on no JSON)
    # otherwise just make it an empty dictionary
    message = message or flask.request.get_json(force=True, silent=True) or {}
    if message and not isinstance(message, dict):
        return error()
    else:
        args = message.get('value', {}) if message else {}
        if not (isinstance(args, dict) or isinstance(args, list)):
            return error()

    if runner.verify():
        try:
            if 'activation' in message:
                code, result = runner.run(args, runner.env(message['activation'] or {}))
                response = flask.jsonify(result)
                response.status_code = code
            else:
                code, result = runner.run(args, runner.env(message or {}))
                response = flask.jsonify(result)
                response.status_code = code
        except Exception as e:
            response = flask.jsonify({'error': 'Internal error. {}'.format(e)})
            response.status_code = 500
    else:
        response = flask.jsonify({'error': 'The action failed to locate a binary. See logs for details.'})
        response.status_code = 502
    return complete(response)