diff --git a/dexa_protocol/v1_0/handlers/accept_dda_handler.py b/dexa_protocol/v1_0/handlers/accept_dda_handler.py index f28764a..c5cde89 100644 --- a/dexa_protocol/v1_0/handlers/accept_dda_handler.py +++ b/dexa_protocol/v1_0/handlers/accept_dda_handler.py @@ -1,10 +1,10 @@ from aries_cloudagent.messaging.base_handler import ( BaseHandler, BaseResponder, - RequestContext + RequestContext, ) +from dexa_protocol.v1_0.messages.negotiation.accept_dda import AcceptDDAMessage from dexa_sdk.managers.dexa_manager import DexaManager -from ..messages.negotiation.accept_dda import AcceptDDAMessage class AcceptDDAMessageHandler(BaseHandler): @@ -19,7 +19,4 @@ async def handle(self, context: RequestContext, responder: BaseResponder): mgr = DexaManager(context) # Process the message. - await mgr.process_accept_dda_message( - context.message, - context.message_receipt - ) + await mgr.process_accept_dda_message(context.message, context.message_receipt) diff --git a/dexa_protocol/v1_0/handlers/dda_negotiation_receipt_handler.py b/dexa_protocol/v1_0/handlers/dda_negotiation_receipt_handler.py index a3ff4fd..5da3933 100644 --- a/dexa_protocol/v1_0/handlers/dda_negotiation_receipt_handler.py +++ b/dexa_protocol/v1_0/handlers/dda_negotiation_receipt_handler.py @@ -1,12 +1,12 @@ from aries_cloudagent.messaging.base_handler import ( BaseHandler, BaseResponder, - RequestContext + RequestContext, ) -from dexa_sdk.managers.dexa_manager import DexaManager -from ..messages.negotiation.dda_negotiation_receipt import ( - DDANegotiationReceiptMessage +from dexa_protocol.v1_0.messages.negotiation.dda_negotiation_receipt import ( + DDANegotiationReceiptMessage, ) +from dexa_sdk.managers.dexa_manager import DexaManager class DDANegotiationReceiptHandler(BaseHandler): @@ -22,6 +22,5 @@ async def handle(self, context: RequestContext, responder: BaseResponder): # Process dda negotiation receipt message. await mgr.process_dda_negotiation_receipt_message( - context.message, - context.message_receipt + context.message, context.message_receipt ) diff --git a/dexa_protocol/v1_0/handlers/deactivate_dda_handler.py b/dexa_protocol/v1_0/handlers/deactivate_dda_handler.py new file mode 100644 index 0000000..63c4acf --- /dev/null +++ b/dexa_protocol/v1_0/handlers/deactivate_dda_handler.py @@ -0,0 +1,24 @@ +from aries_cloudagent.messaging.base_handler import ( + BaseHandler, + BaseResponder, + RequestContext, +) +from dexa_protocol.v1_0.messages.deactivate_dda import DeactivateDDAMessage +from dexa_sdk.managers.dexa_manager import DexaManager + + +class DeactivateDDAMessageHandler(BaseHandler): + """Deactivate DDA message handler logic""" + + async def handle(self, context: RequestContext, responder: BaseResponder): + """Handle function""" + + assert isinstance(context.message, DeactivateDDAMessage) + + # Initialise the manager. + mgr = DexaManager(context) + + # Process the message. + await mgr.process_deactivate_dda_message( + context.message, context.message_receipt + ) diff --git a/dexa_protocol/v1_0/handlers/delete_dda_handler.py b/dexa_protocol/v1_0/handlers/delete_dda_handler.py index 33ac414..cecb670 100644 --- a/dexa_protocol/v1_0/handlers/delete_dda_handler.py +++ b/dexa_protocol/v1_0/handlers/delete_dda_handler.py @@ -1,10 +1,10 @@ from aries_cloudagent.messaging.base_handler import ( BaseHandler, BaseResponder, - RequestContext + RequestContext, ) +from dexa_protocol.v1_0.messages.marketplace.delete_dda import DeleteDDAMessage from dexa_sdk.managers.dexa_manager import DexaManager -from ..messages.marketplace.delete_dda import DeleteDDAMessage class DeleteDDAMessageHandler(BaseHandler): @@ -19,7 +19,4 @@ async def handle(self, context: RequestContext, responder: BaseResponder): mgr = DexaManager(context) # Process publish dda request message. - await mgr.process_delete_dda_message( - context.message, - context.message_receipt - ) + await mgr.process_delete_dda_message(context.message, context.message_receipt) diff --git a/dexa_protocol/v1_0/handlers/list_marketplace_dda_handler.py b/dexa_protocol/v1_0/handlers/list_marketplace_dda_handler.py index b623382..3f98abe 100644 --- a/dexa_protocol/v1_0/handlers/list_marketplace_dda_handler.py +++ b/dexa_protocol/v1_0/handlers/list_marketplace_dda_handler.py @@ -1,13 +1,16 @@ """Basic message handler.""" import json -from loguru import logger + from aries_cloudagent.messaging.base_handler import ( BaseHandler, BaseResponder, RequestContext, ) +from dexa_protocol.v1_0.messages.marketplace.list_marketplace_dda import ( + ListMarketplaceDDAMessage, +) from dexa_sdk.managers.dexa_manager import DexaManager -from ..messages.marketplace.list_marketplace_dda import ListMarketplaceDDAMessage +from loguru import logger class ListMarketplaceDDAMessageHandler(BaseHandler): @@ -33,6 +36,5 @@ async def handle(self, context: RequestContext, responder: BaseResponder): # Process the message await mgr.process_list_marketplace_dda_message( - context.message, - context.message_receipt + context.message, context.message_receipt ) diff --git a/dexa_protocol/v1_0/handlers/offer_dda_handler.py b/dexa_protocol/v1_0/handlers/offer_dda_handler.py index 37004f3..8e05898 100644 --- a/dexa_protocol/v1_0/handlers/offer_dda_handler.py +++ b/dexa_protocol/v1_0/handlers/offer_dda_handler.py @@ -1,10 +1,10 @@ from aries_cloudagent.messaging.base_handler import ( BaseHandler, BaseResponder, - RequestContext + RequestContext, ) +from dexa_protocol.v1_0.messages.negotiation.offer_dda import OfferDDAMessage from dexa_sdk.managers.dexa_manager import DexaManager -from ..messages.negotiation.offer_dda import OfferDDAMessage class OfferDDAMessageHandler(BaseHandler): @@ -19,7 +19,4 @@ async def handle(self, context: RequestContext, responder: BaseResponder): mgr = DexaManager(context) # Process the message. - await mgr.process_offer_dda_message( - context.message, - context.message_receipt - ) + await mgr.process_offer_dda_message(context.message, context.message_receipt) diff --git a/dexa_protocol/v1_0/handlers/publish_dda_handler.py b/dexa_protocol/v1_0/handlers/publish_dda_handler.py index 07bf24a..a572295 100644 --- a/dexa_protocol/v1_0/handlers/publish_dda_handler.py +++ b/dexa_protocol/v1_0/handlers/publish_dda_handler.py @@ -1,10 +1,10 @@ from aries_cloudagent.messaging.base_handler import ( BaseHandler, BaseResponder, - RequestContext + RequestContext, ) +from dexa_protocol.v1_0.messages.marketplace.publish_dda import PublishDDAMessage from dexa_sdk.managers.dexa_manager import DexaManager -from ..messages.marketplace.publish_dda import PublishDDAMessage class PublishDDAMessageHandler(BaseHandler): @@ -20,6 +20,5 @@ async def handle(self, context: RequestContext, responder: BaseResponder): # Process publish dda request message. await mgr.process_publish_dda_request_message( - context.message, - context.message_receipt + context.message, context.message_receipt ) diff --git a/dexa_protocol/v1_0/handlers/request_dda_handler.py b/dexa_protocol/v1_0/handlers/request_dda_handler.py index 9072687..ae7275b 100644 --- a/dexa_protocol/v1_0/handlers/request_dda_handler.py +++ b/dexa_protocol/v1_0/handlers/request_dda_handler.py @@ -1,10 +1,10 @@ from aries_cloudagent.messaging.base_handler import ( BaseHandler, BaseResponder, - RequestContext + RequestContext, ) +from dexa_protocol.v1_0.messages.negotiation.request_dda import RequestDDAMessage from dexa_sdk.managers.dexa_manager import DexaManager -from ..messages.negotiation.request_dda import RequestDDAMessage class RequestDDAMessageHandler(BaseHandler): @@ -19,7 +19,4 @@ async def handle(self, context: RequestContext, responder: BaseResponder): mgr = DexaManager(context) # Process publish dda request message. - await mgr.process_request_dda_message( - context.message, - context.message_receipt - ) + await mgr.process_request_dda_message(context.message, context.message_receipt) diff --git a/dexa_protocol/v1_0/message_types.py b/dexa_protocol/v1_0/message_types.py index 4f2d2c9..2f9f132 100644 --- a/dexa_protocol/v1_0/message_types.py +++ b/dexa_protocol/v1_0/message_types.py @@ -17,6 +17,7 @@ OFFER_DDA = f"dda-negotiation/1.0/offer-dda" ACCEPT_DDA = f"dda-negotiation/1.0/accept-dda" NEGOTIATION_RECEIPT = f"dda-negotiation/1.0/receipt" +DEACTIVATE_DDA = f"dda/1.0/deactivate" PROTOCOL_PACKAGE = "dexa_protocol.v1_0" @@ -31,6 +32,7 @@ REQUEST_DDA: f"{PROTOCOL_PACKAGE}.messages.negotiation.request_dda.RequestDDAMessage", OFFER_DDA: f"{PROTOCOL_PACKAGE}.messages.negotiation.offer_dda.OfferDDAMessage", ACCEPT_DDA: f"{PROTOCOL_PACKAGE}.messages.negotiation.accept_dda.AcceptDDAMessage", - NEGOTIATION_RECEIPT: f"{PROTOCOL_PACKAGE}.messages.negotiation.dda_negotiation_receipt.DDANegotiationReceiptMessage" + NEGOTIATION_RECEIPT: f"{PROTOCOL_PACKAGE}.messages.negotiation.dda_negotiation_receipt.DDANegotiationReceiptMessage", + DEACTIVATE_DDA: f"{PROTOCOL_PACKAGE}.messages.deactivate_dda.DeactivateDDAMessage", } ) diff --git a/dexa_protocol/v1_0/messages/deactivate_dda.py b/dexa_protocol/v1_0/messages/deactivate_dda.py new file mode 100644 index 0000000..ff26ec7 --- /dev/null +++ b/dexa_protocol/v1_0/messages/deactivate_dda.py @@ -0,0 +1,31 @@ +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema +from dexa_protocol.v1_0.message_types import DEACTIVATE_DDA, PROTOCOL_PACKAGE +from dexa_protocol.v1_0.models.deactivate_dda_model import ( + DeactivateDDABodyModel, + DeactivateDDABodyModelSchema, +) +from marshmallow import EXCLUDE, fields + +HANDLER_CLASS = ( + f"{PROTOCOL_PACKAGE}.handlers.deactivate_dda_handler.DeactivateDDAMessageHandler" +) + + +class DeactivateDDAMessage(AgentMessage): + class Meta: + handler_class = HANDLER_CLASS + message_type = DEACTIVATE_DDA + schema_class = "DeactivateDDAMessageSchema" + + def __init__(self, *, body: DeactivateDDABodyModel, **kwargs): + super().__init__(**kwargs) + + self.body = body + + +class DeactivateDDAMessageSchema(AgentMessageSchema): + class Meta: + model_class = DeactivateDDAMessage + unknown = EXCLUDE + + body = fields.Nested(DeactivateDDABodyModelSchema) diff --git a/dexa_protocol/v1_0/messages/marketplace/delete_dda.py b/dexa_protocol/v1_0/messages/marketplace/delete_dda.py index c512c27..bec28fc 100644 --- a/dexa_protocol/v1_0/messages/marketplace/delete_dda.py +++ b/dexa_protocol/v1_0/messages/marketplace/delete_dda.py @@ -1,12 +1,14 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema -from marshmallow import EXCLUDE, fields -from ...message_types import PROTOCOL_PACKAGE, DELETE_DDA -from ...models.delete_dda_model import ( +from dexa_protocol.v1_0.message_types import DELETE_DDA, PROTOCOL_PACKAGE +from dexa_protocol.v1_0.models.delete_dda_model import ( DeleteDDAModel, - DeleteDDAModelSchema + DeleteDDAModelSchema, ) +from marshmallow import EXCLUDE, fields -HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.delete_dda_handler.DeleteDDAMessageHandler" +HANDLER_CLASS = ( + f"{PROTOCOL_PACKAGE}.handlers.delete_dda_handler.DeleteDDAMessageHandler" +) class DeleteDDAMessage(AgentMessage): diff --git a/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda.py b/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda.py index e65ea39..c5fb61a 100644 --- a/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda.py +++ b/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda.py @@ -1,11 +1,8 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema +from dexa_protocol.v1_0.message_types import LIST_MARKETPLACE_DDA, PROTOCOL_PACKAGE from marshmallow import EXCLUDE -from ...message_types import PROTOCOL_PACKAGE, LIST_MARKETPLACE_DDA - -HANDLER_CLASS = ( - f"{PROTOCOL_PACKAGE}.handlers.list_marketplace_dda_handler.ListMarketplaceDDAMessageHandler" -) +HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.list_marketplace_dda_handler.ListMarketplaceDDAMessageHandler" class ListMarketplaceDDAMessage(AgentMessage): @@ -29,7 +26,6 @@ def __init__(self, **kwargs): class ListMarketplaceDDAMessageSchema(AgentMessageSchema): - class Meta: # Model class model_class = ListMarketplaceDDAMessage diff --git a/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda_response.py b/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda_response.py index 45774ff..cc524dc 100644 --- a/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda_response.py +++ b/dexa_protocol/v1_0/messages/marketplace/list_marketplace_dda_response.py @@ -1,10 +1,13 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema -from marshmallow import EXCLUDE, fields -from ...message_types import PROTOCOL_PACKAGE, LIST_MARKETPLACE_DDA_RESPONSE -from ...models.list_marketplace_dda_response_model import ( +from dexa_protocol.v1_0.message_types import ( + LIST_MARKETPLACE_DDA_RESPONSE, + PROTOCOL_PACKAGE, +) +from dexa_protocol.v1_0.models.list_marketplace_dda_response_model import ( ListMarketplaceDDAResponseBody, - ListMarketplaceDDAResponseBodySchema + ListMarketplaceDDAResponseBodySchema, ) +from marshmallow import EXCLUDE, fields HANDLER_CLASS = ( f"{PROTOCOL_PACKAGE}.handlers.list_marketplace_dda_response_handler" @@ -36,7 +39,6 @@ def __init__(self, body: ListMarketplaceDDAResponseBody, **kwargs): class ListMarketplaceDDAResponseMessageSchema(AgentMessageSchema): - class Meta: # Model class model_class = ListMarketplaceDDAResponseMessage diff --git a/dexa_protocol/v1_0/messages/marketplace/publish_dda.py b/dexa_protocol/v1_0/messages/marketplace/publish_dda.py index b1b9935..45d5f0a 100644 --- a/dexa_protocol/v1_0/messages/marketplace/publish_dda.py +++ b/dexa_protocol/v1_0/messages/marketplace/publish_dda.py @@ -1,12 +1,14 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema -from marshmallow import EXCLUDE, fields -from ...message_types import PROTOCOL_PACKAGE, PUBLISH_DDA -from ...models.publish_dda_model import ( +from dexa_protocol.v1_0.message_types import PROTOCOL_PACKAGE, PUBLISH_DDA +from dexa_protocol.v1_0.models.publish_dda_model import ( PublishDDAModel, - PublishDDAModelSchema + PublishDDAModelSchema, ) +from marshmallow import EXCLUDE, fields -HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.publish_dda_handler.PublishDDAMessageHandler" +HANDLER_CLASS = ( + f"{PROTOCOL_PACKAGE}.handlers.publish_dda_handler.PublishDDAMessageHandler" +) class PublishDDAMessage(AgentMessage): @@ -32,7 +34,6 @@ def __init__(self, *, body: PublishDDAModel, **kwargs): class PublishDDAMessageSchema(AgentMessageSchema): - class Meta: # Model class model_class = PublishDDAMessage diff --git a/dexa_protocol/v1_0/messages/negotiation/accept_dda.py b/dexa_protocol/v1_0/messages/negotiation/accept_dda.py index 346f6ec..30513cb 100644 --- a/dexa_protocol/v1_0/messages/negotiation/accept_dda.py +++ b/dexa_protocol/v1_0/messages/negotiation/accept_dda.py @@ -1,11 +1,14 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema -from marshmallow import EXCLUDE, fields -from ...message_types import PROTOCOL_PACKAGE, ACCEPT_DDA -from ...models.accept_dda_model import ( +from dexa_protocol.v1_0.message_types import ACCEPT_DDA, PROTOCOL_PACKAGE +from dexa_protocol.v1_0.models.accept_dda_model import ( AcceptDDAMessageBodyModel, - AcceptDDAMessageBodyModelSchema + AcceptDDAMessageBodyModelSchema, +) +from marshmallow import EXCLUDE, fields + +HANDLER_CLASS = ( + f"{PROTOCOL_PACKAGE}.handlers.accept_dda_handler.AcceptDDAMessageHandler" ) -HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.accept_dda_handler.AcceptDDAMessageHandler" class AcceptDDAMessage(AgentMessage): diff --git a/dexa_protocol/v1_0/messages/negotiation/dda_negotiation_receipt.py b/dexa_protocol/v1_0/messages/negotiation/dda_negotiation_receipt.py index 10409ae..8396ee1 100644 --- a/dexa_protocol/v1_0/messages/negotiation/dda_negotiation_receipt.py +++ b/dexa_protocol/v1_0/messages/negotiation/dda_negotiation_receipt.py @@ -1,14 +1,12 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema -from marshmallow import EXCLUDE, fields -from ...message_types import PROTOCOL_PACKAGE, NEGOTIATION_RECEIPT -from ...models.dda_negotiation_receipt_model import ( +from dexa_protocol.v1_0.message_types import NEGOTIATION_RECEIPT, PROTOCOL_PACKAGE +from dexa_protocol.v1_0.models.dda_negotiation_receipt_model import ( DDANegotiationReceiptBodyModel, - DDANegotiationReceiptBodyModelSchema + DDANegotiationReceiptBodyModelSchema, ) +from marshmallow import EXCLUDE, fields -HANDLER_CLASS = ( - f"{PROTOCOL_PACKAGE}.handlers.dda_negotiation_receipt_handler.DDANegotiationReceiptHandler" -) +HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.dda_negotiation_receipt_handler.DDANegotiationReceiptHandler" class DDANegotiationReceiptMessage(AgentMessage): diff --git a/dexa_protocol/v1_0/messages/negotiation/delete_dda.py b/dexa_protocol/v1_0/messages/negotiation/delete_dda.py deleted file mode 100644 index e69de29..0000000 diff --git a/dexa_protocol/v1_0/messages/negotiation/offer_dda.py b/dexa_protocol/v1_0/messages/negotiation/offer_dda.py index 4a0b24b..a53368f 100644 --- a/dexa_protocol/v1_0/messages/negotiation/offer_dda.py +++ b/dexa_protocol/v1_0/messages/negotiation/offer_dda.py @@ -1,10 +1,10 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema -from marshmallow import EXCLUDE, fields -from ...message_types import PROTOCOL_PACKAGE, OFFER_DDA -from ...models.offer_dda_model import ( +from dexa_protocol.v1_0.message_types import OFFER_DDA, PROTOCOL_PACKAGE +from dexa_protocol.v1_0.models.offer_dda_model import ( OfferDDAMessageBodyModel, - OfferDDAMessageBodyModelSchema + OfferDDAMessageBodyModelSchema, ) +from marshmallow import EXCLUDE, fields HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.offer_dda_handler.OfferDDAMessageHandler" diff --git a/dexa_protocol/v1_0/messages/negotiation/request_dda.py b/dexa_protocol/v1_0/messages/negotiation/request_dda.py index 7f26640..9348221 100644 --- a/dexa_protocol/v1_0/messages/negotiation/request_dda.py +++ b/dexa_protocol/v1_0/messages/negotiation/request_dda.py @@ -1,9 +1,14 @@ from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema +from dexa_protocol.v1_0.message_types import PROTOCOL_PACKAGE, REQUEST_DDA +from dexa_protocol.v1_0.models.request_dda_model import ( + RequestDDAModel, + RequestDDAModelSchema, +) from marshmallow import EXCLUDE, fields -from ...message_types import PROTOCOL_PACKAGE, REQUEST_DDA -from ...models.request_dda_model import RequestDDAModel, RequestDDAModelSchema -HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.request_dda_handler.RequestDDAMessageHandler" +HANDLER_CLASS = ( + f"{PROTOCOL_PACKAGE}.handlers.request_dda_handler.RequestDDAMessageHandler" +) class RequestDDAMessage(AgentMessage): diff --git a/dexa_protocol/v1_0/models/accept_dda_model.py b/dexa_protocol/v1_0/models/accept_dda_model.py index 6a53874..2d30a33 100644 --- a/dexa_protocol/v1_0/models/accept_dda_model.py +++ b/dexa_protocol/v1_0/models/accept_dda_model.py @@ -1,9 +1,9 @@ from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema -from marshmallow import EXCLUDE, fields from dexa_sdk.agreements.dda.v1_0.models.dda_instance_models import ( DataDisclosureAgreementInstanceModel, - DataDisclosureAgreementInstanceSchema + DataDisclosureAgreementInstanceSchema, ) +from marshmallow import EXCLUDE, fields class AcceptDDAMessageBodyModel(BaseModel): @@ -13,12 +13,7 @@ class Meta: # Schema class schema_class = "AcceptDDAMessageBodyModelSchema" - def __init__( - self, - *, - dda: DataDisclosureAgreementInstanceModel, - **kwargs - ): + def __init__(self, *, dda: DataDisclosureAgreementInstanceModel, **kwargs): """Initialise accept DDA message body model. Args: diff --git a/dexa_protocol/v1_0/models/deactivate_dda_model.py b/dexa_protocol/v1_0/models/deactivate_dda_model.py new file mode 100644 index 0000000..7637014 --- /dev/null +++ b/dexa_protocol/v1_0/models/deactivate_dda_model.py @@ -0,0 +1,20 @@ +from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema +from marshmallow import EXCLUDE, fields + + +class DeactivateDDABodyModel(BaseModel): + class Meta: + schema_class = "DeactivateDDABodyModelSchema" + + def __init__(self, *, instance_id: str, **kwargs): + super().__init__(**kwargs) + + self.instance_id = instance_id + + +class DeactivateDDABodyModelSchema(BaseModelSchema): + class Meta: + model_class = DeactivateDDABodyModel + unknown = EXCLUDE + + instance_id = fields.Str() diff --git a/dexa_protocol/v1_0/models/list_marketplace_dda_response_model.py b/dexa_protocol/v1_0/models/list_marketplace_dda_response_model.py index 77ea696..fbfeaab 100644 --- a/dexa_protocol/v1_0/models/list_marketplace_dda_response_model.py +++ b/dexa_protocol/v1_0/models/list_marketplace_dda_response_model.py @@ -1,9 +1,7 @@ import typing -from aries_cloudagent.messaging.models.base import ( - BaseModel, - BaseModelSchema -) -from marshmallow import fields, EXCLUDE + +from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema +from marshmallow import EXCLUDE, fields class ListMarketplaceDDAResponseModel(BaseModel): @@ -56,10 +54,7 @@ class Meta: schema_class = "ListMarketplaceDDAResponseBodySchema" def __init__( - self, - *, - results: typing.List[ListMarketplaceDDAResponseModel], - **kwargs + self, *, results: typing.List[ListMarketplaceDDAResponseModel], **kwargs ): super().__init__(**kwargs) @@ -75,8 +70,4 @@ class Meta: # Unknown fields are excluded unknown = EXCLUDE - results = fields.List( - fields.Nested( - ListMarketplaceDDAResponseModelSchema - ) - ) + results = fields.List(fields.Nested(ListMarketplaceDDAResponseModelSchema)) diff --git a/dexa_protocol/v1_0/models/offer_dda_model.py b/dexa_protocol/v1_0/models/offer_dda_model.py index e2d4acc..55f47d5 100644 --- a/dexa_protocol/v1_0/models/offer_dda_model.py +++ b/dexa_protocol/v1_0/models/offer_dda_model.py @@ -1,9 +1,9 @@ from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema -from marshmallow import EXCLUDE, fields from dexa_sdk.agreements.dda.v1_0.models.dda_instance_models import ( DataDisclosureAgreementInstanceModel, - DataDisclosureAgreementInstanceSchema + DataDisclosureAgreementInstanceSchema, ) +from marshmallow import EXCLUDE, fields class CustomerIdentificationModel(BaseModel): @@ -78,4 +78,6 @@ class Meta: dda = fields.Nested(DataDisclosureAgreementInstanceSchema) # Customer identification data. - customer_identification = fields.Nested(CustomerIdentificationModelSchema, required=False) + customer_identification = fields.Nested( + CustomerIdentificationModelSchema, required=False + ) diff --git a/dexa_protocol/v1_0/models/publish_dda_model.py b/dexa_protocol/v1_0/models/publish_dda_model.py index c90f595..9ae2288 100644 --- a/dexa_protocol/v1_0/models/publish_dda_model.py +++ b/dexa_protocol/v1_0/models/publish_dda_model.py @@ -1,26 +1,19 @@ -from aries_cloudagent.messaging.models.base import ( - BaseModel, - BaseModelSchema -) -from marshmallow import EXCLUDE, fields +from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema from dexa_sdk.agreements.dda.v1_0.models.dda_models import ( DataDisclosureAgreementModel, - DataDisclosureAgreementSchema + DataDisclosureAgreementSchema, ) +from marshmallow import EXCLUDE, fields class PublishDDAModel(BaseModel): """Publish DDA model""" + class Meta: # Schema class schema_class = "PublishDDAModelSchema" - def __init__( - self, - *, - dda: DataDisclosureAgreementModel, - connection_url: str - ): + def __init__(self, *, dda: DataDisclosureAgreementModel, connection_url: str): # Call the parent constructor super().__init__() diff --git a/dexa_protocol/v1_0/routes/dda_routes.py b/dexa_protocol/v1_0/routes/dda_routes.py index 128cd0b..9e28b07 100644 --- a/dexa_protocol/v1_0/routes/dda_routes.py +++ b/dexa_protocol/v1_0/routes/dda_routes.py @@ -1,29 +1,25 @@ from aiohttp import web -from aiohttp_apispec import ( - docs, - request_schema, - querystring_schema, - match_info_schema -) -from dexa_sdk.managers.dexa_manager import DexaManager -from dexa_sdk.utils import clean_and_get_field_from_dict -from mydata_did.v1_0.utils.util import str_to_bool -from mydata_did.v1_0.routes.maps.tag_maps import ( - TAGS_DATA_AGREEMENT_AUDITOR_FUNCTIONS_LABEL -) -from .maps.tag_maps import TAGS_DDA_LABEL -from .openapi.schemas import ( +from aiohttp_apispec import docs, match_info_schema, querystring_schema, request_schema +from dexa_protocol.v1_0.routes.maps.tag_maps import TAGS_DDA_LABEL +from dexa_protocol.v1_0.routes.openapi.schemas import ( CreateDataDisclosureAgreementTemplateRequestSchema, CreateDDATemplateRequestQueryStringSchema, + DDATemplateMatchInfoSchema, + DeactivateDDAMatchInfoSchema, + ListDDAPublishedInMarketplaceQueryStringSchema, PublishDDAToMarketplaceMatchInfoSchema, + QueryDDAInstancesQueryStringSchema, QueryDDATemplateQueryStringSchema, + RequestDDAFromDataSourceMatchInfoSchema, UpdateDDATemplateQueryStringSchema, - DDATemplateMatchInfoSchema, UpdateDDATemplateRequestSchema, - ListDDAPublishedInMarketplaceQueryStringSchema, - RequestDDAFromDataSourceMatchInfoSchema, - QueryDDAInstancesQueryStringSchema ) +from dexa_sdk.managers.dexa_manager import DexaManager +from dexa_sdk.utils import clean_and_get_field_from_dict +from mydata_did.v1_0.routes.maps.tag_maps import ( + TAGS_DATA_AGREEMENT_AUDITOR_FUNCTIONS_LABEL, +) +from mydata_did.v1_0.utils.util import str_to_bool @docs(tags=[TAGS_DDA_LABEL], summary="Create a data disclosure agreement template.") @@ -43,15 +39,16 @@ async def create_data_disclosure_agreement_handler(request: web.BaseRequest): dda = await request.json() # Fetch query string params - publish_flag = str_to_bool(clean_and_get_field_from_dict(request.query, "publish_flag")) + publish_flag = str_to_bool( + clean_and_get_field_from_dict(request.query, "publish_flag") + ) # Initialise DEXA manager manager = DexaManager(context) # Create and store DDA in wallet. record = await manager.create_and_store_dda_template_in_wallet( - dda, - publish_flag=publish_flag + dda, publish_flag=publish_flag ) return web.json_response(record.serialize()) @@ -75,7 +72,9 @@ async def query_dda_handler(request: web.BaseRequest): industry_sector = clean_and_get_field_from_dict(request.query, "industry_sector") publish_flag = clean_and_get_field_from_dict(request.query, "publish_flag") delete_flag = clean_and_get_field_from_dict(request.query, "delete_flag") - latest_version_flag = clean_and_get_field_from_dict(request.query, "latest_version_flag") + latest_version_flag = clean_and_get_field_from_dict( + request.query, "latest_version_flag" + ) page = clean_and_get_field_from_dict(request.query, "page") page = int(page) if page is not None else page page_size = clean_and_get_field_from_dict(request.query, "page_size") @@ -93,7 +92,7 @@ async def query_dda_handler(request: web.BaseRequest): delete_flag=delete_flag, latest_version_flag=latest_version_flag, page=page if page else 1, - page_size=page_size if page_size else 10 + page_size=page_size if page_size else 10, ) return web.json_response(paginationResult._asdict()) @@ -123,9 +122,7 @@ async def update_dda_template_handler(request: web.BaseRequest): manager = DexaManager(context=context) record = await manager.update_dda_template_in_wallet( - template_id=template_id, - dda=dda, - publish_flag=publish_flag + template_id=template_id, dda=dda, publish_flag=publish_flag ) return web.json_response(record.serialize(), status=200) @@ -145,9 +142,7 @@ async def delete_dda_template_handler(request: web.BaseRequest): # Initialise MyData DID Manager manager = DexaManager(context=context) - await manager.delete_dda_template_in_wallet( - template_id - ) + await manager.delete_dda_template_in_wallet(template_id) return web.json_response({}, status=204) @@ -166,9 +161,7 @@ async def publish_dda_template_handler(request: web.BaseRequest): # Initialise MyData DID Manager manager = DexaManager(context=context) - await manager.publish_dda_template_wallet( - template_id - ) + await manager.publish_dda_template_wallet(template_id) return web.json_response({}, status=204) @@ -188,10 +181,7 @@ async def publish_dda_to_marketplace_handler(request: web.BaseRequest): # Initiatlise MyData DID manager mgr = DexaManager(context) - record = await mgr.publish_dda_template_to_marketplace( - connection_id, - template_id - ) + record = await mgr.publish_dda_template_to_marketplace(connection_id, template_id) return web.json_response(record.serialize()) @@ -215,8 +205,7 @@ async def list_dda_published_in_marketplace(request: web.BaseRequest): # Paginated list of published DDAs pagination_result = await mgr.list_dda_published_in_marketplace( - page if page else 1, - page_size if page_size else 10 + page if page else 1, page_size if page_size else 10 ) return web.json_response(pagination_result._asdict()) @@ -242,17 +231,12 @@ async def request_dda_offer_from_ds_handler(request: web.BaseRequest): mgr = DexaManager(context) # Request DDA from DS. - await mgr.request_dda_offer_from_ds( - connection_id, - template_id - ) + await mgr.request_dda_offer_from_ds(connection_id, template_id) return web.json_response({}, status=204) -@docs( - tags=[TAGS_DATA_AGREEMENT_AUDITOR_FUNCTIONS_LABEL], summary="Query DDA instances" -) +@docs(tags=[TAGS_DATA_AGREEMENT_AUDITOR_FUNCTIONS_LABEL], summary="Query DDA instances") @querystring_schema(QueryDDAInstancesQueryStringSchema()) async def query_dda_instances_handler(request: web.BaseRequest): """ @@ -281,7 +265,31 @@ async def query_dda_instances_handler(request: web.BaseRequest): template_version, connection_id, page if page else 1, - page_size if page_size else 10 + page_size if page_size else 10, ) return web.json_response(paginationResult._asdict()) + + +@docs(tags=[TAGS_DDA_LABEL], summary="Deactivate DDA.") +@match_info_schema(DeactivateDDAMatchInfoSchema()) +async def deactivate_dda_instance_handler(request: web.BaseRequest): + """Deactivate DDA instance. + + Args: + request (web.BaseRequest): Request. + """ + + # Context + context = request.app["request_context"] + + # Path parameters + instance_id = request.match_info["instance_id"] + + # Initialise manager. + mgr = DexaManager(context) + + # Call the function. + await mgr.send_deactivate_dda_message(instance_id) + + return web.json_response({}, status=204) diff --git a/dexa_protocol/v1_0/routes/maps/route_maps.py b/dexa_protocol/v1_0/routes/maps/route_maps.py index 1a7eaf7..aee30f7 100644 --- a/dexa_protocol/v1_0/routes/maps/route_maps.py +++ b/dexa_protocol/v1_0/routes/maps/route_maps.py @@ -1,21 +1,21 @@ from aiohttp import web -from ..dda_routes import ( +from dexa_protocol.v1_0.routes.dda_routes import ( create_data_disclosure_agreement_handler, - query_dda_handler, - update_dda_template_handler, + deactivate_dda_instance_handler, delete_dda_template_handler, + list_dda_published_in_marketplace, publish_dda_template_handler, publish_dda_to_marketplace_handler, - list_dda_published_in_marketplace, + query_dda_handler, + query_dda_instances_handler, request_dda_offer_from_ds_handler, - query_dda_instances_handler + update_dda_template_handler, ) - -from ..marketplace_routes import ( +from dexa_protocol.v1_0.routes.marketplace_routes import ( add_marketplace_connection_handler, query_marketplace_connections_handler, + query_publish_dda_template_for_marketplace_connection, query_published_dda_template_handler, - query_publish_dda_template_for_marketplace_connection ) # Data Disclosure Agreement routes @@ -24,62 +24,60 @@ "/v1/data-disclosure-agreements", create_data_disclosure_agreement_handler, ), - web.get( - "/v1/data-disclosure-agreements", - query_dda_handler, - allow_head=False - ), + web.get("/v1/data-disclosure-agreements", query_dda_handler, allow_head=False), web.post( - "/v1/data-disclosure-agreements/{template_id}", - update_dda_template_handler + "/v1/data-disclosure-agreements/{template_id}", update_dda_template_handler ), web.delete( - "/v1/data-disclosure-agreements/{template_id}", - delete_dda_template_handler + "/v1/data-disclosure-agreements/{template_id}", delete_dda_template_handler ), web.post( "/v1/data-disclosure-agreements/{template_id}/publish", - publish_dda_template_handler + publish_dda_template_handler, ), web.post( "/v1/data-disclosure-agreements/{template_id}/marketplace/{connection_id}", - publish_dda_to_marketplace_handler + publish_dda_to_marketplace_handler, ), web.get( "/v1/data-disclosure-agreements/marketplace", list_dda_published_in_marketplace, - allow_head=False + allow_head=False, ), web.post( "/v1/data-disclosure-agreements/{template_id}/request/connections/{connection_id}", - request_dda_offer_from_ds_handler + request_dda_offer_from_ds_handler, ), web.get( "/v1/auditor/data-disclosure-agreements/instances", query_dda_instances_handler, allow_head=False, ), + web.post( + "/v1/data-disclosure-agreements/instances/{instance_id}/deactivate", + deactivate_dda_instance_handler, + ), ] MARKETPLACE_ROUTES = [ web.post( "/v1/data-marketplace/connections/{connection_id}", - add_marketplace_connection_handler + add_marketplace_connection_handler, ), web.get( "/v1/data-marketplace/connections", query_marketplace_connections_handler, - allow_head=False + allow_head=False, ), web.get( "/v1/data-marketplace/published-dda", query_published_dda_template_handler, - allow_head=False + allow_head=False, ), web.get( "/v1/data-marketplace/{connection_id}/published-dda", query_publish_dda_template_for_marketplace_connection, - allow_head=False - ) + allow_head=False, + ), ] diff --git a/dexa_protocol/v1_0/routes/maps/tag_maps.py b/dexa_protocol/v1_0/routes/maps/tag_maps.py index 4f7e54b..0ec0c47 100644 --- a/dexa_protocol/v1_0/routes/maps/tag_maps.py +++ b/dexa_protocol/v1_0/routes/maps/tag_maps.py @@ -1,4 +1,4 @@ -from ...message_types import SPEC_URI +from dexa_protocol.v1_0.message_types import SPEC_URI TAGS_DDA_LABEL = "Data Disclosure Agreements" TAGS_DDA = { diff --git a/dexa_protocol/v1_0/routes/marketplace_routes.py b/dexa_protocol/v1_0/routes/marketplace_routes.py index 7030373..153ca65 100644 --- a/dexa_protocol/v1_0/routes/marketplace_routes.py +++ b/dexa_protocol/v1_0/routes/marketplace_routes.py @@ -1,20 +1,14 @@ from aiohttp import web -from aiohttp_apispec import ( - docs, - match_info_schema, - querystring_schema -) -from dexa_sdk.managers.dexa_manager import DexaManager -from dexa_sdk.utils import ( - clean_and_get_field_from_dict -) -from .maps.tag_maps import TAGS_MARKETPLACE_LABEL -from .openapi.schemas import ( +from aiohttp_apispec import docs, match_info_schema, querystring_schema +from dexa_protocol.v1_0.routes.maps.tag_maps import TAGS_MARKETPLACE_LABEL +from dexa_protocol.v1_0.routes.openapi.schemas import ( AddMarketPlaceConnectionMatchInfoSchema, QueryMarketplaceConnectionsQueryInfoSchema, + QueryPublishedDDATemplatesForMarketplaceConnectionMatchInfoSchema, QueryPublishedDDATemplatesQueryString, - QueryPublishedDDATemplatesForMarketplaceConnectionMatchInfoSchema ) +from dexa_sdk.managers.dexa_manager import DexaManager +from dexa_sdk.utils import clean_and_get_field_from_dict @docs(tags=[TAGS_MARKETPLACE_LABEL], summary="Mark a connection as data marketplace") @@ -80,8 +74,7 @@ async def query_published_dda_template_handler(request: web.BaseRequest): # Query the records and obtain the paginated result. results = await manager.query_publish_dda_template_records( - page if page else 1, - page_size if page_size else 10 + page if page else 1, page_size if page_size else 10 ) return web.json_response(results._asdict()) @@ -89,11 +82,11 @@ async def query_published_dda_template_handler(request: web.BaseRequest): @docs( tags=[TAGS_MARKETPLACE_LABEL], - summary="Query published DDA tempates for a marketplace connection" + summary="Query published DDA tempates for a marketplace connection", ) @match_info_schema(QueryPublishedDDATemplatesForMarketplaceConnectionMatchInfoSchema()) async def query_publish_dda_template_for_marketplace_connection( - request: web.BaseRequest + request: web.BaseRequest, ): """Query published DDA templates for a marketplace connection. @@ -110,8 +103,6 @@ async def query_publish_dda_template_for_marketplace_connection( # Initialise the manager mgr = DexaManager(context) - pagination_result = await mgr.send_list_marketplace_dda_message( - connection_id - ) + pagination_result = await mgr.send_list_marketplace_dda_message(connection_id) return web.json_response(pagination_result._asdict()) diff --git a/dexa_protocol/v1_0/routes/openapi/schemas.py b/dexa_protocol/v1_0/routes/openapi/schemas.py index 46011f1..d70c928 100644 --- a/dexa_protocol/v1_0/routes/openapi/schemas.py +++ b/dexa_protocol/v1_0/routes/openapi/schemas.py @@ -36,18 +36,18 @@ class CreateDataDisclosureAgreementTemplateRequestSchema(OpenAPISchema): language = fields.Str(data_key="language") data_controller = fields.Nested( - DataControllerOpenAPISchema, - data_key="dataController" + DataControllerOpenAPISchema, data_key="dataController" ) agreement_period = fields.Int(data_key="agreementPeriod") data_sharing_restrictions = fields.Nested( - DataSharingRestrictionsOpenAPISchema, - data_key="dataSharingRestrictions" + DataSharingRestrictionsOpenAPISchema, data_key="dataSharingRestrictions" ) purpose = fields.Str(data_key="purpose") purpose_description = fields.Str(data_key="purposeDescription") lawful_basis = fields.Str(data_key="lawfulBasis") - personal_data = fields.List(fields.Nested(PersonalDataOpenAPISchema), data_key="personalData") + personal_data = fields.List( + fields.Nested(PersonalDataOpenAPISchema), data_key="personalData" + ) code_of_conduct = fields.Str(data_key="codeOfConduct") @@ -81,20 +81,17 @@ class UpdateDDATemplateRequestSchema(OpenAPISchema): language = fields.Str(data_key="language") data_controller = fields.Nested( - DataControllerOpenAPISchema, - data_key="dataController" + DataControllerOpenAPISchema, data_key="dataController" ) agreement_period = fields.Int(data_key="agreementPeriod") data_sharing_restrictions = fields.Nested( - DataSharingRestrictionsOpenAPISchema, - data_key="dataSharingRestrictions" + DataSharingRestrictionsOpenAPISchema, data_key="dataSharingRestrictions" ) purpose = fields.Str(data_key="purpose") purpose_description = fields.Str(data_key="purposeDescription") lawful_basis = fields.Str(data_key="lawfulBasis") personal_data = fields.List( - fields.Nested(PersonalDataOpenAPISchema), - data_key="personalData" + fields.Nested(PersonalDataOpenAPISchema), data_key="personalData" ) code_of_conduct = fields.Str(data_key="codeOfConduct") @@ -162,3 +159,9 @@ class QueryDDAInstancesQueryStringSchema(OpenAPISchema): connection_id = fields.Str(required=False) page = fields.Int(required=False) page_size = fields.Int(required=False) + + +class DeactivateDDAMatchInfoSchema(OpenAPISchema): + """Deactivate DDA match info schema""" + + instance_id = fields.Str() diff --git a/dexa_protocol/v1_0/routes/routes.py b/dexa_protocol/v1_0/routes/routes.py index 42f920b..09bdfb7 100644 --- a/dexa_protocol/v1_0/routes/routes.py +++ b/dexa_protocol/v1_0/routes/routes.py @@ -1,9 +1,6 @@ from aiohttp import web -from .maps.route_maps import ( - ROUTES_DDA, - MARKETPLACE_ROUTES -) -from .maps.tag_maps import TAGS_DDA +from dexa_protocol.v1_0.routes.maps.route_maps import MARKETPLACE_ROUTES, ROUTES_DDA +from dexa_protocol.v1_0.routes.maps.tag_maps import TAGS_DDA async def register(app: web.Application): diff --git a/pyproject.toml b/pyproject.toml index 9d4e323..d4af829 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dexa-protocol" -version = "0.1.0" +version = "0.1.1" description = "Hosts Data Disclosure Agreement protocols" authors = ["George J Padayatti "] license = "MIT"