Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add ordering functionality to fetching of askar records #989

Merged
merged 29 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
386ae52
:construction: test feat/pagination-ordering
ff137 Aug 19, 2024
315e95e
:white_check_mark: re-add assertion that pagination returns unique re…
ff137 Aug 19, 2024
f1dbc17
:art: fix assertion error message
ff137 Aug 21, 2024
73969f1
:bug: fetch alice credentials/proofs instead of for faber/acme
ff137 Aug 21, 2024
37549da
:art: clean-up alice exchange records too
ff137 Aug 21, 2024
7edb211
:art:
ff137 Aug 21, 2024
2728f8d
:art:
ff137 Aug 22, 2024
bc3e91e
Update lock files
ff137 Aug 22, 2024
5a8e4c7
:construction: point to cloudcontroller test branch
ff137 Aug 22, 2024
c69d0c5
Merge branch 'development' into test/feat/pagination-ordering
ff137 Aug 29, 2024
2c75449
:sparkles: Implement order_by and descending query params
ff137 Aug 29, 2024
b7fee87
:art: Update doc strings
ff137 Aug 29, 2024
5c30309
:arrow_up: Update base image to our fork
ff137 Aug 29, 2024
141bd19
:arrow_up: Update redis_events plugin reference
ff137 Aug 29, 2024
76b4eb3
:arrow_up: Update acapy-wallet-groups-plugin
ff137 Aug 29, 2024
40c50e7
:arrow_up: Update cloudcontroller
ff137 Aug 29, 2024
2aae23f
:construction_worker: Revert test build context
ff137 Aug 29, 2024
6f15001
Merge branch 'development' into test/feat/pagination-ordering
ff137 Aug 29, 2024
5bf3674
:art: Change default descending behaviour to True
ff137 Aug 29, 2024
bd8d727
:white_check_mark: fix tests with new expected assertions
ff137 Aug 29, 2024
acce9f3
:art: add validation to limit and offset query params
ff137 Aug 29, 2024
304ca0e
:arrow_up: Point to latest tag of redis_events plugin
ff137 Aug 29, 2024
78ff6a5
:art: limit query param should be ge=1, not 0
ff137 Aug 30, 2024
7b7fd1b
:art: correct docstring
ff137 Aug 30, 2024
9482dd7
:arrow_up: Update acapy-wallet-groups-plugin
ff137 Aug 30, 2024
09d8296
:arrow_up: Update redis_events plugin reference
ff137 Aug 30, 2024
5c37178
:arrow_up: Use new 1.0.0b1 image
ff137 Aug 30, 2024
633e577
:white_check_mark: assert record ordering
ff137 Aug 30, 2024
478a497
Merge branch 'development' into test/feat/pagination-ordering
ff137 Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
371 changes: 191 additions & 180 deletions app/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package-mode = false
python = "^3.12"

