async def make_agent_GET_request(
        self, op, rec_id=None, text=False, params=None
    ) -> (int, str):
        if op["topic"] == "connection":
            if rec_id:
                log_msg("Getting connection for", rec_id)
                connection = get_resource(rec_id, "connection")

                if connection:
                    resp_status = 200
                    resp_text = json.dumps({"connection_id": rec_id, "state": "active", "connection": connection})
                    return (resp_status, resp_text)

            else:
                log_msg("Getting connections")
                connections = get_resources("connection")
                log_msg(connections)
                ret_connections = []
                for connection_id in connections:
                    connection = connections[connection_id]
                    ret_connections.append({"connection_id": connection_id, "state": "active", "connection": connection})

                resp_status = 200
                resp_text = json.dumps(ret_connections)
                log_msg(resp_status, resp_text)
                return (resp_status, resp_text)

        log_msg("Returning 404")

        return (404, '404: Not Found\n\n'.encode('utf8'))
    async def stop_agent(self):
        await self.stop_pico()

        self.agent_running = False
        
        log_msg(200, '{"status": "inactive"}')
        return (200, '{"status": "inactive"}')
 async def handle_issue_credential(self, message):
     thread_id = message["thread_id"]
     push_resource(thread_id, "credential-msg", message)
     log_msg('Received Issue Credential Webhook message: ' + json.dumps(message)) 
     if "revocation_id" in message: # also push as a revocation message 
         push_resource(thread_id, "revocation-registry-msg", message)
         log_msg('Issue Credential Webhook message contains revocation info') 
    async def make_agent_GET_request(self,
                                     op,
                                     rec_id=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":
            if rec_id:
                log_msg("Getting connection for", rec_id)
                connection = get_resource(rec_id, "connection")

                if 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)

            else:
                log_msg("Getting connections")
                connections = get_resources("connection")
                log_msg(connections)
                ret_connections = []
                for connection_id in connections:
                    connection = connections[connection_id]
                    connection_dict = await connection.serialize()
                    connection_state = await connection.get_state()
                    ret_connections.append({
                        "connection_id":
                        connection_id,
                        "state":
                        state_text(connection_state),
                        "connection":
                        connection_dict
                    })

                resp_status = 200
                resp_text = json.dumps(ret_connections)
                log_msg(resp_status, resp_text)
                return (resp_status, resp_text)

        log_msg("Returning 404")

        return (404, '404: Not Found\n\n'.encode('utf8'))
    async def start_agent(self):
        log_msg("pico start_agent()")

        # start pico agent sub-process 
        await self.start_pico()

        self.agent_running = True

        log_msg(200, '{"status": "active"}')
        return (200, '{"status": "active"}')
 def handle_output(self, *output, source: str = None, **kwargs):
     end = "" if source else "\n"
     if source == "stderr":
         color = "fg:ansired"
     elif not source:
         color = self.color or "fg:ansiblue"
     else:
         color = None
     log_msg(*output,
             color=color,
             prefix=self.prefix_str,
             end=end,
             **kwargs)
 async def handle_connections(self, message):
     if "invitation_msg_id" in message:
         # This is an did-exchange message based on a Non-Public DID invitation
         invitation_id = message["invitation_msg_id"]
         push_resource(invitation_id, "didexchange-msg", message)
     elif "request_id" in message:
         # This is a did-exchange message based on a Public DID non-invitation
         request_id = message["request_id"]
         push_resource(request_id, "didexchange-msg", message)
     else:
         connection_id = message["connection_id"]
         push_resource(connection_id, "connection-msg", message)
     log_msg('Received a Connection Webhook message: ' + json.dumps(message))
