def agent_callback(topic): """ Main callback for aries agent. Dispatches calls based on the supplied topic. """ if not request.json: abort(400) message = request.json # dispatch based on the topic type if topic == issuer.TOPIC_CONNECTIONS: if "state" in message: return issuer.handle_connections(message["state"], message) return jsonify({}) elif topic == issuer.TOPIC_CREDENTIALS: if "state" in message: return issuer.handle_credentials(message["state"], message) return jsonify({}) elif topic == issuer.TOPIC_PRESENTATIONS: if "state" in message: return issuer.handle_presentations(message["state"], message) return jsonify({}) elif topic == issuer.TOPIC_GET_ACTIVE_MENU: return issuer.handle_get_active_menu(message) elif topic == issuer.TOPIC_PERFORM_MENU_ACTION: return issuer.handle_perform_menu_action(message) elif topic == issuer.TOPIC_ISSUER_REGISTRATION: return issuer.handle_register_issuer(message) elif topic == issuer.TOPIC_PROBLEM_REPORT: return issuer.handle_problem_report(message) else: print("Callback: topic=", topic, ", message=", message) abort(400, {'message': 'Invalid topic: ' + topic})
def agent_callback(topic): """ Main callback for aries agent. Dispatches calls based on the supplied topic. """ start_time = time.perf_counter() method = 'agent_callback.' + topic if not request.json: end_time = time.perf_counter() issuer.log_timing_method(method, start_time, end_time, False) abort(400) message = request.json issuer.log_timing_event(method, message, start_time, None, False) # dispatch based on the topic type if topic == issuer.TOPIC_CONNECTIONS: if "state" in message: method = method + '.' + message["state"] response = issuer.handle_connections(message["state"], message) else: response = jsonify({}) elif topic == issuer.TOPIC_CONNECTIONS_ACTIVITY: response = jsonify({}) elif topic == issuer.TOPIC_CREDENTIALS: if "state" in message: method = method + '.' + message["state"] response = issuer.handle_credentials(message["state"], message) else: response = jsonify({}) elif topic == issuer.TOPIC_PRESENTATIONS: if "state" in message: method = method + '.' + message["state"] response = issuer.handle_presentations(message["state"], message) else: response = jsonify({}) elif topic == issuer.TOPIC_GET_ACTIVE_MENU: response = issuer.handle_get_active_menu(message) elif topic == issuer.TOPIC_PERFORM_MENU_ACTION: response = issuer.handle_perform_menu_action(message) elif topic == issuer.TOPIC_ISSUER_REGISTRATION: response = issuer.handle_register_issuer(message) elif topic == issuer.TOPIC_PROBLEM_REPORT: response = issuer.handle_problem_report(message) else: print("Callback: topic=", topic, ", message=", message) end_time = time.perf_counter() issuer.log_timing_method(method, start_time, end_time, False) issuer.log_timing_event(method, message, start_time, end_time, False) abort(400, {'message': 'Invalid topic: ' + topic}) end_time = time.perf_counter() issuer.log_timing_method(method, start_time, end_time, True) issuer.log_timing_event(method, message, start_time, end_time, True) return response