Skip to content

Commit

Permalink
Merge branch 'main' into fix-3360
Browse files Browse the repository at this point in the history
  • Loading branch information
jamshale authored Dec 2, 2024
2 parents 7ae9138 + 80cc329 commit 583553e
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
additional_dependencies: ['@commitlint/config-conventional']
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ensure this is synced with pyproject.toml
rev: v0.8.0
rev: v0.8.1
hooks:
# Run the linter
- id: ruff
Expand Down
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
29 changes: 16 additions & 13 deletions acapy_agent/askar/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import pytest

from ...askar.profile import AskarProfile
from ...askar.profile import AskarProfile, AskarProfileManager
from ...config.injection_context import InjectionContext
from ...ledger.base import BaseLedger
from .. import profile as test_module
from ..profile_anon import AskarAnonProfileManager


@pytest.fixture
Expand Down Expand Up @@ -107,15 +108,17 @@ async def test_profile_manager_transaction():

@pytest.mark.asyncio
async def test_profile_manager_store():
profile = "profileId"

with mock.patch("acapy_agent.askar.profile.AskarProfile") as AskarProfile:
askar_profile = AskarProfile(None, False, profile_id=profile)
askar_profile.profile_id = profile
askar_profile_session = mock.MagicMock()
askar_profile.store.session.return_value = askar_profile_session

sessionProfile = test_module.AskarProfileSession(askar_profile, False)

assert sessionProfile._opener == askar_profile_session
askar_profile.store.session.assert_called_once_with(profile)
config = {
"test": True,
}
context = InjectionContext(
settings=config,
)
await AskarProfileManager().provision(
context=context,
config=config,
)
await AskarAnonProfileManager().provision(
context=context,
config=config,
)
1 change: 1 addition & 0 deletions acapy_agent/commands/tests/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_exec_start(self):
"0.0.0.0",
"80",
"--no-ledger",
"--wallet-test",
]
)
start_app.assert_called_once()
Expand Down
1 change: 1 addition & 0 deletions acapy_agent/commands/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ async def test_execute(self):
"--from-version",
"v0.7.0",
"--force-upgrade",
"--wallet-test",
]
)

Expand Down
26 changes: 20 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,23 @@ 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",
action="store_true",
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 +1726,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 +1745,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
6 changes: 2 additions & 4 deletions acapy_agent/config/tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,7 @@ async def test_wallet_key_derivation_method_value_parsing(self):
group.add_arguments(parser)

result = parser.parse_args(
[
"--wallet-key-derivation-method",
key_derivation_method,
]
["--wallet-key-derivation-method", key_derivation_method, "--wallet-test"]
)

settings = group.get_settings(result)
Expand All @@ -545,6 +542,7 @@ async def test_wallet_key_value_parsing(self):
[
"--wallet-key",
key_value,
"--wallet-test",
]
)

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
2 changes: 1 addition & 1 deletion mkdocs-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

mkdocs-material==9.5.46
mkdocs-material==9.5.47
mike==2.1.3
Loading

0 comments on commit 583553e

Please sign in to comment.