示例#8
0
    async def make_agent_DELETE_request(self,
                                        op,
                                        rec_id=None,
                                        data=None,
                                        text=False,
                                        params=None) -> (int, str):
        if op["topic"] == "credential" and rec_id:
            # swap thread id for cred ex id from the webhook
            # cred_ex_id = await self.swap_thread_id_for_exchange_id(rec_id, "credential-msg","credential_exchange_id")
            agent_operation = "/credential/" + rec_id
            #operation = op["operation"]
            #agent_operation, admin_data = await self.get_agent_operation_acapy_version_based(op["topic"], operation, rec_id, data)
            log_msg(agent_operation)

            (resp_status, resp_text) = await self.admin_DELETE(agent_operation)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        return (501, '501: Not Implemented\n\n'.encode('utf8'))
示例#9
0
 async def handle_webhook(self, topic: str, payload):
     if topic != "webhook":  # would recurse
         handler = f"handle_{topic}"
         method = getattr(self, handler, None)
         # put a log message here
         log_msg('Passing webhook payload to handler ' + handler)
         if method:
             await method(payload)
         else:
             log_msg(f"Error: agent {self.ident} "
                     f"has no method {handler} "
                     f"to handle webhook on topic {topic}")
     else:
         log_msg('in webhook, topic is: ' + topic + ' payload is: ' +
                 json.dumps(payload))
    async def handle_webhook(self, topic: str, payload):
        if topic != "webhook":  # would recurse
            handler = f"handle_{topic}"

            # Remove this handler change when bug is fixed.
            if handler == "handle_oob-invitation":
                handler = "handle_oob_invitation"

            method = getattr(self, handler, None)
            # put a log message here
            log_msg("Passing webhook payload to handler " + handler)
            if method:
                await method(payload)
            else:
                log_msg(f"Error: agent {self.ident} "
                        f"has no method {handler} "
                        f"to handle webhook on topic {topic}")
        else:
            log_msg("in webhook, topic is: " + topic + " payload is: " +
                    json.dumps(payload))
    async def make_agent_POST_request(self,
                                      op,
                                      rec_id=None,
                                      data=None,
                                      text=False,
                                      params=None) -> (int, str):
        print("make_agent_POST_request:", op)

        if op["topic"] == "connection":
            operation = op["operation"]
            if operation == "receive-invitation":
                self.connection_state = "invited"
                print(
                    "================================================================="
                )

                message_bytes = json.dumps(data).encode("ascii")
                base64_bytes = base64.b64encode(message_bytes)
                base64_message = base64_bytes.decode("ascii")
                invitation_url = data[
                    "serviceEndpoint"] + "?c_i=" + base64_message

                qr = QRCode(border=1)
                qr.add_data(invitation_url)
                log_msg(
                    "Use the following JSON to accept the invite from another demo agent."
                    " Or use the QR code to connect from a mobile agent.")
                log_msg(json.dumps(data), label="Invitation Data:", color=None)
                qr.print_ascii(invert=True)
                log_msg("If you can't scan the QR code here is the url.")
                print("Invitation url:", invitation_url)
                print(
                    "================================================================="
                )

                return (
                    200,
                    '{"result": "ok", "connection_id": "1", "state": "' +
                    self.connection_state + '"}',
                )

            elif (operation == "accept-invitation"
                  or operation == "accept-request" or operation == "remove"
                  or operation == "start-introduction"
                  or operation == "send-ping"):
                self.connection_state = "requested"
                return (
                    200,
                    '{"result": "ok", "connection_id": "1", "state": "' +
                    self.connection_state + '"}',
                )

        elif op["topic"] == "issue-credential":
            operation = op["operation"]
            if operation == "send-request":
                print(
                    "================================================================="
                )
                print("Please respond to the Credential Offer!")
                print(
                    "================================================================="
                )
                return (
                    200,
                    '{"result": "ok", "thread_id": "1", "state": "request-sent"}',
                )
            elif operation == "store":
                return (
                    200,
                    '{"result": "ok", "thread_id": "1", "credential_id": "' +
                    rec_id + '", "state": "done"}',
                )
            else:
                return (200,
                        '{"result": "ok", "thread_id": "1", "state": "N/A"}')

        elif op["topic"] == "proof":
            operation = op["operation"]
            if operation == "send-presentation":
                print(
                    "================================================================="
                )
                print("Please respond to the Proof Request!")
                print(
                    "================================================================="
                )
                return (
                    200,
                    '{"result": "ok", "thread_id": "1", "state": "presentation-sent"}',
                )
            else:
                return (200,
                        '{"result": "ok", "thread_id": "1", "state": "N/A"}')

        return (501, "501: Not Implemented\n\n".encode("utf8"))
