Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multitenant check endorser_info before saving #2395

Merged
merged 5 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions aries_cloudagent/ledger/multiple_ledger/base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand Down Expand Up @@ -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"
shaangill025 marked this conversation as resolved.
Show resolved Hide resolved
settings["ledger.write_ledger"] = ledger_id
33 changes: 0 additions & 33 deletions aries_cloudagent/ledger/multiple_ledger/indy_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,38 +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:
extra_settings = {
"endorser.endorser_alias": endorser_alias,
"endorser.endorser_public_did": endorser_did,
"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,
Expand Down
33 changes: 0 additions & 33 deletions aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,38 +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:
extra_settings = {
"endorser.endorser_alias": endorser_alias,
"endorser.endorser_public_did": endorser_did,
"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(
Expand Down