Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert profile inject #2789

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions aries_cloudagent/config/provider.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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."""
Expand Down
14 changes: 3 additions & 11 deletions aries_cloudagent/core/profile.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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=[]):
Expand All @@ -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=[]):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down