From 67d35e5551c2e0ac0d1d3da8e5add13d3d7ba084 Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Wed, 2 Aug 2023 11:47:35 -0700 Subject: [PATCH 1/4] Multitenant check endorser_info before saving Signed-off-by: Jason Sherman --- .../ledger/multiple_ledger/indy_vdr_manager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py b/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py index 1ee24598d3..db886097be 100644 --- a/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py @@ -94,11 +94,12 @@ async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> st profile.context.settings["endorser.endorser_public_did"] = endorser_did profile.context.settings["ledger.write_ledger"] = ledger_id if multi_tenant_mgr: - extra_settings = { - "endorser.endorser_alias": endorser_alias, - "endorser.endorser_public_did": endorser_did, - "ledger.write_ledger": ledger_id, - } + # may not use an endorser, so check first... + if endorser_info: + extra_settings["endorser.endorser_alias"] = endorser_alias + extra_settings["endorser.endorser_public_did"] = endorser_did + # persist the write ledger... + extra_settings["ledger.write_ledger"] = ledger_id await multi_tenant_mgr.update_wallet( profile.context.settings["wallet.id"], extra_settings, From 7b1752a98bddc226cb6e4a75f821147dff7563c7 Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Wed, 2 Aug 2023 11:58:51 -0700 Subject: [PATCH 2/4] same fix on indy_manager Signed-off-by: Jason Sherman --- .../ledger/multiple_ledger/indy_manager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/aries_cloudagent/ledger/multiple_ledger/indy_manager.py b/aries_cloudagent/ledger/multiple_ledger/indy_manager.py index 97f787a74e..9f54fc450c 100644 --- a/aries_cloudagent/ledger/multiple_ledger/indy_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/indy_manager.py @@ -111,11 +111,12 @@ async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> st profile.context.settings["endorser.endorser_public_did"] = endorser_did profile.context.settings["ledger.write_ledger"] = ledger_id if multi_tenant_mgr: - extra_settings = { - "endorser.endorser_alias": endorser_alias, - "endorser.endorser_public_did": endorser_did, - "ledger.write_ledger": ledger_id, - } + # may not use an endorser, so check first... + if endorser_info: + extra_settings["endorser.endorser_alias"] = endorser_alias + extra_settings["endorser.endorser_public_did"] = endorser_did + # persist the write ledger... + extra_settings["ledger.write_ledger"] = ledger_id await multi_tenant_mgr.update_wallet( profile.context.settings["wallet.id"], extra_settings, From 1d13d6b1cc52c4621c52e93900716c03f3a09fe2 Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Wed, 2 Aug 2023 14:06:36 -0700 Subject: [PATCH 3/4] refactor to base manager Signed-off-by: Jason Sherman --- .../ledger/multiple_ledger/base_manager.py | 38 +++++++++++++++++-- .../ledger/multiple_ledger/indy_manager.py | 34 ----------------- .../multiple_ledger/indy_vdr_manager.py | 34 ----------------- 3 files changed, 34 insertions(+), 72 deletions(-) diff --git a/aries_cloudagent/ledger/multiple_ledger/base_manager.py b/aries_cloudagent/ledger/multiple_ledger/base_manager.py index 8e06ff4e05..98e6964927 100644 --- a/aries_cloudagent/ledger/multiple_ledger/base_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/base_manager.py @@ -7,6 +7,7 @@ from ...core.profile import Profile from ...ledger.base import BaseLedger from ...messaging.valid import IndyDID +from ...multitenant.manager import BaseMultitenantManager class MultipleLedgerManagerError(BaseError): @@ -31,10 +32,6 @@ async def get_write_ledgers(self) -> List[str]: async def get_ledger_id_by_ledger_pool_name(self, pool_name: str) -> str: """Return ledger_id by ledger pool name.""" - @abstractmethod - async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str: - """Set the write ledger for the profile.""" - @abstractmethod async def get_prod_ledgers(self) -> Mapping: """Return configured production ledgers.""" @@ -65,3 +62,36 @@ def extract_did_from_identifier(self, identifier: str) -> str: return identifier.split(":")[-1] else: return identifier.split(":")[0] + + async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str: + """Set the write ledger for the profile.""" + if ledger_id not in self.writable_ledgers: + raise MultipleLedgerManagerError( + f"Provided Ledger identifier {ledger_id} is not write configurable." + ) + extra_settings = {} + multi_tenant_mgr = self.profile.inject_or(BaseMultitenantManager) + multi_ledgers = self.production_ledgers | self.non_production_ledgers + if ledger_id in multi_ledgers: + profile.context.injector.bind_instance( + BaseLedger, multi_ledgers.get(ledger_id) + ) + self._update_settings(profile.context.settings, ledger_id) + self._update_settings(extra_settings, ledger_id) + if multi_tenant_mgr: + await multi_tenant_mgr.update_wallet( + profile.context.settings["wallet.id"], + extra_settings, + ) + return ledger_id + raise MultipleLedgerManagerError(f"No ledger info found for {ledger_id}.") + + def _update_settings(self, settings, ledger_id: str): + endorser_info = self.get_endorser_info_for_ledger(ledger_id) + if endorser_info: + endorser_alias, endorser_did = endorser_info + settings["endorser.endorser_alias"] = endorser_alias + settings["endorser.endorser_public_did"] = endorser_did + else: + settings["endorser.none"] = "true" + settings["ledger.write_ledger"] = ledger_id diff --git a/aries_cloudagent/ledger/multiple_ledger/indy_manager.py b/aries_cloudagent/ledger/multiple_ledger/indy_manager.py index 9f54fc450c..cf379b7913 100644 --- a/aries_cloudagent/ledger/multiple_ledger/indy_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/indy_manager.py @@ -11,7 +11,6 @@ from ...core.profile import Profile from ...ledger.base import BaseLedger from ...ledger.error import LedgerError -from ...multitenant.manager import BaseMultitenantManager from ...wallet.crypto import did_is_self_certified from ..indy import IndySdkLedger @@ -91,39 +90,6 @@ async def get_ledger_id_by_ledger_pool_name(self, pool_name: str) -> str: "in either production_ledgers or non_production_ledgers" ) - async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str: - """Set the write ledger for the profile.""" - if ledger_id not in self.writable_ledgers: - raise MultipleLedgerManagerError( - f"Provided Ledger identifier {ledger_id} is not write configurable." - ) - extra_settings = {} - multi_tenant_mgr = self.profile.inject_or(BaseMultitenantManager) - multi_ledgers = self.production_ledgers | self.non_production_ledgers - if ledger_id in multi_ledgers: - profile.context.injector.bind_instance( - BaseLedger, multi_ledgers.get(ledger_id) - ) - endorser_info = self.get_endorser_info_for_ledger(ledger_id) - if endorser_info: - endorser_alias, endorser_did = endorser_info - profile.context.settings["endorser.endorser_alias"] = endorser_alias - profile.context.settings["endorser.endorser_public_did"] = endorser_did - profile.context.settings["ledger.write_ledger"] = ledger_id - if multi_tenant_mgr: - # may not use an endorser, so check first... - if endorser_info: - extra_settings["endorser.endorser_alias"] = endorser_alias - extra_settings["endorser.endorser_public_did"] = endorser_did - # persist the write ledger... - extra_settings["ledger.write_ledger"] = ledger_id - await multi_tenant_mgr.update_wallet( - profile.context.settings["wallet.id"], - extra_settings, - ) - return ledger_id - raise MultipleLedgerManagerError(f"No ledger info found for {ledger_id}.") - async def _get_ledger_by_did( self, ledger_id: str, diff --git a/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py b/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py index db886097be..8d2c51c576 100644 --- a/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py @@ -11,7 +11,6 @@ from ...core.profile import Profile from ...ledger.base import BaseLedger from ...ledger.error import LedgerError -from ...multitenant.manager import BaseMultitenantManager from ...wallet.crypto import did_is_self_certified from ..indy_vdr import IndyVdrLedger @@ -74,39 +73,6 @@ async def get_nonprod_ledgers(self) -> Mapping: """Return non_production ledgers mapping.""" return self.non_production_ledgers - async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str: - """Set the write ledger for the profile.""" - if ledger_id not in self.writable_ledgers: - raise MultipleLedgerManagerError( - f"Provided Ledger identifier {ledger_id} is not write configurable." - ) - extra_settings = {} - multi_tenant_mgr = self.profile.inject_or(BaseMultitenantManager) - multi_ledgers = self.production_ledgers | self.non_production_ledgers - if ledger_id in multi_ledgers: - profile.context.injector.bind_instance( - BaseLedger, multi_ledgers.get(ledger_id) - ) - endorser_info = self.get_endorser_info_for_ledger(ledger_id) - if endorser_info: - endorser_alias, endorser_did = endorser_info - profile.context.settings["endorser.endorser_alias"] = endorser_alias - profile.context.settings["endorser.endorser_public_did"] = endorser_did - profile.context.settings["ledger.write_ledger"] = ledger_id - if multi_tenant_mgr: - # may not use an endorser, so check first... - if endorser_info: - extra_settings["endorser.endorser_alias"] = endorser_alias - extra_settings["endorser.endorser_public_did"] = endorser_did - # persist the write ledger... - extra_settings["ledger.write_ledger"] = ledger_id - await multi_tenant_mgr.update_wallet( - profile.context.settings["wallet.id"], - extra_settings, - ) - return ledger_id - raise MultipleLedgerManagerError(f"No ledger info found for {ledger_id}.") - async def get_ledger_inst_by_id(self, ledger_id: str) -> Optional[BaseLedger]: """Return BaseLedger instance.""" return self.production_ledgers.get( From e85fd913cf1f9fea3d860acfca6b9bb4d1a8ae68 Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Thu, 3 Aug 2023 10:26:57 -0700 Subject: [PATCH 4/4] remove debugging code... Signed-off-by: Jason Sherman --- aries_cloudagent/ledger/multiple_ledger/base_manager.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/aries_cloudagent/ledger/multiple_ledger/base_manager.py b/aries_cloudagent/ledger/multiple_ledger/base_manager.py index 98e6964927..69e1f2d26c 100644 --- a/aries_cloudagent/ledger/multiple_ledger/base_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/base_manager.py @@ -92,6 +92,4 @@ def _update_settings(self, settings, ledger_id: str): endorser_alias, endorser_did = endorser_info settings["endorser.endorser_alias"] = endorser_alias settings["endorser.endorser_public_did"] = endorser_did - else: - settings["endorser.none"] = "true" settings["ledger.write_ledger"] = ledger_id