示例#12
0
    async def make_agent_GET_request(self,
                                     op,
                                     rec_id=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}))

        if op["topic"] == "version":
            if self.acapy_version is not None:
                status = 200
                #status_msg = json.dumps({"version": self.acapy_version})
                status_msg = self.acapy_version
            else:
                status = 404
                #status_msg = json.dumps({"version": "not found"})
                status_msg = "not found"
            return (status, status_msg)

        elif op["topic"] == "connection":
            if rec_id:
                connection_id = rec_id
                agent_operation = "/connections/" + connection_id
            else:
                agent_operation = "/connections"

            log_msg('GET Request agent operation: ', agent_operation)

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            log_msg('GET Request response details: ', resp_status, resp_text)

            resp_json = json.loads(resp_text)
            if rec_id:
                connection_info = {
                    "connection_id": resp_json["connection_id"],
                    "state": resp_json["state"],
                    "connection": resp_json
                }
                resp_text = json.dumps(connection_info)
            else:
                resp_json = resp_json["results"]
                connection_infos = []
                for connection in resp_json:
                    connection_info = {
                        "connection_id": connection["connection_id"],
                        "state": connection["state"],
                        "connection": connection
                    }
                    connection_infos.append(connection_info)
                resp_text = json.dumps(connection_infos)
            # translate the state from that the agent gave to what the tests expect
            resp_text = self.agent_state_translation(op["topic"], None,
                                                     resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "did":
            agent_operation = "/wallet/did/public"

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            resp_json = json.loads(resp_text)
            did = resp_json["result"]

            resp_text = json.dumps(did)
            return (resp_status, resp_text)

        elif op["topic"] == "schema":
            schema_id = rec_id
            agent_operation = "/schemas/" + schema_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            resp_json = json.loads(resp_text)
            schema = resp_json["schema"]

            resp_text = json.dumps(schema)
            return (resp_status, resp_text)

        elif op["topic"] == "credential-definition":
            cred_def_id = rec_id
            agent_operation = "/credential-definitions/" + cred_def_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            resp_json = json.loads(resp_text)
            credential_definition = resp_json["credential_definition"]

            resp_text = json.dumps(credential_definition)
            return (resp_status, resp_text)

        elif op["topic"] == "issue-credential":
            # swap thread id for cred ex id from the webhook
            cred_ex_id = await self.swap_thread_id_for_exchange_id(
                rec_id, "credential-msg", "credential_exchange_id")
            agent_operation = "/issue-credential/records/" + cred_ex_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "credential":
            operation = op["operation"]
            if operation == 'revoked':
                agent_operation = "/credential/" + operation + "/" + rec_id
            else:
                agent_operation = "/credential/" + rec_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            return (resp_status, resp_text)

        elif op["topic"] == "proof":
            # swap thread id for pres ex id from the webhook
            pres_ex_id = await self.swap_thread_id_for_exchange_id(
                rec_id, "presentation-msg", "presentation_exchange_id")
            agent_operation = "/present-proof/records/" + pres_ex_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "revocation":
            operation = op["operation"]
            agent_operation, admin_data = await self.get_agent_operation_acapy_version_based(
                op["topic"], operation, rec_id, data=None)

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            return (resp_status, resp_text)

        return (501, '501: Not Implemented\n\n'.encode('utf8'))
示例#13
0
    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":
                agent_operation = "/connections/" + operation

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation)

                # extract invitation from the agent's response
                invitation_resp = json.loads(resp_text)
                resp_text = json.dumps(invitation_resp)

                if resp_status == 200:
                    resp_text = self.agent_state_translation(
                        op["topic"], operation, resp_text)
                return (resp_status, resp_text)

            elif operation == "receive-invitation":
                agent_operation = "/connections/" + operation

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation, data=data)
                if resp_status == 200:
                    resp_text = self.agent_state_translation(
                        op["topic"], None, resp_text)
                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
                agent_operation = "/connections/" + connection_id + "/" + operation
                log_msg('POST Request: ', agent_operation, data)

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation, data)

                log_msg(resp_status, resp_text)
                if resp_status == 200:
                    resp_text = self.agent_state_translation(
                        op["topic"], None, resp_text)
                return (resp_status, resp_text)

        elif op["topic"] == "schema":
            # POST operation is to create a new schema
            agent_operation = "/schemas"
            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "credential-definition":
            # POST operation is to create a new cred def
            agent_operation = "/credential-definitions"
            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "issue-credential":
            operation = op["operation"]
            if rec_id is None:
                agent_operation = "/issue-credential/" + operation
            else:
                if (operation == "send-offer" or operation == "send-request"
                        or operation == "issue" or operation == "store"):
                    # swap thread id for cred ex id from the webhook
                    cred_ex_id = await self.swap_thread_id_for_exchange_id(
                        rec_id, "credential-msg", "credential_exchange_id")
                    agent_operation = "/issue-credential/records/" + cred_ex_id + "/" + operation
                # Make Special provisions for revoke since it is passing multiple query params not just one id.
                elif (operation == "revoke"):
                    cred_rev_id = rec_id
                    rev_reg_id = data["rev_registry_id"]
                    publish = data["publish_immediately"]
                    agent_operation = "/issue-credential/" + operation + "?cred_rev_id=" + cred_rev_id + "&rev_reg_id=" + rev_reg_id + "&publish=" + str(
                        publish).lower()
                    data = None
                else:
                    agent_operation = "/issue-credential/" + operation

            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "revocation":
            #set the acapyversion to master since work to set it is not complete. Remove when master report proper version
            #self.acapy_version = "0.5.5-RC"
            operation = op["operation"]
            agent_operation, admin_data = await self.get_agent_operation_acapy_version_based(
                op["topic"], operation, rec_id, data)

            log_msg(agent_operation, admin_data)

            if admin_data is None:
                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation)
            else:
                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation,
                                                    admin_data)

            log_msg(resp_status, resp_text)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "proof":
            operation = op["operation"]
            if operation == "create-send-connectionless-request":
                operation = "create-request"
            if rec_id is None:
                agent_operation = "/present-proof/" + operation
            else:
                if (operation == "send-presentation"
                        or operation == "send-request"
                        or operation == "verify-presentation"
                        or operation == "remove"):

                    if (operation not in "send-presentation"
                            or operation not in "send-request") and (
                                data is None or "~service" not in data):
                        # swap thread id for pres ex id from the webhook
                        pres_ex_id = await self.swap_thread_id_for_exchange_id(
                            rec_id, "presentation-msg",
                            "presentation_exchange_id")
                    else:
                        # swap the thread id for the pres ex id in the service decorator (this is a connectionless proof)
                        pres_ex_id = data["~service"]["recipientKeys"][0]
                    agent_operation = "/present-proof/records/" + pres_ex_id + "/" + operation

                else:
                    agent_operation = "/present-proof/" + operation

            log_msg(agent_operation, data)

            if data is not None:
                # Format the message data that came from the test, to what the Aca-py admin api expects.
                data = self.map_test_json_to_admin_api_json(
                    op["topic"], operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        return (501, '501: Not Implemented\n\n'.encode('utf8'))
示例#14
0
 async def handle_problem_report(self, message):
     thread_id = message["thread_id"]
     push_resource(thread_id, "problem-report-msg", message)
     log_msg('Received Problem Report Webhook message: ' +
             json.dumps(message))
示例#15
0
 async def handle_revocation_registry(self, message):
     # No thread id in the webhook for revocation registry messages
     cred_def_id = message["cred_def_id"]
     push_resource(cred_def_id, "revocation-registry-msg", message)
     log_msg('Received Revocation Registry Webhook message: ' +
             json.dumps(message))
示例#16
0
 async def handle_present_proof(self, message):
     thread_id = message["thread_id"]
     push_resource(thread_id, "presentation-msg", message)
     log_msg('Received a Present Proof Webhook message: ' +
             json.dumps(message))
示例#17
0
 async def handle_connections(self, message):
     connection_id = message["connection_id"]
     push_resource(connection_id, "connection-msg", message)
     log_msg('Received a Connection Webhook message: ' +
             json.dumps(message))
示例#18
0
    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":
                agent_operation = "/connections/" + operation

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation)

                # extract invitation from the agent's response
                invitation_resp = json.loads(resp_text)
                resp_text = json.dumps(invitation_resp)

                if resp_status == 200:
                    resp_text = self.agent_state_translation(
                        op["topic"], operation, resp_text)
                return (resp_status, resp_text)

            elif operation == "receive-invitation":
                agent_operation = "/connections/" + operation

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation, data=data)
                if resp_status == 200:
                    resp_text = self.agent_state_translation(
                        op["topic"], None, resp_text)
                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
                agent_operation = "/connections/" + connection_id + "/" + operation
                log_msg('POST Request: ', agent_operation, data)

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation, data)

                log_msg(resp_status, resp_text)
                if resp_status == 200:
                    resp_text = self.agent_state_translation(
                        op["topic"], None, resp_text)
                return (resp_status, resp_text)

        elif op["topic"] == "schema":
            # POST operation is to create a new schema
            agent_operation = "/schemas"
            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "credential-definition":
            # POST operation is to create a new cred def
            agent_operation = "/credential-definitions"
            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "issue-credential":
            operation = op["operation"]
            if rec_id is None:
                agent_operation = "/issue-credential/" + operation
            else:
                if (operation == "send-offer" or operation == "send-request"
                        or operation == "issue" or operation == "store"):
                    # swap thread id for cred ex id from the webhook
                    cred_ex_id = await self.swap_thread_id_for_exchange_id(
                        rec_id, "credential-msg", "credential_exchange_id")
                    agent_operation = "/issue-credential/records/" + cred_ex_id + "/" + operation
                else:
                    agent_operation = "/issue-credential/" + operation

            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "proof":
            operation = op["operation"]
            if rec_id is None:
                agent_operation = "/present-proof/" + operation
            else:
                if (operation == "send-presentation"
                        or operation == "send-request"
                        or operation == "verify-presentation"
                        or operation == "remove"):
                    #pres_ex_id = rec_id
                    # swap thread id for pres ex id from the webhook
                    pres_ex_id = await self.swap_thread_id_for_exchange_id(
                        rec_id, "presentation-msg", "presentation_exchange_id")
                    agent_operation = "/present-proof/records/" + pres_ex_id + "/" + operation
                else:
                    agent_operation = "/present-proof/" + operation

            log_msg(agent_operation, data)
            # Format the message data that came from the test, to what the Aca-py admin api expects.
            data = self.map_test_json_to_admin_api_json(
                op["topic"], operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            if resp_status == 200:
                resp_text = self.agent_state_translation(
                    op["topic"], None, resp_text)
            return (resp_status, resp_text)

        return (501, '501: Not Implemented\n\n'.encode('utf8'))
示例#19
0
    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":
                agent_operation = "/connections/" + operation

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation)

                # extract invitation from the agent's response
                invitation_resp = json.loads(resp_text)
                resp_text = json.dumps(invitation_resp)

                return (resp_status, resp_text)

            elif operation == "receive-invitation":
                agent_operation = "/connections/" + operation

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation, data=data)

                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
                agent_operation = "/connections/" + connection_id + "/" + operation
                log_msg('POST Request: ', agent_operation, data)

                (resp_status,
                 resp_text) = await self.admin_POST(agent_operation, data)

                log_msg(resp_status, resp_text)
                return (resp_status, resp_text)

        elif op["topic"] == "schema":
            # POST operation is to create a new schema
            agent_operation = "/schemas"
            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "credential-definition":
            # POST operation is to create a new cred def
            agent_operation = "/credential-definitions"
            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            return (resp_status, resp_text)

        elif op["topic"] == "issue-credential":
            operation = op["operation"]
            if rec_id is None:
                agent_operation = "/issue-credential/" + operation
            else:
                if (operation == "send-offer" or operation == "send-request"
                        or operation == "issue" or operation == "store"):
                    cred_ex_id = rec_id
                    agent_operation = "/issue-credential/records/" + cred_ex_id + "/" + operation
                else:
                    agent_operation = "/issue-credential/" + operation

            log_msg(agent_operation, data)

            (resp_status,
             resp_text) = await self.admin_POST(agent_operation, data)

            log_msg(resp_status, resp_text)
            return (resp_status, resp_text)

        return (501, '501: Not Implemented\n\n'.encode('utf8'))
 async def handle_oob_invitation(self, message):
     # No thread id in the webhook for revocation registry messages
     invitation_id = message["invitation_id"]
     push_resource(invitation_id, "oob-inviation-msg", message)
     log_msg("Received Out of Band Invitation Webhook message: " +
             json.dumps(message))