aiohttp = "~3.10.5"
aries-cloudcontroller = "==1.0.0"
aries-cloudcontroller = "==1.0.0b0"
base58 = "~2.1.1"
fastapi = "~0.112.0"
fastapi_websocket_pubsub = "~0.3.8"
Expand Down
11 changes: 10 additions & 1 deletion app/routes/admin/tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
remove_actor_by_id,
)
from app.services.trust_registry.util.actor import assert_actor_name
from app.util.pagination import limit_query_parameter, offset_query_parameter
from app.util.pagination import (
descending_query_parameter,
limit_query_parameter,
offset_query_parameter,
order_by_query_parameter,
)
from app.util.tenants import (
get_wallet_and_assert_valid_group,
tenant_from_wallet_record,
Expand Down Expand Up @@ -307,6 +312,8 @@ async def get_tenants(
group_id: Optional[str] = group_id_query,
limit: Optional[int] = limit_query_parameter,
offset: Optional[int] = offset_query_parameter,
order_by: Optional[str] = order_by_query_parameter,
descending: bool = descending_query_parameter,
admin_auth: AcaPyAuthVerified = Depends(acapy_auth_tenant_admin),
) -> List[Tenant]:
"""Get all tenants, or fetch by wallet name."""
Expand All @@ -321,6 +328,8 @@ async def get_tenants(
acapy_call=admin_controller.multitenancy.get_wallets,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
wallet_name=wallet_name,
group_id=group_id,
)
Expand Down
12 changes: 11 additions & 1 deletion app/routes/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from app.dependencies.auth import AcaPyAuth, acapy_auth_from_header
from app.exceptions import handle_acapy_call
from app.models.connections import AcceptInvitation, CreateInvitation
from app.util.pagination import limit_query_parameter, offset_query_parameter
from app.util.pagination import (
descending_query_parameter,
limit_query_parameter,
offset_query_parameter,
order_by_query_parameter,
)
from shared.log_config import get_logger
from shared.models.connection_record import (
Connection,
Expand Down Expand Up @@ -137,6 +142,8 @@ async def accept_invitation(
async def get_connections(
limit: Optional[int] = limit_query_parameter,
offset: Optional[int] = offset_query_parameter,
order_by: Optional[str] = order_by_query_parameter,
descending: bool = descending_query_parameter,
alias: Optional[str] = None,
connection_protocol: Optional[Protocol] = None,
invitation_key: Optional[str] = None,
Expand All @@ -160,6 +167,7 @@ async def get_connections(
---
limit: int - The maximum number of records to retrieve
offset: int - The offset to start retrieving records from
descending: bool - Whether to return results in descending order. Results are ordered by record created time.
alias: str
connection_protocol: Protocol: "connections/1.0", "didexchange/1.0"
invitation_key: str
Expand All @@ -183,6 +191,8 @@ async def get_connections(
acapy_call=aries_controller.connection.get_connections,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
alias=alias,
connection_protocol=connection_protocol,
invitation_key=invitation_key,
Expand Down
14 changes: 13 additions & 1 deletion app/routes/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
issuer_from_protocol_version,
)
from app.util.did import did_from_credential_definition_id, qualified_did_sov
from app.util.pagination import limit_query_parameter, offset_query_parameter
from app.util.pagination import (
descending_query_parameter,
limit_query_parameter,
offset_query_parameter,
order_by_query_parameter,
)
from app.util.retry_method import coroutine_with_retry_until_value
from shared.log_config import get_logger
from shared.models.credential_exchange import (
Expand Down Expand Up @@ -338,6 +343,8 @@ async def store_credential(
async def get_credentials(
limit: Optional[int] = limit_query_parameter,
offset: Optional[int] = offset_query_parameter,
order_by: Optional[str] = order_by_query_parameter,
descending: bool = descending_query_parameter,
connection_id: Optional[str] = Query(None),
role: Optional[Role] = Query(None),
state: Optional[State] = Query(None),
Expand Down Expand Up @@ -365,6 +372,7 @@ async def get_credentials(
---
limit: int - The maximum number of records to retrieve
offset: int - The offset to start retrieving records from
descending: bool - Whether to return results in descending order. Results are ordered by record created time.
connection_id: str
role: Role: "issuer", "holder"
state: State: "proposal-sent", "proposal-received", "offer-sent", "offer-received",
Expand All @@ -386,6 +394,8 @@ async def get_credentials(
controller=aries_controller,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=back_to_v1_credential_state(state) if state else None,
Expand All @@ -397,6 +407,8 @@ async def get_credentials(
controller=aries_controller,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=state,
Expand Down
16 changes: 14 additions & 2 deletions app/routes/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
assert_valid_verifier,
get_verifier_by_version,
)
from app.util.pagination import limit_query_parameter, offset_query_parameter
from app.util.pagination import (
descending_query_parameter,
limit_query_parameter,
offset_query_parameter,
order_by_query_parameter,
)
from shared.log_config import get_logger
from shared.models.presentation_exchange import (
PresentationExchange,
Expand Down Expand Up @@ -327,6 +332,8 @@ async def reject_proof_request(
async def get_proof_records(
limit: Optional[int] = limit_query_parameter,
offset: Optional[int] = offset_query_parameter,
order_by: Optional[str] = order_by_query_parameter,
descending: bool = descending_query_parameter,
connection_id: Optional[str] = None,
role: Optional[Role] = None,
state: Optional[State] = None,
Expand All @@ -344,6 +351,7 @@ async def get_proof_records(
---
limit: int: The maximum number of records to retrieve
offset: int: The offset to start retrieving records from
descending: bool - Whether to return results in descending order. Results are ordered by record created time.
connection_id: str
role: Role: "prover", "verifier"
state: State: "presentation-received", "presentation-sent", "proposal-received", "proposal-sent",
Expand All @@ -365,6 +373,8 @@ async def get_proof_records(
controller=aries_controller,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=back_to_v1_presentation_state(state) if state else None,
Expand All @@ -375,6 +385,8 @@ async def get_proof_records(
controller=aries_controller,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=state,
Expand All @@ -384,7 +396,7 @@ async def get_proof_records(
logger.info("Could not fetch proof records: {}.", e)
raise

result = v1_records + v2_records
result = v1_records + v2_records # TODO: V1 to be deprecated. No need to re-order
if result:
logger.debug("Successfully fetched v1 and v2 records.")
else:
Expand Down
30 changes: 26 additions & 4 deletions app/services/issuer/acapy_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,41 @@ async def get_records(
controller: AcaPyClient,
limit: Optional[int] = None,
offset: Optional[int] = None,
order_by: Optional[str] = "id",
descending: bool = True,
connection_id: Optional[str] = None,
role: Optional[str] = None,
state: Optional[str] = None,
thread_id: Optional[str] = None,
) -> List[CredentialExchange]:
"""Get list of credential records.
"""
Get a list of credential records.

Parameters:
-----------
controller: AcaPyClient
The aries_cloudcontroller object
connection_id:
Filter credential record by connection id
The aries_cloudcontroller object used to interact with the ACA-Py API.
limit: Optional[int]
The maximum number of records to return. If not specified, returns all available records.
offset: Optional[int]
The starting index from where to return records. Useful for pagination.
order_by: Optional[str]
The field by which to order the results. Default is "id".
descending: bool
If True, the results are sorted in descending order. Default is True (descending order).
connection_id: Optional[str]
Filter by the connection ID associated with the credential records.
role: Optional[str]
Filter by the role of the agent in the credential exchange (e.g., "issuer", "holder").
state: Optional[str]
Filter by the state of the credential exchange (e.g., "offer_sent", "credential_issued").
thread_id: Optional[str]
Filter by the thread ID associated with the credential exchange.

Returns:
--------
List[CredentialExchange]
A list of credential exchange records.
"""

@classmethod
Expand Down
4 changes: 4 additions & 0 deletions app/services/issuer/acapy_issuer_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ async def get_records(
controller: AcaPyClient,
limit: Optional[int] = None,
offset: Optional[int] = None,
order_by: Optional[str] = "id",
descending: bool = True,
connection_id: Optional[str] = None,
role: Optional[str] = None,
state: Optional[str] = None,
Expand All @@ -191,6 +193,8 @@ async def get_records(
acapy_call=controller.issue_credential_v1_0.get_records,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=state,
Expand Down
4 changes: 4 additions & 0 deletions app/services/issuer/acapy_issuer_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ async def get_records(
controller: AcaPyClient,
limit: Optional[int] = None,
offset: Optional[int] = None,
order_by: Optional[str] = "id",
descending: bool = True,
connection_id: Optional[str] = None,
role: Optional[str] = None,
state: Optional[str] = None,
Expand All @@ -213,6 +215,8 @@ async def get_records(
acapy_call=controller.issue_credential_v2_0.get_records,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=state,
Expand Down
37 changes: 31 additions & 6 deletions app/services/verifier/acapy_verifier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import List
from typing import List, Optional

from aries_cloudcontroller import AcaPyClient, IndyCredPrecis

Expand Down Expand Up @@ -106,20 +106,45 @@ async def reject_proof_request(
@classmethod
@abstractmethod
async def get_proof_records(
cls, controller: AcaPyClient
cls,
controller: AcaPyClient,
limit: Optional[int] = None,
offset: Optional[int] = None,
order_by: Optional[str] = "id",
descending: bool = True,
connection_id: str = None,
role: str = None,
state: str = None,
thread_id: str = None,
) -> List[PresentationExchange]:
"""
Get all proof records
Get all proof records.

Parameters:
-----------
controller: AcaPyClient
The aries_cloudcontroller object
The aries_cloudcontroller object used to interact with the ACA-Py API.
limit: Optional[int]
The maximum number of records to return. If not specified, returns all available records.
offset: Optional[int]
The starting index from where to return records. Useful for pagination.
order_by: Optional[str]
The field by which to order the results. Default is "id".
descending: bool
If True, the results are sorted in descending order. Default is True (descending order).
connection_id: Optional[str]
Filter by the connection ID associated with the proof records.
role: Optional[str]
Filter by the role of the agent in the proof exchange (e.g., "prover", "verifier").
state: Optional[str]
Filter by the state of the proof exchange (e.g., "request_sent", "presentation_acked").
thread_id: Optional[str]
Filter by the thread ID associated with the proof exchange.

Returns:
--------
[PresentationExchange]
A list of presentation exchange records
List[PresentationExchange]
A list of presentation exchange records.
"""

@classmethod
Expand Down
4 changes: 4 additions & 0 deletions app/services/verifier/acapy_verifier_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ async def get_proof_records(
controller: AcaPyClient,
limit: Optional[int] = None,
offset: Optional[int] = None,
order_by: Optional[str] = "id",
descending: bool = True,
connection_id: str = None,
role: str = None,
state: str = None,
Expand All @@ -199,6 +201,8 @@ async def get_proof_records(
acapy_call=controller.present_proof_v1_0.get_records,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=state,
Expand Down
4 changes: 4 additions & 0 deletions app/services/verifier/acapy_verifier_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ async def get_proof_records(
controller: AcaPyClient,
limit: Optional[int] = None,
offset: Optional[int] = None,
order_by: Optional[str] = "id",
descending: bool = True,
connection_id: str = None,
role: str = None,
state: str = None,
Expand All @@ -215,6 +217,8 @@ async def get_proof_records(
acapy_call=controller.present_proof_v2_0.get_records,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=state,
Expand Down
Loading
Loading