Skip to content

Commit

Permalink
🎨 Modify count/start query params to be Integers, not Strings
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Aug 29, 2024
1 parent fcbfb2f commit 806cf5d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
31 changes: 17 additions & 14 deletions aries_cloudagent/holder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 14 additions & 17 deletions aries_cloudagent/protocols/present_proof/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
31 changes: 14 additions & 17 deletions aries_cloudagent/protocols/present_proof/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 806cf5d

Please sign in to comment.