示例#21
0
    async def make_agent_GET_request(self,
                                     op,
                                     rec_id=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":
            if rec_id:
                connection_id = rec_id
                agent_operation = "/connections/" + connection_id
            else:
                agent_operation = "/connections"

            log_msg('GET Request agent operation: ', agent_operation)

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            log_msg('GET Request response details: ', resp_status, resp_text)

            resp_json = json.loads(resp_text)
            if rec_id:
                connection_info = {
                    "connection_id": resp_json["connection_id"],
                    "state": resp_json["state"],
                    "connection": resp_json
                }
                resp_text = json.dumps(connection_info)
            else:
                resp_json = resp_json["results"]
                connection_infos = []
                for connection in resp_json:
                    connection_info = {
                        "connection_id": connection["connection_id"],
                        "state": connection["state"],
                        "connection": connection
                    }
                    connection_infos.append(connection_info)
                resp_text = json.dumps(connection_infos)
            return (resp_status, resp_text)

        elif op["topic"] == "did":
            agent_operation = "/wallet/did/public"

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            resp_json = json.loads(resp_text)
            did = resp_json["result"]

            resp_text = json.dumps(did)
            return (resp_status, resp_text)

        elif op["topic"] == "schema":
            schema_id = rec_id
            agent_operation = "/schemas/" + schema_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            resp_json = json.loads(resp_text)
            schema = resp_json["schema"]

            resp_text = json.dumps(schema)
            return (resp_status, resp_text)

        elif op["topic"] == "credential-definition":
            cred_def_id = rec_id
            agent_operation = "/credential-definitions/" + cred_def_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            if resp_status != 200:
                return (resp_status, resp_text)

            resp_json = json.loads(resp_text)
            credential_definition = resp_json["credential_definition"]

            resp_text = json.dumps(credential_definition)
            return (resp_status, resp_text)

        elif op["topic"] == "issue-credential":
            cred_def_id = rec_id
            agent_operation = "/issue-credential/records/" + cred_def_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            return (resp_status, resp_text)

        elif op["topic"] == "credential":
            agent_operation = "/credential/" + rec_id

            (resp_status, resp_text) = await self.admin_GET(agent_operation)
            return (resp_status, resp_text)

        return (501, '501: Not Implemented\n\n'.encode('utf8'))