aries_cloudagent.multitenant package

Submodules

aries_cloudagent.multitenant.askar_profile_manager module

Manager for askar profile multitenancy mode.

class aries_cloudagent.multitenant.askar_profile_manager.AskarProfileMultitenantManager(profile: aries_cloudagent.core.profile.Profile, multitenant_profile: aries_cloudagent.askar.profile.AskarProfile = None)[source]

Bases: aries_cloudagent.multitenant.base.BaseMultitenantManager

Class for handling askar profile multitenancy.

DEFAULT_MULTITENANT_WALLET_NAME = 'multitenant_sub_wallet'
get_wallet_profile(base_context: aries_cloudagent.config.injection_context.InjectionContext, wallet_record: aries_cloudagent.wallet.models.wallet_record.WalletRecord, extra_settings: dict = {}, *, provision=False) → aries_cloudagent.core.profile.Profile[source]

Get Askar profile for a wallet record.

An object of type AskarProfile is returned but this should not be confused with the underlying profile mechanism provided by Askar that enables multiple “profiles” to share a wallet. Usage of this mechanism is what causes this implementation of BaseMultitenantManager.get_wallet_profile to look different from others, especially since no explicit clean up is required for profiles that are no longer in use.

Parameters:
  • base_context – Base context to extend from
  • wallet_record – Wallet record to get the context for
  • extra_settings – Any extra context settings
Returns:

Profile for the wallet record

Return type:

Profile

open_profiles

Return iterator over open profiles.

Only the core multitenant profile is considered open.

remove_wallet_profile(profile: aries_cloudagent.core.profile.Profile)[source]

Remove the wallet profile instance.

Parameters:profile – The wallet profile instance

aries_cloudagent.multitenant.base module

Manager for multitenancy.

class aries_cloudagent.multitenant.base.BaseMultitenantManager(profile: aries_cloudagent.core.profile.Profile)[source]

Bases: abc.ABC

Base class for handling multitenancy.

create_auth_token(wallet_record: aries_cloudagent.wallet.models.wallet_record.WalletRecord, wallet_key: str = None) → str[source]

Create JWT auth token for specified wallet record.

Parameters:
  • wallet_record – The wallet record to create the token for
  • wallet_key – The wallet key to include in the token. Only required for “unmanaged” wallets
Raises:

WalletKeyMissingError – If the wallet key is missing. Only thrown for “unmanaged” wallets

Returns:

JWT auth token

Return type:

str

create_wallet(settings: dict, key_management_mode: str) → aries_cloudagent.wallet.models.wallet_record.WalletRecord[source]

Create new wallet and wallet record.

Parameters:
  • settings – The context settings for this wallet
  • key_management_mode – The mode to use for key management. Either “unmanaged” to not store the wallet key, or “managed” to store the wallet key
Raises:

MultitenantManagerError – If the wallet name already exists

Returns:

The newly created wallet record

Return type:

WalletRecord

get_default_mediator() → Optional[aries_cloudagent.protocols.coordinate_mediation.v1_0.models.mediation_record.MediationRecord][source]

Retrieve the default mediator used for subwallet routing.

Returns:retrieved default mediator or None if not set
Return type:Optional[MediationRecord]
get_profile_for_key(context: aries_cloudagent.config.injection_context.InjectionContext, recipient_key: str) → Optional[aries_cloudagent.core.profile.Profile][source]

Retrieve a wallet profile by recipient key.

get_profile_for_token(context: aries_cloudagent.config.injection_context.InjectionContext, token: str) → aries_cloudagent.core.profile.Profile[source]

Get the profile associated with a JWT header token.

Parameters:
  • context – The context to use for profile creation
  • token – The token
Raises:
  • WalletKeyMissingError – If the wallet_key is missing for an unmanaged wallet
  • InvalidTokenError – If there is an exception while decoding the token
Returns:

Profile associated with the token

