From 47b89b151115f82f86b7dd95b2b9d56bfe2d456f Mon Sep 17 00:00:00 2001 From: Armin Veres Date: Wed, 15 Nov 2023 10:01:02 +0100 Subject: [PATCH] wip --- impl/src/agents/agent_container.py | 2 ++ impl/src/agents/issuer.py | 33 ++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/impl/src/agents/agent_container.py b/impl/src/agents/agent_container.py index b8de8c8..0d78636 100644 --- a/impl/src/agents/agent_container.py +++ b/impl/src/agents/agent_container.py @@ -93,6 +93,8 @@ def __init__( self.last_proof_received = None async def detect_connection(self): + self._connection_ready = asyncio.Future() + log_msg("Waiting for connection...") await self._connection_ready self._connection_ready = None diff --git a/impl/src/agents/issuer.py b/impl/src/agents/issuer.py index 6e5ae66..ddb646b 100644 --- a/impl/src/agents/issuer.py +++ b/impl/src/agents/issuer.py @@ -19,7 +19,7 @@ PERF_LOG = "./.agent_cache/time_log" -def log_time_to_file(text): +async def log_time_to_file(text): with open(PERF_LOG, mode="a", encoding="utf-8") as perf_log: perf_log.write(text) @@ -146,8 +146,8 @@ async def handle_notify_vulnerability(self, message): # mark devices to be revoked for device in self.db_client.db_keys[vuln_db_name]: db_result = await self.db_client.query_key(vuln_db_name, device) - log_json(db_result) - log_json(vulnerability) + # log_json(db_result) + # log_json(vulnerability) for component_key, component_value in db_result["components"].items(): for ( @@ -213,7 +213,7 @@ async def handle_node_updated(self, message): await self.issue_credential(node_did, node_name, node_cred, DB_NAME) await self.db_client.record_key(DB_NAME, node_name, db_entry) - log_time_to_file(f"UPDATE: time: {time.perf_counter_ns()}, node: {node_name}\n") + await log_time_to_file(f"UPDATE: time: {time.perf_counter_ns()}, node: {node_name}\n") # ============================================================================================= # Additional methods @@ -229,6 +229,9 @@ async def revoke_credential( Revoke a credentials and publish it. """ response = await self.db_client.query_key(db_name, node_name) + cred_ex_id = response.get("cred_ex_id") + + # update database with removed credential id response["cred_ex_id"] = "" response["valid"] = False await self.db_client.record_key(db_name, node_name, response) @@ -250,7 +253,7 @@ async def issue_credential( node_did: str, node_name: str, node_cred: dict, - domain: str, + db_name: str, ): """ Issue a predetermined credential to a node @@ -262,7 +265,7 @@ async def issue_credential( """ recipient_key = await self.send_invitation(node_did) # we set the recipient key for later identification - self.db_client.db_keys[domain][node_name]["recipient_key"] = recipient_key + self.db_client.db_keys[db_name][node_name]["recipient_key"] = recipient_key self._connection_ready = asyncio.Future() log_msg("Waiting for connection...") @@ -276,9 +279,9 @@ async def issue_credential( for conn in response["results"]: if conn["invitation_key"] == recipient_key: conn_id = conn["connection_id"] - self.db_client.db_keys[domain][node_name]["connection_id"] = conn_id + self.db_client.db_keys[db_name][node_name]["connection_id"] = conn_id # remove recipient/invitation key - self.db_client.db_keys[domain][node_name].pop("recipient_key") + self.db_client.db_keys[db_name][node_name].pop("recipient_key") self.reset_connection() @@ -296,7 +299,7 @@ async def issue_credential( "credential_preview": cred_preview, "filter": {"indy": {"cred_def_id": self.cred_def_id}}, } - response = await self.admin_POST("/issue-credential-2.0/send-offer", offer_request) + _ = await self.admin_POST("/issue-credential-2.0/send-offer", offer_request) async def onboard_node(self, domain: str, node_name: str, node_did: str): """ @@ -349,7 +352,7 @@ async def mass_onboard(self): await self.onboard_node(DB_NAME, node["name"], node["did"]) async def remove_device(self, node_name: str): - db_result = await self.db_client.query_key(DB_NAME, node_name) + # db_result = await self.db_client.query_key(DB_NAME, node_name) await self.revoke_credential( "", DB_NAME, @@ -482,6 +485,14 @@ def get_prompt(): # ========================================================================================= # New prompt based event loop, events such as webhooks still run in the background. + await setup_database(agent_container, DB_NAME) + prompt_options.pop("setup_db") + # add onboarding option and update order by values + prompt_options = add_option( + prompt_options, "onboard", " [3]: Onboard node with public DID\n" + ) + prompt_options = add_option(prompt_options, "mass_onboard", " [4]: Mass Onboard fleet\n") + async for option in prompt_loop(get_prompt): if option is not None: option = option.strip() @@ -529,7 +540,7 @@ def get_prompt(): node_did = node_did.strip() await agent_container.agent.onboard_node( - domain=DB_NAME, + db_name=DB_NAME, node_did=node_did, node_name=node_name, )