Skip to content

Commit

Permalink
Merge branch 'feature/undelivered-events' of github.com:Indicio-tech/…
Browse files Browse the repository at this point in the history
…aries-cloudagent-python into feature/undelivered-events
  • Loading branch information
mepeltier committed Mar 29, 2022
2 parents c80ed59 + 9cc2013 commit 4868141
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 159 deletions.
3 changes: 3 additions & 0 deletions .commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
};
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
repos:
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v2.2.0
hooks:
- id: commitlint
stages: [commit-msg]
args: ["--config", ".commitlint.config.js"]
additional_dependencies: ['@commitlint/config-conventional']
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
stages: [commit]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.0
hooks:
- id: flake8
stages: [commit]
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,21 @@ end-user and developer demos in the repo should include updates or extensions to
If you would like to propose a significant change, please open an issue first to discuss the work with the community.

Contributions are made pursuant to the Developer's Certificate of Origin, available at [https://developercertificate.org](https://developercertificate.org), and licensed under the Apache License, version 2.0 (Apache-2.0).

## Development Tools

### Pre-commit

A configuration for [pre-commit](https://pre-commit.com/) is included in this repository. This is an optional tool to help contributors commit code that follows the formatting requirements enforced by the CI pipeline. Additionally, it can be used to help contributors write descriptive commit messages that can be parsed by changelog generators.

On each commit, pre-commit hooks will run that verify the committed code complies with flake8 and is formatted with black. To install the flake8 and black checks:

```
$ pre-commit install
```

To install the commit message linter:

```
$ pre-commit install --hook-type commit-msg
```
4 changes: 2 additions & 2 deletions SupportedRFCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ and an overview of the ACA-Py feature set. This document is
manually updated and as such, may not be up to date with the most recent release of
ACA-Py or the repository `main` branch. Reminders (and PRs!) to update this page are
welcome! If you have any questions, please contact us on the #aries channel on
[Hyperledger Rocketchat](https://chat.hyperledger.org) or through an issue in this repo.
[Hyperledger Discord](https://discord.gg/hyperledger) or through an issue in this repo.

**Last Update**: 2021-12-22, Release 0.7.3

> The checklist version of this document was created as a joint effort
> between [Northern Block](https://northernblock.io/) and [Animo Solutions](https://animo.id/).
> between [Northern Block](https://northernblock.io/), [Animo Solutions](https://animo.id/) and the Ontario government, on behalf of the Ontario government.
## AIP Support and Interoperability

Expand Down
5 changes: 4 additions & 1 deletion aries_cloudagent/connections/models/conn_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def __eq__(self, other: Union[str, "ConnRecord.State"]) -> bool:
"invitation_key",
"their_public_did",
"invitation_msg_id",
"their_role",
}

RECORD_TYPE = "connection"
Expand Down Expand Up @@ -373,7 +374,7 @@ async def find_existing_connection(

@classmethod
async def retrieve_by_request_id(
cls, session: ProfileSession, request_id: str
cls, session: ProfileSession, request_id: str, their_role: str = None
) -> "ConnRecord":
"""Retrieve a connection record from our previous request ID.
Expand All @@ -382,6 +383,8 @@ async def retrieve_by_request_id(
request_id: The ID of the originating connection request
"""
tag_filter = {"request_id": request_id}
if their_role:
tag_filter["their_role"] = their_role
return await cls.retrieve_by_tag_filter(session, tag_filter)

@classmethod
Expand Down
25 changes: 19 additions & 6 deletions aries_cloudagent/messaging/credential_definitions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,12 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq
except (IndyIssuerError, LedgerError) as e:
raise web.HTTPBadRequest(reason=e.message) from e

issuer_did = cred_def_id.split(":")[0]
meta_data = {
"context": {
"schema_id": schema_id,
"cred_def_id": cred_def_id,
"issuer_did": issuer_did,
"support_revocation": support_revocation,
"novel": novel,
"tag": tag,
Expand All @@ -263,15 +266,20 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq

if not create_transaction_for_endorser:
# Notify event
issuer_did = cred_def_id.split(":")[0]
meta_data["context"]["schema_id"] = schema_id
meta_data["context"]["cred_def_id"] = cred_def_id
meta_data["context"]["issuer_did"] = issuer_did
meta_data["processing"]["auto_create_rev_reg"] = True
await notify_cred_def_event(context.profile, cred_def_id, meta_data)

return web.json_response({"credential_definition_id": cred_def_id})
return web.json_response(
{
"sent": {"credential_definition_id": cred_def_id},
"credential_definition_id": cred_def_id,
}
)

# If the transaction is for the endorser, but the schema has already been created,
# then we send back the schema since the transaction will fail to be created.
elif "signed_txn" not in cred_def:
return web.json_response({"sent": {"credential_definition_id": cred_def_id}})
else:
meta_data["processing"]["auto_create_rev_reg"] = context.settings.get_value(
"endorser.auto_create_rev_reg"
Expand Down Expand Up @@ -301,7 +309,12 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq

await outbound_handler(transaction_request, connection_id=connection_id)

return web.json_response({"txn": transaction.serialize()})
return web.json_response(
{
"sent": {"credential_definition_id": cred_def_id},
"txn": transaction.serialize(),
}
)


@docs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ async def test_send_credential_definition(self):
)
assert result == mock_response.return_value
mock_response.assert_called_once_with(
{"credential_definition_id": CRED_DEF_ID}
{
"sent": {"credential_definition_id": CRED_DEF_ID},
"credential_definition_id": CRED_DEF_ID,
}
)

async def test_send_credential_definition_create_transaction_for_endorser(self):
Expand Down Expand Up @@ -126,7 +129,12 @@ async def test_send_credential_definition_create_transaction_for_endorser(self):
)
)
assert result == mock_response.return_value
mock_response.assert_called_once_with({"txn": {"...": "..."}})
mock_response.assert_called_once_with(
{
"sent": {"credential_definition_id": CRED_DEF_ID},
"txn": {"...": "..."},
}
)

async def test_send_credential_definition_create_transaction_for_endorser_storage_x(
self,
Expand Down
23 changes: 20 additions & 3 deletions aries_cloudagent/messaging/schemas/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,20 @@ async def schemas_send_schema(request: web.BaseRequest):
if not create_transaction_for_endorser:
# Notify event
await notify_schema_event(context.profile, schema_id, meta_data)
return web.json_response({"schema_id": schema_id, "schema": schema_def})

return web.json_response(
{
"sent": {"schema_id": schema_id, "schema": schema_def},
"schema_id": schema_id,
"schema": schema_def,
}
)

# If the transaction is for the endorser, but the schema has already been created,
# then we send back the schema since the transaction will fail to be created.
elif "signed_txn" not in schema_def:
return web.json_response(
{"sent": {"schema_id": schema_id, "schema": schema_def}}
)
else:
transaction_mgr = TransactionManager(context.profile)
try:
Expand All @@ -286,7 +298,12 @@ async def schemas_send_schema(request: web.BaseRequest):

await outbound_handler(transaction_request, connection_id=connection_id)

return web.json_response({"txn": transaction.serialize()})
return web.json_response(
{
"sent": {"schema_id": schema_id, "schema": schema_def},
"txn": transaction.serialize(),
}
)


@docs(
Expand Down
20 changes: 19 additions & 1 deletion aries_cloudagent/messaging/schemas/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ async def test_send_schema(self):
assert result == mock_response.return_value
mock_response.assert_called_once_with(
{
"sent": {
"schema_id": SCHEMA_ID,
"schema": {
"schema": "def",
"signed_txn": "...",
},
},
"schema_id": SCHEMA_ID,
"schema": {
"schema": "def",
Expand Down Expand Up @@ -116,7 +123,18 @@ async def test_send_schema_create_transaction_for_endorser(self):
)
result = await test_module.schemas_send_schema(self.request)
assert result == mock_response.return_value
mock_response.assert_called_once_with({"txn": {"...": "..."}})
mock_response.assert_called_once_with(
{
"sent": {
"schema_id": SCHEMA_ID,
"schema": {
"schema": "def",
"signed_txn": "...",
},
},
"txn": {"...": "..."},
}
)

async def test_send_schema_create_transaction_for_endorser_storage_x(self):
self.request.json = async_mock.CoroutineMock(
Expand Down
44 changes: 35 additions & 9 deletions aries_cloudagent/protocols/didexchange/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,24 @@ async def accept_response(
conn_rec = None
if response._thread:
# identify the request by the thread ID
try:
async with self.profile.session() as session:
async with self.profile.session() as session:
try:
conn_rec = await ConnRecord.retrieve_by_request_id(
session, response._thread_id
session,
response._thread_id,
their_role=ConnRecord.Role.RESPONDER.rfc23,
)
except StorageNotFoundError:
pass
except StorageNotFoundError:
pass
if not conn_rec:
try:
conn_rec = await ConnRecord.retrieve_by_request_id(
session,
response._thread_id,
their_role=ConnRecord.Role.RESPONDER.rfc160,
)
except StorageNotFoundError:
pass

if not conn_rec and receipt.sender_did:
# identify connection by the DID they used for us
Expand Down Expand Up @@ -809,12 +820,27 @@ async def accept_complete(
conn_rec = None

# identify the request by the thread ID
try:
async with self.profile.session() as session:
async with self.profile.session() as session:
try:
conn_rec = await ConnRecord.retrieve_by_request_id(
session, complete._thread_id
session,
complete._thread_id,
their_role=ConnRecord.Role.REQUESTER.rfc23,
)
except StorageNotFoundError:
except StorageNotFoundError:
pass

if not conn_rec:
try:
conn_rec = await ConnRecord.retrieve_by_request_id(
session,
complete._thread_id,
their_role=ConnRecord.Role.REQUESTER.rfc160,
)
except StorageNotFoundError:
pass

if not conn_rec:
raise DIDXManagerError(
"No corresponding connection request found",
error_code=ProblemReportReason.COMPLETE_NOT_ACCEPTED.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)
)

credential_ack_message = await credential_manager.send_credential_ack(
(_, credential_ack_message) = await credential_manager.send_credential_ack(
cred_ex_record
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ async def test_called_auto_store(self):
receive_credential=async_mock.CoroutineMock(),
store_credential=async_mock.CoroutineMock(),
send_credential_ack=async_mock.CoroutineMock(
return_value="credential_ack_message"
return_value=(
async_mock.CoroutineMock(),
async_mock.CoroutineMock(),
)
),
)
request_context.message = CredentialIssue()
Expand Down Expand Up @@ -78,7 +81,12 @@ async def test_called_auto_store_x(self):
store_credential=async_mock.CoroutineMock(
side_effect=test_module.IndyHolderError()
),
send_credential_ack=async_mock.CoroutineMock(),
send_credential_ack=async_mock.CoroutineMock(
return_value=(
async_mock.CoroutineMock(),
async_mock.CoroutineMock(),
)
),
)

request_context.message = CredentialIssue()
Expand Down
Loading

0 comments on commit 4868141

Please sign in to comment.