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

Endorser protocol askar fixes #1450

Merged
merged 18 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
155 changes: 78 additions & 77 deletions aries_cloudagent/holder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ async def credentials_get(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
credential_id = request.match_info["credential_id"]
session = await context.session()

holder = session.inject(IndyHolder)
try:
credential = await holder.get_credential(credential_id)
except WalletNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
async with context.profile.session() as session:
holder = session.inject(IndyHolder)
ianco marked this conversation as resolved.
Show resolved Hide resolved
try:
credential = await holder.get_credential(credential_id)
except WalletNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err

credential_json = json.loads(credential)
return web.json_response(credential_json)
Expand All @@ -202,31 +202,31 @@ async def credentials_revoked(request: web.BaseRequest):

"""
context: AdminRequestContext = request["context"]
session = await context.session()
credential_id = request.match_info["credential_id"]
fro = request.query.get("from")
to = request.query.get("to")

ledger = session.inject_or(BaseLedger)
if not ledger:
reason = "No ledger available"
if not context.settings.get_value("wallet.type"):
reason += ": missing wallet-type?"
raise web.HTTPForbidden(reason=reason)

async with ledger:
try:
holder = session.inject(IndyHolder)
revoked = await holder.credential_revoked(
ledger,
credential_id,
int(fro) if fro else None,
int(to) if to else None,
)
except WalletNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except LedgerError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
async with context.profile.session() as session:
ledger = session.inject_or(BaseLedger)
if not ledger:
reason = "No ledger available"
if not context.settings.get_value("wallet.type"):
reason += ": missing wallet-type?"
raise web.HTTPForbidden(reason=reason)

async with ledger:
try:
holder = session.inject(IndyHolder)
revoked = await holder.credential_revoked(
ledger,
credential_id,
int(fro) if fro else None,
int(to) if to else None,
)
except WalletNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except LedgerError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

return web.json_response({"revoked": revoked})

Expand All @@ -246,11 +246,12 @@ async def credentials_attr_mime_types_get(request: web.BaseRequest):

"""
context: AdminRequestContext = request["context"]
session = await context.session()
credential_id = request.match_info["credential_id"]

holder = session.inject(IndyHolder)
return web.json_response({"results": await holder.get_mime_type(credential_id)})
async with context.profile.session() as session:
holder = session.inject(IndyHolder)
mime_types = await holder.get_mime_type(credential_id)
return web.json_response({"results": mime_types})


@docs(tags=["credentials"], summary="Remove credential from wallet by id")
Expand All @@ -270,12 +271,12 @@ async def credentials_remove(request: web.BaseRequest):
context: AdminRequestContext = request["context"]
credential_id = request.match_info["credential_id"]

session = await context.session()
holder = session.inject(IndyHolder)
try:
await holder.delete_credential(credential_id)
except WalletNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
async with context.profile.session() as session:
holder = session.inject(IndyHolder)
try:
await holder.delete_credential(credential_id)
ianco marked this conversation as resolved.
Show resolved Hide resolved
except WalletNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err

return web.json_response({})

Expand All @@ -298,7 +299,6 @@ async def credentials_list(request: web.BaseRequest):

"""
context: AdminRequestContext = request["context"]
session = await context.session()
start = request.query.get("start")
count = request.query.get("count")

Expand All @@ -310,11 +310,12 @@ async def credentials_list(request: web.BaseRequest):
start = int(start) if isinstance(start, str) else 0
count = int(count) if isinstance(count, str) else 10

holder = session.inject(IndyHolder)
try:
credentials = await holder.get_credentials(start, count, wql)
except IndyHolderError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
async with context.profile.session() as session:
holder = session.inject(IndyHolder)
try:
credentials = await holder.get_credentials(start, count, wql)
except IndyHolderError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

return web.json_response({"results": credentials})

Expand All @@ -339,14 +340,14 @@ async def w3c_cred_get(request: web.BaseRequest):
context: AdminRequestContext = request["context"]
credential_id = request.match_info["credential_id"]

session = await context.session()
holder = session.inject(VCHolder)
try:
vc_record = await holder.retrieve_credential_by_id(credential_id)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
async with context.profile.session() as session:
holder = session.inject(VCHolder)
try:
vc_record = await holder.retrieve_credential_by_id(credential_id)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

return web.json_response(vc_record.serialize())

Expand All @@ -371,15 +372,15 @@ async def w3c_cred_remove(request: web.BaseRequest):
context: AdminRequestContext = request["context"]
credential_id = request.match_info["credential_id"]

session = await context.session()
holder = session.inject(VCHolder)
try:
vc_record = await holder.retrieve_credential_by_id(credential_id)
await holder.delete_credential(vc_record)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
async with context.profile.session() as session:
holder = session.inject(VCHolder)
try:
vc_record = await holder.retrieve_credential_by_id(credential_id)
await holder.delete_credential(vc_record)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

return web.json_response({})

Expand All @@ -403,7 +404,6 @@ async def w3c_creds_list(request: web.BaseRequest):

"""
context: AdminRequestContext = request["context"]
session = await context.session()
body = await request.json()
contexts = body.get("contexts")
types = body.get("types")
Expand All @@ -415,23 +415,24 @@ async def w3c_creds_list(request: web.BaseRequest):
tag_query = body.get("tag_query")
max_results = body.get("max_results")

holder = session.inject(VCHolder)
try:
search = holder.search_credentials(
contexts=contexts,
types=types,
schema_ids=schema_ids,
issuer_id=issuer_id,
subject_ids=subject_ids,
proof_types=proof_types,
given_id=given_id,
tag_query=tag_query,
)
records = await search.fetch(max_results)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
async with context.profile.session() as session:
holder = session.inject(VCHolder)
try:
search = holder.search_credentials(
contexts=contexts,
types=types,
schema_ids=schema_ids,
issuer_id=issuer_id,
subject_ids=subject_ids,
proof_types=proof_types,
given_id=given_id,
tag_query=tag_query,
)
records = await search.fetch(max_results)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

return web.json_response({"results": [record.serialize() for record in records]})

Expand Down
Loading