Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into refactor/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
amanji committed Apr 24, 2024
2 parents 8309867 + a50b81b commit 9f9dc94
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 99 deletions.
25 changes: 9 additions & 16 deletions aries_cloudagent/core/oob_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import logging
from typing import Any, Callable, Dict, List, Optional, cast
from typing import Any, Callable, Dict, List, Optional

from ..messaging.agent_message import AgentMessage
from ..connections.models.conn_record import ConnRecord
Expand Down Expand Up @@ -91,16 +91,18 @@ async def find_oob_target_for_outbound_message(
oob_record.their_service,
)

their_service = ServiceDecorator.deserialize(oob_record.their_service)
their_service = oob_record.their_service
if not their_service:
raise OobMessageProcessorError("Could not determine their service")

# Attach ~service decorator so other message can respond
message = json.loads(outbound_message.payload)
if not message.get("~service"):
if not message.get("~service") and oob_record.our_service:
LOGGER.debug(
"Setting our service on the message ~service %s",
oob_record.our_service,
)
message["~service"] = oob_record.our_service
message["~service"] = oob_record.our_service.serialize()

message["~thread"] = {
**message.get("~thread", {}),
Expand Down Expand Up @@ -256,24 +258,15 @@ async def find_oob_record_for_inbound_message(
)
return None

their_service = (
cast(
ServiceDecorator,
ServiceDecorator.deserialize(oob_record.their_service),
)
if oob_record.their_service
else None
)

# Verify the sender key is present in their service in our record
# If we don't have the sender verkey stored yet we can allow any key
if their_service and (
if oob_record.their_service and (
(
context.message_receipt.recipient_verkey
and (
not context.message_receipt.sender_verkey
or context.message_receipt.sender_verkey
not in their_service.recipient_keys
not in oob_record.their_service.recipient_keys
)
)
):
Expand Down Expand Up @@ -357,7 +350,7 @@ async def handle_message(
LOGGER.debug(
"Storing their service in oob record %s", their_service
)
oob_record.their_service = their_service.serialize()
oob_record.their_service = their_service

await oob_record.save(session)

Expand Down
54 changes: 27 additions & 27 deletions aries_cloudagent/core/tests/test_oob_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ async def asyncSetUp(self):
self.oob_record = mock.MagicMock(
connection_id="a-connection-id",
attach_thread_id="the-thid",
their_service={
"recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"],
"routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],
"serviceEndpoint": "http://their-service-endpoint.com",
},
their_service=ServiceDecorator(
recipient_keys=["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"],
routing_keys=["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],
endpoint="http://their-service-endpoint.com",
),
emit_event=mock.CoroutineMock(),
delete_record=mock.CoroutineMock(),
save=mock.CoroutineMock(),
Expand Down Expand Up @@ -121,16 +121,16 @@ async def test_find_oob_target_for_outbound_message(self):
invitation=mock.MagicMock(requests_attach=[]),
invi_msg_id="the-pthid",
our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx",
their_service={
"recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"],
"serviceEndpoint": "http://their-service-endpoint.com",
"routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],
},
our_service={
"recipientKeys": ["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"],
"serviceEndpoint": "http://our-service-endpoint.com",
"routingKeys": [],
},
their_service=ServiceDecorator(
recipient_keys=["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"],
endpoint="http://their-service-endpoint.com",
routing_keys=["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],
),
our_service=ServiceDecorator(
recipient_keys=["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"],
endpoint="http://our-service-endpoint.com",
routing_keys=[],
),
)

message = json.dumps({"~thread": {"thid": "the-thid"}})
Expand Down Expand Up @@ -196,16 +196,16 @@ async def test_find_oob_target_for_outbound_message_update_service_thread(self):
invitation=mock.MagicMock(requests_attach=[]),
invi_msg_id="the-pthid",
our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx",
their_service={
"recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"],
"serviceEndpoint": "http://their-service-endpoint.com",
"routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],
},
our_service={
"recipientKeys": ["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"],
"serviceEndpoint": "http://our-service-endpoint.com",
"routingKeys": [],
},
their_service=ServiceDecorator(
recipient_keys=["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"],
endpoint="http://their-service-endpoint.com",
routing_keys=["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],
),
our_service=ServiceDecorator(
recipient_keys=["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"],
endpoint="http://our-service-endpoint.com",
routing_keys=[],
),
)

with mock.patch.object(
Expand Down Expand Up @@ -303,7 +303,7 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob(
self.context.message_receipt = MessageReceipt(
thread_id="the-thid",
recipient_verkey="our-recipient-key",
sender_verkey=self.oob_record.their_service["recipientKeys"][0],
sender_verkey=self.oob_record.their_service.recipient_keys[0],
)

assert await self.oob_processor.find_oob_record_for_inbound_message(
Expand Down Expand Up @@ -728,7 +728,7 @@ async def test_handle_message_connectionless(self):
)

assert oob_record.attach_thread_id == "4a580490-a9d8-44f5-a3f6-14e0b8a219b0"
assert oob_record.their_service == {
assert oob_record.their_service.serialize() == {
"serviceEndpoint": "http://their-service-endpoint.com",
"recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"],
"routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],
Expand Down
12 changes: 6 additions & 6 deletions aries_cloudagent/revocation/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def validate_fields(self, data, **kwargs):
)


class PublishRevocationsSchemaAnoncreds(OpenAPISchema):
class PublishRevocationsSchema(OpenAPISchema):
"""Request and result schema for revocation publication API call."""

rrid2crid = fields.Dict(
Expand All @@ -293,7 +293,7 @@ class TxnOrPublishRevocationsResultSchema(OpenAPISchema):
"""Result schema for credential definition send request."""

sent = fields.Nested(
PublishRevocationsSchemaAnoncreds(),
PublishRevocationsSchema(),
required=False,
metadata={"definition": "Content sent"},
)
Expand Down Expand Up @@ -330,7 +330,7 @@ class ClearPendingRevocationsRequestSchema(OpenAPISchema):
)


class CredRevRecordResultSchemaAnoncreds(OpenAPISchema):
class CredRevRecordResultSchema(OpenAPISchema):
"""Result schema for credential revocation record request."""

result = fields.Nested(IssuerCredRevRecordSchema())
Expand Down Expand Up @@ -613,7 +613,7 @@ async def revoke(request: web.BaseRequest):


@docs(tags=["revocation"], summary="Publish pending revocations to ledger")
@request_schema(PublishRevocationsSchemaAnoncreds())
@request_schema(PublishRevocationsSchema())
@querystring_schema(CreateRevRegTxnForEndorserOptionSchema())
@querystring_schema(RevRegConnIdMatchInfoSchema())
@response_schema(TxnOrPublishRevocationsResultSchema(), 200, description="")
Expand Down Expand Up @@ -686,7 +686,7 @@ async def publish_revocations(request: web.BaseRequest):

@docs(tags=["revocation"], summary="Clear pending revocations")
@request_schema(ClearPendingRevocationsRequestSchema())
@response_schema(PublishRevocationsSchemaAnoncreds(), 200, description="")
@response_schema(PublishRevocationsSchema(), 200, description="")
async def clear_pending_revocations(request: web.BaseRequest):
"""Request handler for clearing pending revocations.
Expand Down Expand Up @@ -1070,7 +1070,7 @@ async def update_rev_reg_revoked_state(request: web.BaseRequest):
summary="Get credential revocation status",
)
@querystring_schema(CredRevRecordQueryStringSchema())
@response_schema(CredRevRecordResultSchemaAnoncreds(), 200, description="")
@response_schema(CredRevRecordResultSchema(), 200, description="")
async def get_cred_rev_record(request: web.BaseRequest):
"""Request handler to get credential revocation record.
Expand Down
56 changes: 6 additions & 50 deletions aries_cloudagent/revocation_anoncreds/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
WHOLE_NUM_VALIDATE,
UUIDFour,
)
from ..protocols.endorse_transaction.v1_0.models.transaction_record import (
TransactionRecordSchema,
)
from ..revocation.error import RevocationError
from ..revocation.models.issuer_rev_reg_record import (
IssuerRevRegRecord,
Expand Down Expand Up @@ -80,23 +77,6 @@ class RevRegResultSchemaAnoncreds(OpenAPISchema):
result = fields.Nested(IssuerRevRegRecordSchema())


class TxnOrRevRegResultSchema(OpenAPISchema):
"""Result schema for credential definition send request."""

sent = fields.Nested(
RevRegResultSchemaAnoncreds(),
required=False,
metadata={"definition": "Content sent"},
)
txn = fields.Nested(
TransactionRecordSchema(),
required=False,
metadata={
"description": "Revocation registry definition transaction to endorse"
},
)


class CredRevRecordQueryStringSchema(OpenAPISchema):
"""Parameters and validators for credential revocation record request."""

Expand Down Expand Up @@ -173,31 +153,7 @@ def validate_fields(self, data, **kwargs):
)


class ClearPendingRevocationsRequestSchema(OpenAPISchema):
"""Request schema for clear pending revocations API call."""

purge = fields.Dict(
required=False,
keys=fields.Str(metadata={"example": INDY_REV_REG_ID_EXAMPLE}),
values=fields.List(
fields.Str(
validate=INDY_CRED_REV_ID_VALIDATE,
metadata={
"description": "Credential revocation identifier",
"example": INDY_CRED_REV_ID_EXAMPLE,
},
)
),
metadata={
"description": (
"Credential revocation ids by revocation registry id: omit for all,"
" specify null or empty list for all pending per revocation registry"
)
},
)


class CredRevRecordResultSchema(OpenAPISchema):
class CredRevRecordResultSchemaAnoncreds(OpenAPISchema):
"""Result schema for credential revocation record request."""

result = fields.Nested(IssuerCredRevRecordSchemaAnoncreds())
Expand Down Expand Up @@ -386,7 +342,7 @@ class PublishRevocationsOptions(OpenAPISchema):
)


class PublishRevocationsSchema(OpenAPISchema):
class PublishRevocationsSchemaAnoncreds(OpenAPISchema):
"""Request and result schema for revocation publication API call."""

rrid2crid = fields.Dict(
Expand All @@ -406,7 +362,7 @@ class PublishRevocationsSchema(OpenAPISchema):
options = fields.Nested(PublishRevocationsOptions())


class PublishRevocationsResultSchema(OpenAPISchema):
class PublishRevocationsResultSchemaAnoncreds(OpenAPISchema):
"""Result schema for credential definition send request."""

rrid2crid = fields.Dict(
Expand Down Expand Up @@ -554,8 +510,8 @@ async def revoke(request: web.BaseRequest):


@docs(tags=[TAG_TITLE], summary="Publish pending revocations to ledger")
@request_schema(PublishRevocationsSchema())
@response_schema(PublishRevocationsResultSchema(), 200, description="")
@request_schema(PublishRevocationsSchemaAnoncreds())
@response_schema(PublishRevocationsResultSchemaAnoncreds(), 200, description="")
async def publish_revocations(request: web.BaseRequest):
"""Request handler for publishing pending revocations to the ledger.
Expand Down Expand Up @@ -988,7 +944,7 @@ async def update_rev_reg_revoked_state(request: web.BaseRequest):
summary="Get credential revocation status",
)
@querystring_schema(CredRevRecordQueryStringSchema())
@response_schema(CredRevRecordResultSchema(), 200, description="")
@response_schema(CredRevRecordResultSchemaAnoncreds(), 200, description="")
async def get_cred_rev_record(request: web.BaseRequest):
"""Request handler to get credential revocation record.
Expand Down

0 comments on commit 9f9dc94

Please sign in to comment.