get_wallet_and_profile(context: aries_cloudagent.config.injection_context.InjectionContext, wallet_id: str, wallet_key: str) → Tuple[aries_cloudagent.wallet.models.wallet_record.WalletRecord, aries_cloudagent.core.profile.Profile][source]

Get the wallet_record and profile associated with wallet id and key.

get_wallet_details_from_token(token: str) → Tuple[str, str][source]

Get the wallet_id and wallet_key from provided token.

get_wallet_profile(base_context: aries_cloudagent.config.injection_context.InjectionContext, wallet_record: aries_cloudagent.wallet.models.wallet_record.WalletRecord, extra_settings: dict = {}, *, provision=False) → aries_cloudagent.core.profile.Profile[source]

Get profile for a wallet record.

Parameters:
  • base_context – Base context to extend from
  • wallet_record – Wallet record to get the context for
  • extra_settings – Any extra context settings
Returns:

Profile for the wallet record

Return type:

Profile

get_wallets_by_message(message_body, wire_format: aries_cloudagent.transport.wire_format.BaseWireFormat = None) → List[aries_cloudagent.wallet.models.wallet_record.WalletRecord][source]

Get the wallet records associated with the message boy.

Parameters:
  • message_body – The body of the message
  • wire_format – Wire format to use for recipient detection
Returns:

Wallet records associated with the message body

get_webhook_urls(base_context: aries_cloudagent.config.injection_context.InjectionContext, wallet_record: aries_cloudagent.wallet.models.wallet_record.WalletRecord) → list[source]

Get the webhook urls according to dispatch_type.

Parameters:
  • base_context – Base context to get base_webhook_urls
  • wallet_record – Wallet record to get dispatch_type and webhook_urls
Returns:

webhook urls according to dispatch_type

open_profiles

Return iterator over open profiles.

remove_wallet(wallet_id: str, wallet_key: str = None)[source]

Remove the wallet with specified wallet id.

Parameters:
  • wallet_id – The wallet id of the wallet record
  • wallet_key – The wallet key to open the wallet. Only required for “unmanaged” wallets
Raises:

WalletKeyMissingError – If the wallet key is missing. Only thrown for “unmanaged” wallets

remove_wallet_profile(profile: aries_cloudagent.core.profile.Profile)[source]

Remove the wallet profile instance.

Parameters:profile – The wallet profile instance
update_wallet(wallet_id: str, new_settings: dict) → aries_cloudagent.wallet.models.wallet_record.WalletRecord[source]

Update an existing wallet record.

Parameters:
  • wallet_id – The wallet id of the wallet record
  • new_settings – The context settings to be updated for this wallet
Returns:

The updated wallet record

Return type:

WalletRecord

exception aries_cloudagent.multitenant.base.MultitenantManagerError(*args, error_code: str = None, **kwargs)[source]

Bases: aries_cloudagent.core.error.BaseError

Generic multitenant error.

aries_cloudagent.multitenant.cache module

Cache for multitenancy profiles.

class aries_cloudagent.multitenant.cache.ProfileCache(capacity: int)[source]

Bases: object

Profile cache that caches based on LRU strategy.

get(key: str) → Optional[aries_cloudagent.core.profile.Profile][source]

Get profile with associated key from cache.

If a profile is open but has been evicted from the cache, this will reinsert the profile back into the cache. This prevents attempting to open a profile that is already open. Triggers clean up.

Parameters:key (str) – the key to get the profile for.
Returns:Profile if found in cache.
Return type:Optional[Profile]
has(key: str) → bool[source]

Check whether there is a profile with associated key in the cache.

Parameters:key (str) – the key to check for a profile
Returns:Whether the key exists in the cache
Return type:bool
put(key: str, value: aries_cloudagent.core.profile.Profile) → None[source]

Add profile with associated key to the cache.

If new profile exceeds the cache capacity least recently used profiles that are not used will be removed from the cache.

Parameters:
  • key (str) – the key to set
  • value (Profile) – the profile to set
remove(key: str)[source]

Remove profile with associated key from the cache.

Parameters:key (str) – The key to remove from the cache.

