diff --git a/aries_cloudagent/config/provider.py b/aries_cloudagent/config/provider.py index c97c300cec..17a4e22b70 100644 --- a/aries_cloudagent/config/provider.py +++ b/aries_cloudagent/config/provider.py @@ -1,14 +1,12 @@ """Service provider implementations.""" import hashlib - from typing import Optional, Sequence, Union from weakref import ReferenceType from ..utils.classloader import DeferLoad from ..utils.stats import Collector - -from .base import BaseProvider, BaseSettings, BaseInjector, InjectionError +from .base import BaseInjector, BaseProvider, BaseSettings, InjectionError class InstanceProvider(BaseProvider): @@ -52,10 +50,8 @@ def __init__( self._ctor_kwargs = ctor_kwargs self._init_method = init_method if isinstance(instance_cls, str): - cls = DeferLoad(instance_cls) - else: - cls = instance_cls - self._instance_cls: Union[type, DeferLoad] = cls + instance_cls = DeferLoad(instance_cls) + self._instance_cls = instance_cls def provide(self, config: BaseSettings, injector: BaseInjector): """Provide the object instance given a config and injector.""" diff --git a/aries_cloudagent/core/profile.py b/aries_cloudagent/core/profile.py index 395e320d23..7b2b2f50da 100644 --- a/aries_cloudagent/core/profile.py +++ b/aries_cloudagent/core/profile.py @@ -1,20 +1,17 @@ """Classes for managing profile information within a request context.""" import logging - from abc import ABC, abstractmethod from typing import Any, Mapping, Optional, Type -from weakref import ref -from .event_bus import EventBus, Event from ..config.base import InjectionError -from ..config.injector import BaseInjector, InjectType from ..config.injection_context import InjectionContext +from ..config.injector import BaseInjector, InjectType from ..config.provider import BaseProvider from ..config.settings import BaseSettings from ..utils.classloader import ClassLoader, ClassNotFoundError - from .error import ProfileSessionInactiveError +from .event_bus import Event, EventBus LOGGER = logging.getLogger(__name__) @@ -33,14 +30,9 @@ def __init__( created: bool = False, ): """Initialize a base profile.""" - context = context or InjectionContext() - scope = "profile" - if name: - scope += ":" + name - self._context = context.start_scope(scope) + self._context = context or InjectionContext() self._created = created self._name = name or Profile.DEFAULT_NAME - self._context.injector.bind_instance(Profile, ref(self)) @property def backend(self) -> str: diff --git a/aries_cloudagent/multitenant/admin/routes.py b/aries_cloudagent/multitenant/admin/routes.py index eb5f439eea..2ebdc83800 100644 --- a/aries_cloudagent/multitenant/admin/routes.py +++ b/aries_cloudagent/multitenant/admin/routes.py @@ -8,7 +8,6 @@ request_schema, response_schema, ) - from marshmallow import ValidationError, fields, validate, validates_schema from ...admin.request_context import AdminRequestContext @@ -40,6 +39,10 @@ "ACAPY_AUTO_WRITE_TRANSACTIONS": "endorser.auto_write", "ACAPY_CREATE_REVOCATION_TRANSACTIONS": "endorser.auto_create_rev_reg", "ACAPY_ENDORSER_ROLE": "endorser.protocol_role", + "ACAPY_EMIT_DID_PEER_2": "emit_did_peer_2", + "ACAPY_EMIT_DID_PEER_4": "emit_did_peer_4", + "ACAPY_PRESERVE_EXCHANGE_RECORDS": "preserve_exchange_records", + "ACAPY_REQUESTS_THROUGH_PUBLIC_DID": "requests_through_public_did", } ACAPY_LIFECYCLE_CONFIG_FLAG_ARGS_MAP = { @@ -59,6 +62,10 @@ "auto-write-transactions": "endorser.auto_write", "auto-create-revocation-transactions": "endorser.auto_create_rev_reg", "endorser-protocol-role": "endorser.protocol_role", + "emit-did-peer-2": "emit_did_peer_2", + "emit-did-peer-4": "emit_did_peer_4", + "preserve-exchange-records": "preserve_exchange_records", + "requests-through-public-did": "requests_through_public_did", } ACAPY_ENDORSER_FLAGS_DEPENDENT_ON_AUTHOR_ROLE = [ diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py index c1949d2486..9640101e5a 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py @@ -132,7 +132,7 @@ async def create_proposal( self, cred_ex_record: V20CredExRecord, proposal_data: Mapping ) -> CredFormatAttachment: """Create linked data proof credential proposal.""" - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) detail = LDProofVCDetail.deserialize(proposal_data) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) @@ -164,7 +164,7 @@ async def create_offer( # but also when we create an offer (manager does some weird stuff) offer_data = cred_proposal_message.attachment(LDProofCredFormatHandler.format) detail = LDProofVCDetail.deserialize(offer_data) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) try: @@ -224,7 +224,7 @@ async def create_request( ) detail = LDProofVCDetail.deserialize(request_data) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) try: @@ -290,7 +290,7 @@ async def issue_credential( LDProofCredFormatHandler.format ) detail = LDProofVCDetail.deserialize(detail_dict) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) try: @@ -381,7 +381,7 @@ async def store_credential( credential = VerifiableCredential.deserialize(cred_dict, unknown=INCLUDE) # Get signature suite, proof purpose and document loader - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) try: result = await manager.verify_credential(credential) except VcLdpManagerError as err: diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py index be1d5c86ec..3472f1f3f5 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py @@ -1,11 +1,11 @@ from copy import deepcopy -from .......vc.ld_proofs.error import LinkedDataProofException from unittest import IsolatedAsyncioTestCase -from aries_cloudagent.tests import mock from unittest.mock import patch + from marshmallow import ValidationError -from .. import handler as test_module +from aries_cloudagent.tests import mock + from .......core.in_memory import InMemoryProfile from .......messaging.decorators.attach_decorator import AttachDecorator from .......storage.vc_holder.base import VCHolder @@ -15,6 +15,7 @@ SECURITY_CONTEXT_BBS_URL, SECURITY_CONTEXT_ED25519_2020_URL, ) +from .......vc.ld_proofs.error import LinkedDataProofException from .......vc.tests.document_loader import custom_document_loader from .......vc.vc_ld.manager import VcLdpManager from .......vc.vc_ld.models.credential import VerifiableCredential @@ -39,8 +40,9 @@ from ....models.cred_ex_record import V20CredExRecord from ....models.detail.ld_proof import V20CredExRecordLDProof from ...handler import V20CredFormatError -from ..handler import LDProofCredFormatHandler +from .. import handler as test_module from ..handler import LOGGER as LD_PROOF_LOGGER +from ..handler import LDProofCredFormatHandler from ..models.cred_detail import LDProofVCDetail TEST_DID_SOV = "did:sov:LjgpST2rjsoxYegQDRm7EL" @@ -249,7 +251,7 @@ async def test_receive_proposal(self): async def test_create_offer(self): with mock.patch.object( - self.manager, + VcLdpManager, "assert_can_issue_with_id_and_proof_type", mock.CoroutineMock(), ) as mock_can_issue, patch.object( @@ -289,7 +291,7 @@ async def test_create_offer_adds_bbs_context(self): ) with mock.patch.object( - self.manager, + VcLdpManager, "assert_can_issue_with_id_and_proof_type", mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): @@ -314,7 +316,7 @@ async def test_create_offer_adds_ed25519_2020_context(self): ) with mock.patch.object( - self.manager, + VcLdpManager, "assert_can_issue_with_id_and_proof_type", mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): @@ -585,7 +587,7 @@ async def test_issue_credential(self): ) with mock.patch.object( - self.manager, + VcLdpManager, "issue", mock.CoroutineMock( return_value=VerifiableCredential.deserialize(LD_PROOF_VC) @@ -843,7 +845,7 @@ async def test_store_credential(self): self.holder.store_credential = mock.CoroutineMock() with mock.patch.object( - self.manager, + VcLdpManager, "verify_credential", mock.CoroutineMock(return_value=DocumentVerificationResult(verified=True)), ) as mock_verify_credential: diff --git a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py index 207cbca5e0..d7f2b0dd2c 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py @@ -446,7 +446,7 @@ async def verify_pres(self, pres_ex_record: V20PresExRecord) -> V20PresExRecord: pres_request = pres_ex_record.pres_request.attachment( DIFPresFormatHandler.format ) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) options = LDProofVCOptions.deserialize(pres_request["options"]) if not options.challenge: diff --git a/aries_cloudagent/vc/routes.py b/aries_cloudagent/vc/routes.py index 0676fe9f92..8a021223ae 100644 --- a/aries_cloudagent/vc/routes.py +++ b/aries_cloudagent/vc/routes.py @@ -75,7 +75,7 @@ async def issue_credential_route(request: web.BaseRequest): """ body = await request.json() context: AdminRequestContext = request["context"] - manager = context.inject(VcLdpManager) + manager = VcLdpManager(context.profile) try: credential = body["credential"] options = {} if "options" not in body else body["options"] @@ -120,7 +120,7 @@ async def verify_credential_route(request: web.BaseRequest): """ body = await request.json() context: AdminRequestContext = request["context"] - manager = context.inject(VcLdpManager) + manager = VcLdpManager(context.profile) try: vc = VerifiableCredential.deserialize(body["verifiableCredential"]) result = await manager.verify_credential(vc) @@ -147,7 +147,7 @@ async def store_credential_route(request: web.BaseRequest): """ body = await request.json() context: AdminRequestContext = request["context"] - manager = context.inject(VcLdpManager) + manager = VcLdpManager(context.profile) try: vc = body["verifiableCredential"] @@ -183,7 +183,7 @@ async def prove_presentation_route(request: web.BaseRequest): """ context: AdminRequestContext = request["context"] - manager = context.inject(VcLdpManager) + manager = VcLdpManager(context.profile) body = await request.json() try: presentation = body["presentation"] @@ -225,7 +225,7 @@ async def verify_presentation_route(request: web.BaseRequest): """ context: AdminRequestContext = request["context"] - manager = context.inject(VcLdpManager) + manager = VcLdpManager(context.profile) body = await request.json() try: vp = VerifiablePresentation.deserialize(body["verifiablePresentation"])