Skip to content

Commit

Permalink
Make single wallet config more explicit (#3105)
Browse files Browse the repository at this point in the history
* Make single wallet config more explicit

Signed-off-by: jamshale <[email protected]>

* Fix minor string tuple issue

Signed-off-by: jamshale <[email protected]>

---------

Signed-off-by: jamshale <[email protected]>
Co-authored-by: Ian Costanzo <[email protected]>
  • Loading branch information
jamshale and ianco authored Jul 17, 2024
1 parent 6c4764b commit 0c0ddce
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 73 deletions.
13 changes: 11 additions & 2 deletions .vscode-sample/multitenant-admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ inbound-transport:

outbound-transport: http

wallet-type: askar-anoncreds
wallet-type: askar
wallet-storage-type: default
wallet-name: multitenant-admin-wallet
wallet-key: multitenant-admin-wallet-key
multitenancy-config: '{"wallet_type": "single-wallet-askar"}'

admin-insecure-mode: true

admin: [0.0.0.0, 9051]

endpoint: http://localhost:9050

genesis-url: https://localhost:9000/genesis
genesis-url: http://localhost:9000/genesis

# Connections
debug-connections: true
Expand All @@ -35,3 +36,11 @@ multitenant-admin: true
log-level: info

tails-server-base-url: https://localhost:6543

plugin:
- multitenant_provider.v1_0

# This is used if you want to use the multitoken multitenant manager plugin
# plugin-config-value:
# - multitenant_provider.manager.class_name="multitenant_provider.v1_0.manager.SingleWalletAskarMultitokenMultitenantManager"
# - multitenant_provider.manager.always_check_provided_wallet_key=false
10 changes: 4 additions & 6 deletions aries_cloudagent/askar/tests/test_profile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import asyncio
import pytest

from unittest import mock

import pytest

from ...askar.profile import AskarProfile
from ...config.injection_context import InjectionContext
from ...ledger.base import BaseLedger

from .. import profile as test_module


Expand Down Expand Up @@ -53,8 +52,7 @@ async def test_init_multi_ledger(open_store):
assert askar_profile.opened == open_store
assert askar_profile.settings["endorser.endorser_alias"] == "endorser_dev"
assert (
askar_profile.settings["endorser.endorser_public_did"]
== "9QPa6tHvBHttLg6U4xvviv"
askar_profile.settings["endorser.endorser_public_did"] == "9QPa6tHvBHttLg6U4xvviv"
)
assert (askar_profile.inject_or(BaseLedger)).pool_name == "BCovrinDev"

Expand All @@ -65,7 +63,7 @@ async def test_remove_success(open_store):
context = InjectionContext()
profile_id = "profile_id"
context.settings = {
"multitenant.wallet_type": "askar-profile",
"multitenant.wallet_type": "single-wallet-askar",
"wallet.askar_profile": profile_id,
"ledger.genesis_transactions": mock.MagicMock(),
}
Expand Down
24 changes: 8 additions & 16 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def __call__(self, group_cls: ArgumentGroup):
def get_registered(cls, category: str = None):
"""Fetch the set of registered classes in a category."""
return (
grp
for (cats, grp) in cls._registered
if category is None or category in cats
grp for (cats, grp) in cls._registered if category is None or category in cats
)


Expand Down Expand Up @@ -504,9 +502,7 @@ def get_settings(self, args: Namespace) -> dict:
if "protocols" in provided_lists:
settings["disclose_protocol_list"] = provided_lists.get("protocols")
if "goal-codes" in provided_lists:
settings["disclose_goal_code_list"] = provided_lists.get(
"goal-codes"
)
settings["disclose_goal_code_list"] = provided_lists.get("goal-codes")
return settings


Expand Down Expand Up @@ -1197,8 +1193,8 @@ def get_settings(self, args: Namespace) -> dict:
if args.requests_through_public_did:
if not args.public_invites:
raise ArgsParseError(
"--public-invites is required to use "
"--requests-through-public-did"
"--public-invites is required to use ",
"--requests-through-public-did",
)
settings["requests_through_public_did"] = True
if args.timing:
Expand Down Expand Up @@ -1416,9 +1412,7 @@ def get_settings(self, args: Namespace):
settings["transport.outbound_configs"] = args.outbound_transports
else:
raise ArgsParseError("-ot/--outbound-transport is required")
settings["transport.enable_undelivered_queue"] = (
args.enable_undelivered_queue
)
settings["transport.enable_undelivered_queue"] = args.enable_undelivered_queue
if args.max_message_size:
settings["transport.max_message_size"] = args.max_message_size
if args.max_outbound_retry:
Expand Down Expand Up @@ -1525,9 +1519,7 @@ def get_settings(self, args: Namespace):
settings["mediation.clear"] = True

if args.clear_default_mediator and args.default_mediator_id:
raise ArgsParseError(
"Cannot both set and clear mediation at the same time."
)
raise ArgsParseError("Cannot both set and clear mediation at the same time.")

return settings

Expand Down Expand Up @@ -1770,10 +1762,10 @@ def add_arguments(self, parser: ArgumentParser):
env_var="ACAPY_MULTITENANCY_CONFIGURATION",
help=(
"Specify multitenancy configuration in key=value pairs. "
'For example: "wallet_type=askar-profile wallet_name=askar-profile-name" '
'For example: "wallet_type=single-wallet-askar wallet_name=wallet-name" '
"Possible values: wallet_name, wallet_key, cache_size, "
'key_derivation_method. "wallet_name" is only used when '
'"wallet_type" is "askar-profile"'
'"wallet_type" is "single-wallet-askar"'
),
)
parser.add_argument(
Expand Down
33 changes: 18 additions & 15 deletions aries_cloudagent/core/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ async def setup(self):
)

