From 806cf5d608c5587bf9d7d4aecc6ec2a3a55c0794 Mon Sep 17 00:00:00 2001 From: ff137 Date: Thu, 29 Aug 2024 12:15:10 +0300 Subject: [PATCH] :art: Modify count/start query params to be Integers, not Strings Signed-off-by: ff137 --- aries_cloudagent/holder/routes.py | 31 ++++++++++--------- .../protocols/present_proof/v1_0/routes.py | 31 +++++++++---------- .../protocols/present_proof/v2_0/routes.py | 31 +++++++++---------- 3 files changed, 45 insertions(+), 48 deletions(-) diff --git a/aries_cloudagent/holder/routes.py b/aries_cloudagent/holder/routes.py index 37c1d5e1e7..2d8001656c 100644 --- a/aries_cloudagent/holder/routes.py +++ b/aries_cloudagent/holder/routes.py @@ -27,11 +27,13 @@ ENDPOINT_VALIDATE, INDY_WQL_EXAMPLE, INDY_WQL_VALIDATE, - NUM_STR_NATURAL_EXAMPLE, - NUM_STR_NATURAL_VALIDATE, + NATURAL_NUM_EXAMPLE, + NATURAL_NUM_VALIDATE, NUM_STR_WHOLE_EXAMPLE, NUM_STR_WHOLE_VALIDATE, UUID4_EXAMPLE, + WHOLE_NUM_EXAMPLE, + WHOLE_NUM_VALIDATE, ) from ..storage.error import StorageError, StorageNotFoundError from ..storage.vc_holder.base import VCHolder @@ -64,17 +66,22 @@ class CredInfoListSchema(OpenAPISchema): class CredentialsListQueryStringSchema(OpenAPISchema): """Parameters and validators for query string in credentials list query.""" - start = fields.Str( + start = fields.Int( required=False, - validate=NUM_STR_WHOLE_VALIDATE, - metadata={"description": "Start index", "example": NUM_STR_WHOLE_EXAMPLE}, + load_default=0, + validate=WHOLE_NUM_VALIDATE, + metadata={ + "description": "Start index", + "example": WHOLE_NUM_EXAMPLE, + }, ) - count = fields.Str( + count = fields.Int( required=False, - validate=NUM_STR_NATURAL_VALIDATE, + load_default=10, + validate=NATURAL_NUM_VALIDATE, metadata={ "description": "Maximum number to retrieve", - "example": NUM_STR_NATURAL_EXAMPLE, + "example": NATURAL_NUM_EXAMPLE, }, ) wql = fields.Str( @@ -379,17 +386,13 @@ async def credentials_list(request: web.BaseRequest): """ context: AdminRequestContext = request["context"] - start = request.query.get("start") - count = request.query.get("count") + start = int(request.query.get("start", 0)) + count = int(request.query.get("count", 10)) # url encoded json wql encoded_wql = request.query.get("wql") or "{}" wql = json.loads(encoded_wql) - # defaults - start = int(start) if isinstance(start, str) else 0 - count = int(count) if isinstance(count, str) else 10 - if context.settings.get(wallet_type_config) == "askar-anoncreds": holder = AnonCredsHolder(context.profile) credentials = await holder.get_credentials(start, count, wql) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/routes.py b/aries_cloudagent/protocols/present_proof/v1_0/routes.py index 97459a687e..cee88c5e9c 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/routes.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/routes.py @@ -29,12 +29,12 @@ from ....messaging.valid import ( INDY_EXTRA_WQL_EXAMPLE, INDY_EXTRA_WQL_VALIDATE, - NUM_STR_NATURAL_EXAMPLE, - NUM_STR_NATURAL_VALIDATE, - NUM_STR_WHOLE_EXAMPLE, - NUM_STR_WHOLE_VALIDATE, + NATURAL_NUM_EXAMPLE, + NATURAL_NUM_VALIDATE, UUID4_EXAMPLE, UUID4_VALIDATE, + WHOLE_NUM_EXAMPLE, + WHOLE_NUM_VALIDATE, ) from ....storage.error import StorageError, StorageNotFoundError from ....utils.tracing import AdminAPIMessageTracingSchema, get_timer, trace_event @@ -235,21 +235,22 @@ class CredentialsFetchQueryStringSchema(OpenAPISchema): "example": "1_name_uuid,2_score_uuid", }, ) - start = fields.Str( + start = fields.Int( required=False, - validate=NUM_STR_WHOLE_VALIDATE, + load_default=0, + validate=WHOLE_NUM_VALIDATE, metadata={ "description": "Start index", - "strict": True, - "example": NUM_STR_WHOLE_EXAMPLE, + "example": WHOLE_NUM_EXAMPLE, }, ) - count = fields.Str( + count = fields.Int( required=False, - validate=NUM_STR_NATURAL_VALIDATE, + load_default=10, + validate=NATURAL_NUM_VALIDATE, metadata={ "description": "Maximum number to retrieve", - "example": NUM_STR_NATURAL_EXAMPLE, + "example": NATURAL_NUM_EXAMPLE, }, ) extra_query = fields.Str( @@ -413,17 +414,13 @@ async def presentation_exchange_credentials_list(request: web.BaseRequest): except StorageNotFoundError as err: raise web.HTTPNotFound(reason=err.roll_up) from err - start = request.query.get("start") - count = request.query.get("count") + start = int(request.query.get("start", 0)) + count = int(request.query.get("count", 10)) # url encoded json extra_query encoded_extra_query = request.query.get("extra_query") or "{}" extra_query = json.loads(encoded_extra_query) - # defaults - start = int(start) if isinstance(start, str) else 0 - count = int(count) if isinstance(count, str) else 10 - holder = profile.inject(IndyHolder) try: credentials = await holder.get_credentials_for_presentation_request_by_referent( diff --git a/aries_cloudagent/protocols/present_proof/v2_0/routes.py b/aries_cloudagent/protocols/present_proof/v2_0/routes.py index 2edb0e4c08..853ed892f0 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/routes.py @@ -30,12 +30,12 @@ from ....messaging.valid import ( INDY_EXTRA_WQL_EXAMPLE, INDY_EXTRA_WQL_VALIDATE, - NUM_STR_NATURAL_EXAMPLE, - NUM_STR_NATURAL_VALIDATE, - NUM_STR_WHOLE_EXAMPLE, - NUM_STR_WHOLE_VALIDATE, + NATURAL_NUM_EXAMPLE, + NATURAL_NUM_VALIDATE, UUID4_EXAMPLE, UUID4_VALIDATE, + WHOLE_NUM_EXAMPLE, + WHOLE_NUM_VALIDATE, ) from ....storage.base import BaseStorage from ....storage.error import StorageError, StorageNotFoundError @@ -348,21 +348,22 @@ class V20CredentialsFetchQueryStringSchema(OpenAPISchema): "example": "1_name_uuid,2_score_uuid", }, ) - start = fields.Str( + start = fields.Int( required=False, - validate=NUM_STR_WHOLE_VALIDATE, + load_default=0, + validate=WHOLE_NUM_VALIDATE, metadata={ "description": "Start index", - "strict": True, - "example": NUM_STR_WHOLE_EXAMPLE, + "example": WHOLE_NUM_EXAMPLE, }, ) - count = fields.Str( + count = fields.Int( required=False, - validate=NUM_STR_NATURAL_VALIDATE, + load_default=10, + validate=NATURAL_NUM_VALIDATE, metadata={ "description": "Maximum number to retrieve", - "example": NUM_STR_NATURAL_EXAMPLE, + "example": NATURAL_NUM_EXAMPLE, }, ) extra_query = fields.Str( @@ -544,17 +545,13 @@ async def present_proof_credentials_list(request: web.BaseRequest): except StorageNotFoundError as err: raise web.HTTPNotFound(reason=err.roll_up) from err - start = request.query.get("start") - count = request.query.get("count") + start = int(request.query.get("start", 0)) + count = int(request.query.get("count", 10)) # url encoded json extra_query encoded_extra_query = request.query.get("extra_query") or "{}" extra_query = json.loads(encoded_extra_query) - # defaults - start = int(start) if isinstance(start, str) else 0 - count = int(count) if isinstance(count, str) else 10 - wallet_type = profile.settings.get_value("wallet.type") if wallet_type == "askar-anoncreds": indy_holder = AnonCredsHolder(profile)