aries_cloudagent.multitenant.error module

Multitenant error classes.

exception aries_cloudagent.multitenant.error.WalletKeyMissingError(*args, error_code: str = None, **kwargs)[source]

Bases: aries_cloudagent.core.error.BaseError

Wallet key missing exception.

aries_cloudagent.multitenant.manager module

Manager for multitenancy.

class aries_cloudagent.multitenant.manager.MultitenantManager(profile: aries_cloudagent.core.profile.Profile)[source]

Bases: aries_cloudagent.multitenant.base.BaseMultitenantManager

Class for handling multitenancy.

get_wallet_profile(base_context: aries_cloudagent.config.injection_context.InjectionContext, wallet_record: aries_cloudagent.wallet.models.wallet_record.WalletRecord, extra_settings: dict = {}, *, provision=False) → aries_cloudagent.core.profile.Profile[source]

Get profile for a wallet record.

Parameters:
  • base_context – Base context to extend from
  • wallet_record – Wallet record to get the context for
  • extra_settings – Any extra context settings
Returns:

Profile for the wallet record

Return type:

Profile

open_profiles

Return iterator over open profiles.

remove_wallet_profile(profile: aries_cloudagent.core.profile.Profile)[source]

Remove the wallet profile instance.

Parameters:profile – The wallet profile instance
update_wallet(wallet_id: str, new_settings: dict) → aries_cloudagent.wallet.models.wallet_record.WalletRecord[source]

Update an existing wallet and wallet record.

Parameters:
  • wallet_id – The wallet id of the wallet record
  • new_settings – The context settings to be updated for this wallet
Returns:

The updated wallet record

Return type:

WalletRecord

aries_cloudagent.multitenant.manager_provider module

Profile manager for multitenancy.

class aries_cloudagent.multitenant.manager_provider.MultitenantManagerProvider(root_profile)[source]

Bases: aries_cloudagent.config.base.BaseProvider

Multitenant manager provider.

Decides which manager to use based on the settings.

MANAGER_TYPES = {'askar-profile': 'aries_cloudagent.multitenant.askar_profile_manager.AskarProfileMultitenantManager', 'basic': 'aries_cloudagent.multitenant.manager.MultitenantManager'}
askar_profile_manager_path = 'aries_cloudagent.multitenant.askar_profile_manager.AskarProfileMultitenantManager'
provide(settings: aries_cloudagent.config.base.BaseSettings, injector: aries_cloudagent.config.base.BaseInjector)[source]

Create the multitenant manager instance.

aries_cloudagent.multitenant.route_manager module

Multitenancy route manager.

class aries_cloudagent.multitenant.route_manager.BaseWalletRouteManager[source]

Bases: aries_cloudagent.protocols.coordinate_mediation.v1_0.route_manager.CoordinateMediationV1RouteManager

Route manager for operations specific to the base wallet.

connection_from_recipient_key(profile: aries_cloudagent.core.profile.Profile, recipient_key: str) → aries_cloudagent.connections.models.conn_record.ConnRecord[source]

Retrieve a connection by recipient key.

The recipient key is expected to be a local key owned by this agent.

Since the multi-tenant base wallet can receive and send keylist updates for sub wallets, we check the sub wallet’s connections before the base wallet.

class aries_cloudagent.multitenant.route_manager.MultitenantRouteManager(root_profile: aries_cloudagent.core.profile.Profile)[source]

Bases: aries_cloudagent.protocols.coordinate_mediation.v1_0.route_manager.RouteManager

Multitenancy route manager.

get_base_wallet_mediator() → Optional[aries_cloudagent.protocols.coordinate_mediation.v1_0.models.mediation_record.MediationRecord][source]

Get base wallet’s default mediator.

routing_info(profile: aries_cloudagent.core.profile.Profile, my_endpoint: str, mediation_record: Optional[aries_cloudagent.protocols.coordinate_mediation.v1_0.models.mediation_record.MediationRecord] = None) → Tuple[List[str], str][source]

Return routing info.