# Bind default PyLD document loader
context.injector.bind_instance(
DocumentLoader, DocumentLoader(self.root_profile)
)
context.injector.bind_instance(DocumentLoader, DocumentLoader(self.root_profile))

# Admin API
if context.settings.get("admin.enabled"):
Expand Down Expand Up @@ -480,8 +478,8 @@ async def start(self) -> None:
try:
async with self.root_profile.session() as session:
invite_store = MediationInviteStore(session.context.inject(BaseStorage))
mediation_invite_record = (
await invite_store.get_mediation_invite_record(provided_invite)
mediation_invite_record = await invite_store.get_mediation_invite_record(
provided_invite
)
except Exception:
LOGGER.exception("Error retrieving mediator invitation")
Expand Down Expand Up @@ -609,9 +607,7 @@ def inbound_message_router(
def dispatch_complete(self, message: InboundMessage, completed: CompletedTask):
"""Handle completion of message dispatch."""
if completed.exc_info:
LOGGER.exception(
"Exception in message handler:", exc_info=completed.exc_info
)
LOGGER.exception("Exception in message handler:", exc_info=completed.exc_info)
if isinstance(completed.exc_info[1], LedgerConfigError) or isinstance(
completed.exc_info[1], LedgerTransactionError
):
Expand Down Expand Up @@ -725,9 +721,7 @@ async def queue_outbound(
conn_mgr = ConnectionManager(profile)
try:
outbound.target_list = await self.dispatcher.run_task(
conn_mgr.get_connection_targets(
connection_id=outbound.connection_id
)
conn_mgr.get_connection_targets(connection_id=outbound.connection_id)
)
except ConnectionManagerError:
LOGGER.exception("Error preparing outbound message for transmission")
Expand All @@ -742,9 +736,7 @@ async def queue_outbound(
elif not has_target and outbound.reply_thread_id:
message_processor = profile.inject(OobMessageProcessor)
outbound.target = await self.dispatcher.run_task(
message_processor.find_oob_target_for_outbound_message(
profile, outbound
)
message_processor.find_oob_target_for_outbound_message(profile, outbound)
)

return await self._queue_message(profile, outbound)
Expand Down Expand Up @@ -864,7 +856,18 @@ async def check_for_valid_wallet_type(self, profile):

async def check_for_wallet_upgrades_in_progress(self):
"""Check for upgrade and upgrade if needed."""
multitenant_mgr = self.context.inject_or(BaseMultitenantManager)

# We need to use the correct multitenant manager for single vs multiple wallets
# here because the multitenant provider hasn't been initialized yet.
manager_type = self.context.settings.get_value(
"multitenant.wallet_type", default="basic"
).lower()

manager_class = MultitenantManagerProvider.MANAGER_TYPES.get(
manager_type, manager_type
)

multitenant_mgr = self.context.inject_or(manager_class)
if multitenant_mgr:
subwallet_profiles = await get_subwallet_profiles_from_storage(
self.root_profile
Expand Down
13 changes: 6 additions & 7 deletions aries_cloudagent/multitenant/manager_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import logging

from ..config.base import InjectionError
from ..config.injector import BaseInjector
from ..config.provider import BaseProvider
from ..config.settings import BaseSettings
from ..config.injector import BaseInjector
from ..config.base import InjectionError
from ..utils.classloader import ClassLoader, ClassNotFoundError

LOGGER = logging.getLogger(__name__)
Expand All @@ -17,13 +17,13 @@ class MultitenantManagerProvider(BaseProvider):
Decides which manager to use based on the settings.
"""

askar_profile_manager_path = (
single_wallet_askar_manager_path = (
"aries_cloudagent.multitenant."
"askar_profile_manager.AskarProfileMultitenantManager"
"single_wallet_askar_manager.SingleWalletAskarMultitenantManager"
)
MANAGER_TYPES = {
"basic": "aries_cloudagent.multitenant.manager.MultitenantManager",
"askar-profile": askar_profile_manager_path,
"single-wallet-askar": single_wallet_askar_manager_path,
}

def __init__(self, root_profile):
Expand All @@ -34,9 +34,8 @@ def __init__(self, root_profile):
def provide(self, settings: BaseSettings, injector: BaseInjector):
"""Create the multitenant manager instance."""

multitenant_wallet_type = "multitenant.wallet_type"
manager_type = settings.get_value(
multitenant_wallet_type, default="basic"
"multitenant.wallet_type", default="basic"
).lower()

manager_class = self.MANAGER_TYPES.get(manager_type, manager_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from ..core.profile import (
Profile,
)
from ..multitenant.base import BaseMultitenantManager
from ..wallet.models.wallet_record import WalletRecord
from .base import BaseMultitenantManager


class AskarProfileMultitenantManager(BaseMultitenantManager):
class SingleWalletAskarMultitenantManager(BaseMultitenantManager):
"""Class for handling askar profile multitenancy."""

DEFAULT_MULTITENANT_WALLET_NAME = "multitenant_sub_wallet"
Expand Down Expand Up @@ -92,9 +92,7 @@ async def get_wallet_profile(
profile_context = self._multitenant_profile.context.copy()

if provision:
await self._multitenant_profile.store.create_profile(
wallet_record.wallet_id
)
await self._multitenant_profile.store.create_profile(wallet_record.wallet_id)

extra_settings = {
"admin.webhook_urls": self.get_webhook_urls(base_context, wallet_record),
Expand Down
8 changes: 4 additions & 4 deletions aries_cloudagent/multitenant/tests/test_manager_provider.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from unittest import IsolatedAsyncioTestCase

from ...config.injection_context import InjectionContext
from ...config.base import InjectionError
from ..manager_provider import MultitenantManagerProvider
from ...config.injection_context import InjectionContext
from ...core.in_memory import InMemoryProfile
from ..manager_provider import MultitenantManagerProvider


class TestProfileManagerProvider(IsolatedAsyncioTestCase):
Expand All @@ -21,11 +21,11 @@ async def test_provide_askar_profile_manager(self):
profile = InMemoryProfile.test_profile()
provider = MultitenantManagerProvider(profile)
context = InjectionContext()
context.settings["multitenant.wallet_type"] = "askar-profile"
context.settings["multitenant.wallet_type"] = "single-wallet-askar"

self.assertEqual(
provider.provide(context.settings, context.injector).__class__.__name__,
"AskarProfileMultitenantManager",
"SingleWalletAskarMultitenantManager",
)

async def test_invalid_manager_type(self):
Expand Down
Loading

0 comments on commit 0c0ddce

Please sign in to comment.