Skip to content

Commit

Permalink
Add test wallet config option
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Nov 26, 2024
1 parent 799cd64 commit da380ee
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
8 changes: 6 additions & 2 deletions acapy_agent/askar/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,19 @@ async def provision(
) -> Profile:
"""Provision a new instance of a profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=True)
opened = await store_config.open_store(
provision=True, in_memory=config.get("test")
)
return AskarProfile(opened, context)

async def open(
self, context: InjectionContext, config: Mapping[str, Any] = None
) -> Profile:
"""Open an instance of an existing profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=False)
opened = await store_config.open_store(
provision=False, in_memory=config.get("test")
)
return AskarProfile(opened, context)

@classmethod
Expand Down
8 changes: 6 additions & 2 deletions acapy_agent/askar/profile_anon.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,19 @@ async def provision(
) -> Profile:
"""Provision a new instance of a profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=True)
opened = await store_config.open_store(
provision=True, in_memory=config.get("test")
)
return AskarAnoncredsProfile(opened, context)

async def open(
self, context: InjectionContext, config: Mapping[str, Any] = None
) -> Profile:
"""Open an instance of an existing profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=False)
opened = await store_config.open_store(
provision=False, in_memory=config.get("test")
)
return AskarAnoncredsProfile(opened, context)

@classmethod
Expand Down
27 changes: 21 additions & 6 deletions acapy_agent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,13 +1610,13 @@ def add_arguments(self, parser: ArgumentParser):
"--wallet-type",
type=str,
metavar="<wallet-type>",
default="basic",
default="askar",
env_var="ACAPY_WALLET_TYPE",
help=(
"Specifies the type of wallet provider to use. "
"Supported internal storage types are 'basic' (memory), 'askar' "
"Supported internal storage types are 'askar' "
"and 'askar-anoncreds'."
"The default (if not specified) is 'basic'."
"The default (if not specified) is 'askar'."
),
)
parser.add_argument(
Expand All @@ -1627,11 +1627,24 @@ def add_arguments(self, parser: ArgumentParser):
env_var="ACAPY_WALLET_STORAGE_TYPE",
help=(
"Specifies the type of wallet backend to use. "
"Supported internal storage types are 'basic' (memory), "
"'default' (sqlite), and 'postgres_storage'. The default, "
"Supported internal storage types are 'default' (sqlite), "
"and 'postgres_storage'. The default, "
"if not specified, is 'default'."
),
)
parser.add_argument(
"--wallet-test",
type=str,
metavar="<wallet-test>",
default=False,
env_var="ACAPY_WALLET_TEST",
help=(
"Using this option will create a wallet with an in-memory askar wallet "
"storage with a random name. This is useful for testing purposes. "
"The data will not be persisted after the agent is stopped. The default "
"is False. "
),
)
parser.add_argument(
"--wallet-storage-config",
type=str,
Expand Down Expand Up @@ -1714,6 +1727,8 @@ def get_settings(self, args: Namespace) -> dict:
settings["wallet.storage_type"] = args.wallet_storage_type
if args.wallet_type:
settings["wallet.type"] = args.wallet_type
if args.wallet_test:
settings["wallet.test"] = True
if args.wallet_key_derivation_method:
settings["wallet.key_derivation_method"] = args.wallet_key_derivation_method
if args.wallet_rekey_derivation_method:
Expand All @@ -1731,7 +1746,7 @@ def get_settings(self, args: Namespace) -> dict:
# check required settings for persistent wallets
if settings["wallet.type"] in ["askar", "askar-anoncreds"]:
# requires name, key
if not args.wallet_name or not args.wallet_key:
if not args.wallet_test and (not args.wallet_name or not args.wallet_key):
raise ArgsParseError(
"Parameters --wallet-name and --wallet-key must be provided "
"for persistent wallets"
Expand Down
1 change: 1 addition & 0 deletions acapy_agent/config/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"storage_config",
"storage_creds",
"storage_type",
"test",
}


Expand Down

0 comments on commit da380ee

Please sign in to comment.