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 admin route to create a presentation request without sending it #112

Merged
Merged
Changes from all 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
71 changes: 57 additions & 14 deletions aries_cloudagent/messaging/presentations/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,30 @@ async def presentation_exchange_credentials_list(request: web.BaseRequest):
return web.json_response(credentials)


@docs(tags=["presentation_exchange"], summary="Sends a presentation request")
async def _create_request_helper(context, spec):
"""Create a presentation request."""
connection_id = spec.get("connection_id")
name = spec.get("name")
version = spec.get("version")
requested_attributes = spec.get("requested_attributes")
requested_predicates = spec.get("requested_predicates")

presentation_manager = PresentationManager(context)

(
presentation_exchange_record,
presentation_request_message,
) = await presentation_manager.create_request(
name, version, requested_attributes, requested_predicates, connection_id
)
return presentation_exchange_record, presentation_request_message


@docs(tags=["presentation_exchange"], summary="Creates a presentation request")
@request_schema(PresentationRequestRequestSchema())
async def presentation_exchange_send_request(request: web.BaseRequest):
async def presentation_exchange_create_request(request: web.BaseRequest):
"""
Request handler for sending a presentation request.
Request handler for creating a presentation request.

Args:
request: aiohttp request object
Expand All @@ -206,27 +225,47 @@ async def presentation_exchange_send_request(request: web.BaseRequest):
"""

context = request.app["request_context"]
outbound_handler = request.app["outbound_message_router"]

body = await request.json()

connection_id = body.get("connection_id")
(
presentation_exchange_record,
presentation_request_message,
) = await _create_request_helper(context, body)

name = body.get("name")
version = body.get("version")
requested_attributes = body.get("requested_attributes")
requested_predicates = body.get("requested_predicates")
return web.json_response(presentation_exchange_record.serialize())

presentation_manager = PresentationManager(context)

@docs(
tags=["presentation_exchange"], summary="Creates and sends a presentation request"
)
@request_schema(PresentationRequestRequestSchema())
async def presentation_exchange_send_request(request: web.BaseRequest):
"""
Request handler for creating and sending a presentation request.

Args:
request: aiohttp request object

Returns:
The presentation exchange details.

"""

context = request.app["request_context"]
outbound_handler = request.app["outbound_message_router"]

body = await request.json()

(
presentation_exchange_record,
presentation_request_message,
) = await presentation_manager.create_request(
name, version, requested_attributes, requested_predicates, connection_id
)
) = await _create_request_helper(context, body)

await outbound_handler(presentation_request_message, connection_id=connection_id)
await outbound_handler(
presentation_request_message,
connection_id=presentation_exchange_record.connection_id,
)

return web.json_response(presentation_exchange_record.serialize())

Expand Down Expand Up @@ -353,6 +392,10 @@ async def register(app: web.Application):
"/presentation_exchange/{id}/credentials/{referent}",
presentation_exchange_credentials_list,
),
web.post(
"/presentation_exchange/create_request",
presentation_exchange_create_request,
),
web.post(
"/presentation_exchange/send_request",
presentation_exchange_send_request,
Expand Down