async def make_agent_POST_request(self, op, rec_id=None, data=None, text=False, params=None) -> (int, str): if op["topic"] == "connection": operation = op["operation"] if operation == "create-invitation": connection_id = create_uuid() connection = await Connection.create(connection_id) await connection.connect('{"use_public_did": true}') invitation = await connection.invite_details(False) store_resource(connection_id, "connection", connection) connection_dict = await connection.serialize() resp_status = 200 resp_text = json.dumps({ "connection_id": connection_id, "invitation": invitation, "connection": connection_dict }) return (resp_status, resp_text) elif operation == "receive-invitation": connection_id = create_uuid() connection = await Connection.create_with_details( connection_id, json.dumps(data)) await connection.connect('{"use_public_did": true}') connection_state = await connection.update_state() store_resource(connection_id, "connection", connection) connection_dict = await connection.serialize() resp_status = 200 resp_text = json.dumps({ "connection_id": connection_id, "invitation": data, "connection": connection_dict }) return (resp_status, resp_text) elif (operation == "accept-invitation" or operation == "accept-request" or operation == "remove" or operation == "start-introduction" or operation == "send-ping"): connection_id = rec_id connection = get_resource(rec_id, "connection") if connection: # wait for a small period just in case ... await asyncio.sleep(0.1) # make sure we have latest & greatest connection state await connection.update_state() store_resource(connection_id, "connection", connection) connection_dict = await connection.serialize() connection_state = await connection.get_state() resp_status = 200 resp_text = json.dumps({ "connection_id": rec_id, "state": state_text(connection_state), "connection": connection_dict }) return (resp_status, resp_text) return (404, '404: Not Found\n\n'.encode('utf8'))
async def make_agent_POST_request( self, op, rec_id=None, data=None, text=False, params=None ) -> (int, str): if op["topic"] == "status": status = 200 if self.ACTIVE else 418 status_msg = "Active" if self.ACTIVE else "Inactive" return (status, json.dumps({"status": status_msg})) elif op["topic"] == "connection": operation = op["operation"] if operation == "create-invitation": connection_id = create_uuid() (invitation_url, invitation) = await self.pico_create_invitation() print(invitation_url, invitation) connection = {"id": connection_id, "invitation": invitation, "invitation_url": invitation_url} store_resource(connection_id, "connection", connection) resp_status = 200 resp_text = json.dumps({"connection_id": connection_id, "invitation": invitation, "invitation_url": invitation_url, "connection": connection}) return (resp_status, resp_text) elif operation == "receive-invitation": connection_id = create_uuid() if "invitation_url" in data and 0 < len(data["invitation_url"]): invitation_url = data["invitation_url"] invitation = self.extract_invite_info(invitation_url) elif "invitation" in data and 0 < len(data["invitation"]): return (500, '500: No Invitation URL Provided\n\n'.encode('utf8')) else: return (500, '500: No Invitation Provided\n\n'.encode('utf8')) print(invitation_url) print(invitation) await self.pico_receive_invitation(invitation_url) connection = {"id": connection_id, "invitation": invitation, "invitation_url": invitation_url} store_resource(connection_id, "connection", connection) resp_status = 200 resp_text = json.dumps({"connection_id": connection_id, "invitation": invitation, "invitation_url": invitation_url, "connection": connection}) return (resp_status, resp_text) elif (operation == "accept-invitation" or operation == "accept-request" or operation == "remove" or operation == "start-introduction" or operation == "send-ping" ): connection_id = rec_id connection = get_resource(rec_id, "connection") if connection: # TODO no op for now resp_status = 200 resp_text = json.dumps({"connection_id": rec_id, "state": "active", "connection": connection_dict}) return (resp_status, resp_text) return (404, '404: Not Found\n\n'.encode('utf8'))