Skip to content

Commit

Permalink
Merge pull request #112 from andrewwhitehead/create-pres-req
Browse files Browse the repository at this point in the history
Add admin route to create a presentation request without sending it
  • Loading branch information
nrempel authored Aug 1, 2019
2 parents a22edc9 + 60ed12c commit a876e88
Showing 1 changed file with 57 additions and 14 deletions.
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

0 comments on commit a876e88

Please sign in to comment.