From 671558ee97c6002a507b3526361c99db412d4524 Mon Sep 17 00:00:00 2001 From: Jamie Hale Date: Tue, 24 Sep 2024 19:25:06 +0000 Subject: [PATCH] Remove did:tdw web interface Signed-off-by: Jamie Hale --- aries_cloudagent/config/default_context.py | 3 - aries_cloudagent/did/manager.py | 30 ------- aries_cloudagent/did/tdw/__init__.py | 0 aries_cloudagent/did/tdw/routes.py | 84 ------------------- aries_cloudagent/did/tdw/tdw_manager.py | 36 -------- aries_cloudagent/did/tdw/tests/test_routes.py | 66 --------------- .../did/tdw/tests/test_tdw_manager.py | 23 ----- aries_cloudagent/resolver/routes.py | 8 +- 8 files changed, 6 insertions(+), 244 deletions(-) delete mode 100644 aries_cloudagent/did/manager.py delete mode 100644 aries_cloudagent/did/tdw/__init__.py delete mode 100644 aries_cloudagent/did/tdw/routes.py delete mode 100644 aries_cloudagent/did/tdw/tdw_manager.py delete mode 100644 aries_cloudagent/did/tdw/tests/test_routes.py delete mode 100644 aries_cloudagent/did/tdw/tests/test_tdw_manager.py diff --git a/aries_cloudagent/config/default_context.py b/aries_cloudagent/config/default_context.py index 5665239efc..669052965f 100644 --- a/aries_cloudagent/config/default_context.py +++ b/aries_cloudagent/config/default_context.py @@ -140,9 +140,6 @@ async def load_plugins(self, context: InjectionContext): plugin_registry.register_plugin("aries_cloudagent.wallet") plugin_registry.register_plugin("aries_cloudagent.wallet.keys") - # Did management plugins - plugin_registry.register_plugin("aries_cloudagent.did.tdw") - anoncreds_plugins = [ "aries_cloudagent.anoncreds", "aries_cloudagent.anoncreds.default.did_indy", diff --git a/aries_cloudagent/did/manager.py b/aries_cloudagent/did/manager.py deleted file mode 100644 index 55c5b1b240..0000000000 --- a/aries_cloudagent/did/manager.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Abstract class for DID manager.""" - -from abc import ABC, abstractmethod -from typing import List, Optional - -from aries_cloudagent.core.profile import Profile - - -class DidManager(ABC): - """Abstract class for DID manager.""" - - def __init__(self, profile: Profile): - """Initialize the DID manager.""" - self.profile = profile - - @abstractmethod - async def register(self, features: Optional[List[dict]] = None): - """Register a DID with the ledger.""" - - @abstractmethod - async def resolve(self, did: str): - """Resolve a DID.""" - - @abstractmethod - async def update(self, did: str): - """Update a DID.""" - - @abstractmethod - async def delete(self, did: str): - """Delete a DID.""" diff --git a/aries_cloudagent/did/tdw/__init__.py b/aries_cloudagent/did/tdw/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/aries_cloudagent/did/tdw/routes.py b/aries_cloudagent/did/tdw/routes.py deleted file mode 100644 index fc71d26c98..0000000000 --- a/aries_cloudagent/did/tdw/routes.py +++ /dev/null @@ -1,84 +0,0 @@ -"""DID TDW routes.""" - -from http import HTTPStatus - -from aiohttp import web -from aiohttp_apispec import docs, request_schema, response_schema -from marshmallow import fields - -from ...admin.decorators.auth import tenant_authentication -from ...admin.request_context import AdminRequestContext -from ...did.tdw.tdw_manager import DidTdwManager -from ...messaging.models.openapi import OpenAPISchema - - -class DidTdwResolveSchema(OpenAPISchema): - """Parameters and validators for create DID endpoint.""" - - did = fields.Str( - required=True, - metadata={ - "example": "did:tdw:QmRHpkso6BM1jRvGee5VoiS3a6wUfPAfuPnyGRBFo4rL6k:example.com", # noqa: E501 - "description": "Did TDW to resolve", - }, - ) - - -class DidTdwResolveResponse(OpenAPISchema): - """Response schema for create DID endpoint.""" - - did_doc = fields.Dict( - required=True, - metadata={ - "description": "Resolved DID document", - "example": { - "@context": [ - "https://www.w3.org/ns/did/v1", - "https://w3id.org/security/multikey/v1", - ], - "id": "did:tdw:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example", # noqa: E501 - }, - }, - ) - - -@docs(tags=["did"], summary="Resolve a TDW DID") -@request_schema(DidTdwResolveSchema()) -@response_schema(DidTdwResolveResponse()) -@tenant_authentication -async def resolve_did_tdw(request: web.BaseRequest): - """Resolve a DID TDW.""" - context: AdminRequestContext = request["context"] - did = (await request.json()).get("did") - resolved_did_response = await DidTdwManager(context.profile).resolve(did) - if resolved_did_response.get("error"): - return web.json_response( - { - "error": resolved_did_response["error"], - "message": resolved_did_response["errorMessage"], - }, - status=HTTPStatus.BAD_REQUEST, - ) - return web.json_response({"did_doc": resolved_did_response}) - - -async def register(app: web.Application): - """Register routes.""" - app.add_routes([web.post("/did/tdw/resolve", resolve_did_tdw)]) - - -def post_process_routes(app: web.Application): - """Amend swagger API.""" - # Add top-level tags description - if "tags" not in app._state["swagger_dict"]: - app._state["swagger_dict"]["tags"] = [] - app._state["swagger_dict"]["tags"].append( - { - "name": "did", - "description": "Endpoints for managing dids", - "externalDocs": { - "description": "Specification", - "url": "https://www.w3.org/TR/did-core/", - }, - } - ) diff --git a/aries_cloudagent/did/tdw/tdw_manager.py b/aries_cloudagent/did/tdw/tdw_manager.py deleted file mode 100644 index 52deee9a60..0000000000 --- a/aries_cloudagent/did/tdw/tdw_manager.py +++ /dev/null @@ -1,36 +0,0 @@ -"""DID TDW manager.""" - -import logging -from typing import List, Optional - -from ...core.profile import Profile -from ...did.manager import DidManager -from ...resolver.did_resolver import DIDResolver - -LOGGER = logging.getLogger(__name__) - - -class DidTdwManager(DidManager): - """DID TDW manager.""" - - def __init__(self, profile: Profile): - """Initialize DID Rotate Manager.""" - self.profile = profile - - async def register(self, features: Optional[List[dict]] = None): - """Register a DID TDW with the ledger.""" - raise NotImplementedError - - async def resolve(self, did: str): - """Resolve a DID TDW.""" - - resolver = self.profile.inject(DIDResolver) - return await resolver.resolve(self.profile, did) - - async def update(self, did: str): - """Update a DID TDW.""" - raise NotImplementedError - - async def delete(self, did: str): - """Delete a DID TDW.""" - raise NotImplementedError diff --git a/aries_cloudagent/did/tdw/tests/test_routes.py b/aries_cloudagent/did/tdw/tests/test_routes.py deleted file mode 100644 index 5cb5cc89fa..0000000000 --- a/aries_cloudagent/did/tdw/tests/test_routes.py +++ /dev/null @@ -1,66 +0,0 @@ -from unittest import IsolatedAsyncioTestCase - -from aries_cloudagent.admin.request_context import AdminRequestContext -from aries_cloudagent.core.in_memory.profile import InMemoryProfile -from aries_cloudagent.did.tdw.routes import resolve_did_tdw -from aries_cloudagent.resolver.did_resolver import DIDResolver -from aries_cloudagent.tests import mock - -mock_response = { - "@context": [ - "https://www.w3.org/ns/did/v1", - "https://w3id.org/security/multikey/v1", - ], - "id": "did:tdw:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example", # noqa: E501 -} - - -class TestAnoncredsRoutes(IsolatedAsyncioTestCase): - async def asyncSetUp(self) -> None: - self.session_inject = {} - self.profile = InMemoryProfile.test_profile( - settings={ - "admin.admin_api_key": "secret-key", - }, - ) - self.context = AdminRequestContext.test_context(self.session_inject, self.profile) - self.request_dict = { - "context": self.context, - } - self.request = mock.MagicMock( - app={}, - match_info={}, - query={}, - __getitem__=lambda _, k: self.request_dict[k], - context=self.context, - headers={"x-api-key": "secret-key"}, - json=mock.AsyncMock( - return_value={ - "did": "did:tdw:QmRHpkso6BM1jRvGee5VoiS3a6wUfPAfuPnyGRBFo4rL6k:example.com" - } - ), - ) - - async def test_resolve_did_tdw(self): - self.profile.context.injector.bind_instance( - DIDResolver, - mock.MagicMock(resolve=mock.CoroutineMock(return_value=mock_response)), - ) - response = await resolve_did_tdw(self.request) - assert response.body - - async def test_resolve_did_tdw_error(self): - self.profile.context.injector.bind_instance( - DIDResolver, - mock.MagicMock( - resolve=mock.CoroutineMock( - return_value={ - "error": "error", - "errorMessage": "error message", - } - ) - ), - ) - response = await resolve_did_tdw(self.request) - assert response.status == 400 - assert response.body diff --git a/aries_cloudagent/did/tdw/tests/test_tdw_manager.py b/aries_cloudagent/did/tdw/tests/test_tdw_manager.py deleted file mode 100644 index fb0ad4fbfb..0000000000 --- a/aries_cloudagent/did/tdw/tests/test_tdw_manager.py +++ /dev/null @@ -1,23 +0,0 @@ -from aries_cloudagent.core.in_memory.profile import InMemoryProfile -from aries_cloudagent.did.tdw.tdw_manager import DidTdwManager -from aries_cloudagent.resolver.did_resolver import DIDResolver -from aries_cloudagent.tests import mock - - -class TestTdwManager: - def test_init(self): - manager = DidTdwManager(InMemoryProfile.test_profile()) - assert manager - - async def test_resolve(self): - profile = InMemoryProfile.test_profile() - profile.context.injector.bind_instance( - DIDResolver, - mock.MagicMock( - resolve=mock.CoroutineMock(return_value={"did_doc": "resolved"}) - ), - ) - await DidTdwManager(profile).resolve( - "did:tdw:QmRHpkso6BM1jRvGee5VoiS3a6wUfPAfuPnyGRBFo4rL6k:example.com" - ) - assert profile.context.injector.get_provider(DIDResolver)._instance.resolve.called diff --git a/aries_cloudagent/resolver/routes.py b/aries_cloudagent/resolver/routes.py index 3016aafbb7..a46065aafe 100644 --- a/aries_cloudagent/resolver/routes.py +++ b/aries_cloudagent/resolver/routes.py @@ -1,9 +1,10 @@ """Resolve did document admin routes.""" +import re + from aiohttp import web from aiohttp_apispec import docs, match_info_schema, response_schema from marshmallow import fields, validate -from pydid.common import DID_PATTERN from ..admin.decorators.auth import tenant_authentication from ..admin.request_context import AdminRequestContext @@ -23,7 +24,10 @@ class W3cDID(validate.Regexp): """Validate value against w3c DID.""" EXAMPLE = "did:ted:WgWxqztrNooG92RXvxSTWv" - PATTERN = DID_PATTERN + # Did or DidUrl regex + PATTERN = re.compile( + r"did:([a-z0-9]+):((?:[a-zA-Z0-9._%-]*:)*[a-zA-Z0-9._%-]+)+(#\w+)?$" + ) def __init__(self): """Initialize the instance."""