Skip to content

Commit

Permalink
Merge pull request #384 from ianco/fix-216-credential-api
Browse files Browse the repository at this point in the history
Add credential_id to store_credential protocol
  • Loading branch information
ianco authored Feb 24, 2020
2 parents d816653 + bc4fc7b commit 469e38f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 4 additions & 2 deletions aries_cloudagent/protocols/issue_credential/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ async def receive_credential(self) -> V10CredentialExchange:
return credential_exchange_record

async def store_credential(
self, credential_exchange_record: V10CredentialExchange
self, credential_exchange_record: V10CredentialExchange,
credential_id: str = None
) -> Tuple[V10CredentialExchange, CredentialAck]:
"""
Store a credential in holder wallet; send ack to issuer.
Expand Down Expand Up @@ -553,7 +554,8 @@ async def store_credential(
credential_definition,
raw_credential,
credential_exchange_record.credential_request_metadata,
mime_types
mime_types,
credential_id=credential_id
)

credential = await holder.get_credential(credential_id)
Expand Down
19 changes: 18 additions & 1 deletion aries_cloudagent/protocols/issue_credential/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from aiohttp_apispec import docs, request_schema, response_schema
from marshmallow import fields, Schema

from json.decoder import JSONDecodeError

from ....connections.models.connection_record import ConnectionRecord
from ....holder.base import BaseHolder
from ....messaging.credential_definitions.util import CRED_DEF_TAGS
Expand Down Expand Up @@ -43,6 +45,12 @@ class V10CredentialExchangeListResultSchema(Schema):
)


class V10CredentialStoreRequestSchema(Schema):
"""Request schema for sending a credential store admin message."""

credential_id = fields.Str(required=False)


class V10CredentialProposalRequestSchemaBase(Schema):
"""Base class for request schema for sending credential proposal admin message."""

Expand Down Expand Up @@ -568,6 +576,7 @@ async def credential_exchange_issue(request: web.BaseRequest):


@docs(tags=["issue-credential"], summary="Store a received credential")
@request_schema(V10CredentialStoreRequestSchema())
@response_schema(V10CredentialExchangeSchema(), 200)
async def credential_exchange_store(request: web.BaseRequest):
"""
Expand All @@ -583,6 +592,12 @@ async def credential_exchange_store(request: web.BaseRequest):
context = request.app["request_context"]
outbound_handler = request.app["outbound_message_router"]

try:
body = await request.json() or {}
credential_id = body.get("credential_id")
except JSONDecodeError:
credential_id = None

credential_exchange_id = request.match_info["cred_ex_id"]
credential_exchange_record = await V10CredentialExchange.retrieve_by_id(
context, credential_exchange_id
Expand All @@ -608,7 +623,9 @@ async def credential_exchange_store(request: web.BaseRequest):
(
credential_exchange_record,
credential_stored_message,
) = await credential_manager.store_credential(credential_exchange_record)
) = await credential_manager.store_credential(
credential_exchange_record, credential_id
)

await outbound_handler(credential_stored_message, connection_id=connection_id)
return web.json_response(credential_exchange_record.serialize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ async def test_store_credential(self):
cred,
cred_req_meta,
mock_preview_deserialize.return_value.mime_types.return_value,
credential_id=None,
)

holder.get_credential.assert_called_once_with(cred_id)
Expand Down Expand Up @@ -831,7 +832,8 @@ async def test_store_credential_no_preview(self):
cred_def,
cred,
cred_req_meta,
None
None,
credential_id=None
)

holder.get_credential.assert_called_once_with(cred_id)
Expand Down

0 comments on commit 469e38f

Please sign in to comment.