From df69da03831cf3822e01f0cc968728918db6cbe0 Mon Sep 17 00:00:00 2001 From: ff137 Date: Mon, 3 Jun 2024 11:03:32 +0300 Subject: [PATCH] :construction: in progress --- aries_cloudagent/askar/profile.py | 2 +- .../protocols/connections/v1_0/routes.py | 12 +++++++++++- .../connections/v1_0/tests/test_routes.py | 2 ++ .../endorse_transaction/v1_0/routes.py | 12 +++++++++++- .../protocols/issue_credential/v2_0/routes.py | 7 +++++++ .../protocols/present_proof/v2_0/routes.py | 7 ++++++- aries_cloudagent/revocation/routes.py | 8 +++++++- aries_cloudagent/storage/askar.py | 18 ++++++++++++------ demo/runners/support/agent.py | 2 +- 9 files changed, 58 insertions(+), 12 deletions(-) diff --git a/aries_cloudagent/askar/profile.py b/aries_cloudagent/askar/profile.py index 27cec91b7c..5fc1e23a1a 100644 --- a/aries_cloudagent/askar/profile.py +++ b/aries_cloudagent/askar/profile.py @@ -219,7 +219,7 @@ def handle(self) -> Session: @property def store(self) -> Store: """Accessor for the Store instance.""" - return self._handle and self._handle.store + return self._handle and self._handle._store @property def is_transaction(self) -> bool: diff --git a/aries_cloudagent/protocols/connections/v1_0/routes.py b/aries_cloudagent/protocols/connections/v1_0/routes.py index e067b547af..13727cabc8 100644 --- a/aries_cloudagent/protocols/connections/v1_0/routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/routes.py @@ -13,6 +13,8 @@ ) from marshmallow import fields, validate, validates_schema +from aries_cloudagent.storage.base import DEFAULT_PAGE_SIZE + from ....admin.decorators.auth import tenant_authentication from ....admin.request_context import AdminRequestContext from ....cache.base import BaseCache @@ -468,11 +470,19 @@ async def connections_list(request: web.BaseRequest): if request.query.get("connection_protocol"): post_filter["connection_protocol"] = request.query["connection_protocol"] + limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE)) + offset = int(request.query.get("offset", 0)) + profile = context.profile try: async with profile.session() as session: records = await ConnRecord.query( - session, tag_filter, post_filter_positive=post_filter, alt=True + session, + tag_filter, + limit=limit, + offset=offset, + post_filter_positive=post_filter, + alt=True, ) results = [record.serialize() for record in records] results.sort(key=connection_sort_key) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py index d561e8f0a0..d56494d5bd 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py @@ -103,6 +103,8 @@ async def test_connections_list(self): "their_public_did": "a_public_did", "invitation_msg_id": "dummy_msg", }, + limit=100, + offset=0, post_filter_positive={ "their_role": list(ConnRecord.Role.REQUESTER.value), "connection_protocol": "connections/1.0", diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py index f4ab0f2ebc..de6d51ff3f 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py @@ -12,6 +12,8 @@ ) from marshmallow import fields, validate +from aries_cloudagent.storage.base import DEFAULT_PAGE_SIZE + from ....admin.decorators.auth import tenant_authentication from ....admin.request_context import AdminRequestContext from ....connections.models.conn_record import ConnRecord @@ -140,10 +142,18 @@ async def transactions_list(request: web.BaseRequest): tag_filter = {} post_filter = {} + limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE)) + offset = int(request.query.get("offset", 0)) + try: async with context.profile.session() as session: records = await TransactionRecord.query( - session, tag_filter, post_filter_positive=post_filter, alt=True + session, + tag_filter, + limit=limit, + offset=offset, + post_filter_positive=post_filter, + alt=True, ) results = [record.serialize() for record in records] except (StorageError, BaseModelError) as err: diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/routes.py b/aries_cloudagent/protocols/issue_credential/v2_0/routes.py index bf15b91df2..849ed655d0 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/routes.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/routes.py @@ -14,6 +14,8 @@ ) from marshmallow import ValidationError, fields, validate, validates_schema +from aries_cloudagent.storage.base import DEFAULT_PAGE_SIZE + from ....admin.decorators.auth import tenant_authentication from ....admin.request_context import AdminRequestContext from ....anoncreds.holder import AnonCredsHolderError @@ -566,11 +568,16 @@ async def credential_exchange_list(request: web.BaseRequest): if request.query.get(k, "") != "" } + limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE)) + offset = int(request.query.get("offset", 0)) + try: async with profile.session() as session: cred_ex_records = await V20CredExRecord.query( session=session, tag_filter=tag_filter, + limit=limit, + offset=offset, post_filter_positive=post_filter, ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/routes.py b/aries_cloudagent/protocols/present_proof/v2_0/routes.py index 943494522d..f8727bd25e 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/routes.py @@ -36,7 +36,7 @@ UUID4_EXAMPLE, UUID4_VALIDATE, ) -from ....storage.base import BaseStorage +from ....storage.base import DEFAULT_PAGE_SIZE, BaseStorage from ....storage.error import StorageError, StorageNotFoundError from ....storage.vc_holder.base import VCHolder from ....storage.vc_holder.vc_record import VCRecord @@ -448,11 +448,16 @@ async def present_proof_list(request: web.BaseRequest): if request.query.get(k, "") != "" } + limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE)) + offset = int(request.query.get("offset", 0)) + try: async with profile.session() as session: records = await V20PresExRecord.query( session=session, tag_filter=tag_filter, + limit=limit, + offset=offset, post_filter_positive=post_filter, ) results = [record.serialize() for record in records] diff --git a/aries_cloudagent/revocation/routes.py b/aries_cloudagent/revocation/routes.py index c2e0c13782..25eb6b0bec 100644 --- a/aries_cloudagent/revocation/routes.py +++ b/aries_cloudagent/revocation/routes.py @@ -56,7 +56,7 @@ get_endorser_connection_id, is_author_role, ) -from ..storage.base import BaseStorage +from ..storage.base import DEFAULT_PAGE_SIZE, BaseStorage from ..storage.error import StorageError, StorageNotFoundError from ..utils.profiles import is_anoncreds_profile_raise_web_exception from .error import RevocationError, RevocationNotSupportedError @@ -827,10 +827,16 @@ async def rev_regs_created(request: web.BaseRequest): tag_filter = { tag: request.query[tag] for tag in search_tags if tag in request.query } + + limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE)) + offset = int(request.query.get("offset", 0)) + async with context.profile.session() as session: found = await IssuerRevRegRecord.query( session, tag_filter, + limit=limit, + offset=offset, post_filter_negative={"state": IssuerRevRegRecord.STATE_INIT}, ) diff --git a/aries_cloudagent/storage/askar.py b/aries_cloudagent/storage/askar.py index aeb522bbdc..70141ed9e4 100644 --- a/aries_cloudagent/storage/askar.py +++ b/aries_cloudagent/storage/askar.py @@ -1,8 +1,8 @@ """Aries-Askar implementation of BaseStorage interface.""" -from typing import Mapping, Sequence +from typing import Mapping, Optional, Sequence -from aries_askar import AskarError, AskarErrorCode, Session +from aries_askar import AskarError, AskarErrorCode, Session, Store from ..askar.profile import AskarProfile, AskarProfileSession from .base import ( @@ -344,11 +344,14 @@ async def __anext__(self): tags=row.tags, ) - async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]: + async def fetch( + self, max_count: Optional[int] = None, offset: Optional[int] = None + ) -> Sequence[StorageRecord]: """Fetch the next list of results from the store. Args: max_count: Max number of records to return + offset: The offset to start retrieving records from Returns: A list of `StorageRecord` instances @@ -359,11 +362,12 @@ async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]: """ if self._done: raise StorageSearchError("Search query is complete") - await self._open() + + limit = max_count or self.page_size + await self._open(limit=limit, offset=offset) count = 0 ret = [] - limit = max_count or self.page_size while count < limit: try: @@ -389,7 +393,7 @@ async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]: return ret - async def _open(self): + async def _open(self, offset: Optional[int] = None, limit: Optional[int] = None): """Start the search query.""" if self._scan: return @@ -397,6 +401,8 @@ async def _open(self): self._scan = self._profile.store.scan( category=self.type_filter, tag_filter=self.tag_query, + offset=offset, + limit=limit, profile=self._profile.settings.get("wallet.askar_profile"), ) except AskarError as err: diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index 153be98abb..ae03cde81d 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -785,7 +785,7 @@ async def register_or_switch_wallet( "wallet_name": target_wallet_name, "wallet_type": self.wallet_type, "label": target_wallet_name, - "wallet_webhook_urls": self.webhook_url, + "wallet_webhook_urls": [self.webhook_url], "wallet_dispatch_type": "both", } self.wallet_name = target_wallet_name