Skip to content

Commit

Permalink
Merge branch 'main' into fix-deprecation-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 authored Feb 17, 2024
2 parents afae3db + a36094e commit f77019c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
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
9 changes: 8 additions & 1 deletion aries_cloudagent/multitenant/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
request_schema,
response_schema,
)

from marshmallow import ValidationError, fields, validate, validates_schema

from ...admin.request_context import AdminRequestContext
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 = [
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
10 changes: 5 additions & 5 deletions aries_cloudagent/vc/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit f77019c

Please sign in to comment.