Skip to content

Commit

Permalink
Merge pull request #1 from andrewwhitehead/sign-ack-merge
Browse files Browse the repository at this point in the history
Merge with upstream refactoring
  • Loading branch information
sklump authored Nov 6, 2019
2 parents 07669b7 + 98b9f78 commit 2c7db80
Show file tree
Hide file tree
Showing 288 changed files with 1,350 additions and 1,622 deletions.
40 changes: 13 additions & 27 deletions aries_cloudagent/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,13 @@

from aiohttp import web

from ..messaging.actionmenu.routes import register as register_actionmenu
from ..messaging.connections.routes import register as register_connections
from ..messaging.credentials.routes import register as register_credentials
from ..messaging.introduction.routes import register as register_introduction
from ..messaging.issue_credential.v1_0.routes import (
register as register_v10_issue_credential
)
from ..messaging.present_proof.v1_0.routes import (
register as register_v10_present_proof
)
from ..messaging.presentations.routes import register as register_presentations
from ..classloader import ClassLoader, ModuleLoadError
from ..messaging.schemas.routes import register as register_schemas
from ..messaging.credential_definitions.routes import (
register as register_credential_definitions,
)
from ..messaging.basicmessage.routes import register as register_basicmessages
from ..messaging.discovery.routes import register as register_discovery
from ..messaging.trustping.routes import register as register_trustping
from ..wallet.routes import register as register_wallet
from ..ledger.routes import register as register_ledger
from ..wallet.routes import register as register_wallet


async def register_module_routes(app: web.Application):
Expand All @@ -31,17 +18,16 @@ async def register_module_routes(app: web.Application):
Eventually this should use dynamic registration based on the
currently-selected message families.
"""
await register_actionmenu(app)
await register_connections(app)
await register_credentials(app)
await register_introduction(app)
await register_presentations(app)
await register_schemas(app)
await register_credential_definitions(app)
await register_basicmessages(app)
await register_discovery(app)
await register_trustping(app)
await register_v10_issue_credential(app)
await register_v10_present_proof(app)
await register_wallet(app)
await register_ledger(app)
await register_schemas(app)
await register_wallet(app)

packages = ClassLoader.scan_subpackages("aries_cloudagent.protocols")
for pkg in packages:
try:
mod = ClassLoader.load_module(pkg + ".routes")
except ModuleLoadError:
continue
if hasattr(mod, "register"):
await mod.register(app)
20 changes: 20 additions & 0 deletions aries_cloudagent/classloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import inspect
import logging
import pkg_resources

from importlib import import_module
from typing import Sequence

from .error import BaseError

Expand Down Expand Up @@ -148,3 +150,21 @@ def load_class(cls, class_name: str, default_module: str = None):
f"Resolved value is not a class: {mod_path}.{class_name}"
)
return resolved

@classmethod
def scan_subpackages(cls, package: str) -> Sequence[str]:
"""Return a list of sub-packages defined under a named package."""
# FIXME use importlib.resources in python 3.7
if "." in package:
package, sub_pkg = package.split(".", 1)
else:
sub_pkg = "."
if not pkg_resources.resource_isdir(package, sub_pkg):
raise ModuleLoadError(f"Undefined package {package}")
found = []
for sub_path in pkg_resources.resource_listdir(package, sub_pkg):
if pkg_resources.resource_exists(
package, f"{sub_pkg}/{sub_path}/__init__.py"
):
found.append(f"{package}.{sub_pkg}.{sub_path}")
return found
10 changes: 6 additions & 4 deletions aries_cloudagent/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from .config.logging import LoggingConfigurator
from .config.wallet import wallet_config
from .dispatcher import Dispatcher
from .messaging.connections.manager import ConnectionManager, ConnectionManagerError
from .messaging.connections.models.connection_record import ConnectionRecord
from .protocols.connections.manager import ConnectionManager, ConnectionManagerError
from .connections.models.connection_record import ConnectionRecord
from .messaging.error import MessageParseError, MessagePrepareError
from .messaging.outbound_message import OutboundMessage
from .messaging.responder import BaseResponder
Expand Down Expand Up @@ -228,8 +228,10 @@ async def stop(self, timeout=0.1):
tasks = []
if self.admin_server:
tasks.append(self.admin_server.stop())
tasks.append(self.inbound_transport_manager.stop())
tasks.append(self.outbound_transport_manager.stop())
if self.inbound_transport_manager:
tasks.append(self.inbound_transport_manager.stop())
if self.outbound_transport_manager:
tasks.append(self.outbound_transport_manager.stop())
await asyncio.wait_for(asyncio.gather(*tasks), timeout)

async def register_socket(
Expand Down
8 changes: 4 additions & 4 deletions aries_cloudagent/config/default_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
from ..issuer.base import BaseIssuer
from ..holder.base import BaseHolder
from ..verifier.base import BaseVerifier
from ..messaging.actionmenu.base_service import BaseMenuService
from ..messaging.actionmenu.driver_service import DriverMenuService
from ..messaging.introduction.base_service import BaseIntroductionService
from ..messaging.introduction.demo_service import DemoIntroductionService
from ..messaging.protocol_registry import ProtocolRegistry
from ..messaging.serializer import MessageSerializer
from ..protocols.actionmenu.base_service import BaseMenuService
from ..protocols.actionmenu.driver_service import DriverMenuService
from ..protocols.introduction.base_service import BaseIntroductionService
from ..protocols.introduction.demo_service import DemoIntroductionService
from ..stats import Collector
from ..storage.base import BaseStorage
from ..storage.provider import StorageProvider
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
from marshmallow import fields
from marshmallow.validate import OneOf

from ....config.injection_context import InjectionContext
from ....storage.base import BaseStorage
from ....storage.record import StorageRecord

from ...models.base_record import BaseRecord, BaseRecordSchema
from ...util import time_now
from ...valid import INDY_DID, INDY_RAW_PUBLIC_KEY, UUIDFour

from ..messages.connection_invitation import ConnectionInvitation
from ..messages.connection_request import ConnectionRequest
from ...config.injection_context import InjectionContext
from ...messaging.models.base_record import BaseRecord, BaseRecordSchema
from ...messaging.valid import INDY_DID, INDY_RAW_PUBLIC_KEY, UUIDFour
from ...messaging.util import time_now
from ...protocols.connections.messages.connection_invitation import ConnectionInvitation
from ...protocols.connections.messages.connection_request import ConnectionRequest
from ...storage.base import BaseStorage
from ...storage.record import StorageRecord


class ConnectionRecord(BaseRecord): # lgtm[py/missing-equals]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from marshmallow import fields

from ...models.base import BaseModel, BaseModelSchema
from ...valid import INDY_DID, INDY_RAW_PUBLIC_KEY
from ...messaging.models.base import BaseModel, BaseModelSchema
from ...messaging.valid import INDY_DID, INDY_RAW_PUBLIC_KEY


class ConnectionTarget(BaseModel):
Expand Down Expand Up @@ -52,40 +52,24 @@ class Meta:

model_class = ConnectionTarget

did = fields.Str(
required=False,
description="",
**INDY_DID
)
did = fields.Str(required=False, description="", **INDY_DID)
endpoint = fields.Str(
required=False,
description="Connection endpoint",
example="http://192.168.56.102:8020",
)
label = fields.Str(
required=False,
description="Connection label",
example="Bob"
)
label = fields.Str(required=False, description="Connection label", example="Bob")
recipient_keys = fields.List(
fields.Str(
description="Recipient public key",
**INDY_RAW_PUBLIC_KEY
),
fields.Str(description="Recipient public key", **INDY_RAW_PUBLIC_KEY),
required=False,
description="List of recipient keys"
description="List of recipient keys",
)
routing_keys = fields.List(
fields.Str(
description="Routing key",
**INDY_RAW_PUBLIC_KEY
),
fields.Str(description="Routing key", **INDY_RAW_PUBLIC_KEY),
data_key="routingKeys",
required=False,
description="List of routing keys",
)
sender_key = fields.Str(
required=False,
description="Sender public key",
**INDY_RAW_PUBLIC_KEY
required=False, description="Sender public key", **INDY_RAW_PUBLIC_KEY
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from asynctest import TestCase as AsyncTestCase

from ....config.injection_context import InjectionContext
from ...config.injection_context import InjectionContext
from ...storage.base import BaseStorage
from ...storage.basic import BasicStorage

from ..models.connection_record import ConnectionRecord
from ....storage.base import BaseStorage
from ....storage.basic import BasicStorage


class TestConfig:
Expand Down Expand Up @@ -67,7 +68,9 @@ async def test_request_is_not_ready(self):

async def test_invitation_is_not_multi_use(self):
record = ConnectionRecord(
my_did=self.test_did, state=ConnectionRecord.STATE_INVITATION, invitation_mode=ConnectionRecord.INVITATION_MODE_ONCE
my_did=self.test_did,
state=ConnectionRecord.STATE_INVITATION,
invitation_mode=ConnectionRecord.INVITATION_MODE_ONCE,
)
record_id = await record.save(self.context)
fetched = await ConnectionRecord.retrieve_by_id(self.context, record_id)
Expand All @@ -76,7 +79,9 @@ async def test_invitation_is_not_multi_use(self):

async def test_invitation_is_multi_use(self):
record = ConnectionRecord(
my_did=self.test_did, state=ConnectionRecord.STATE_INVITATION,invitation_mode=ConnectionRecord.INVITATION_MODE_MULTI
my_did=self.test_did,
state=ConnectionRecord.STATE_INVITATION,
invitation_mode=ConnectionRecord.INVITATION_MODE_MULTI,
)
record_id = await record.save(self.context)
fetched = await ConnectionRecord.retrieve_by_id(self.context, record_id)
Expand Down
53 changes: 11 additions & 42 deletions aries_cloudagent/defaults.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,22 @@
"""Sane defaults for known message definitions."""

from .classloader import ClassLoader, ModuleLoadError
from .messaging.protocol_registry import ProtocolRegistry

from .messaging.actionmenu.message_types import (
CONTROLLERS as ACTIONMENU_CONTROLLERS,
MESSAGE_TYPES as ACTIONMENU_MESSAGES,
)
from .messaging.basicmessage.message_types import MESSAGE_TYPES as BASICMESSAGE_MESSAGES
from .messaging.connections.message_types import MESSAGE_TYPES as CONNECTION_MESSAGES
from .messaging.discovery.message_types import MESSAGE_TYPES as DISCOVERY_MESSAGES
from .messaging.introduction.message_types import MESSAGE_TYPES as INTRODUCTION_MESSAGES
from .messaging.presentations.message_types import (
MESSAGE_TYPES as PRESENTATION_MESSAGES,
)
from .messaging.credentials.message_types import MESSAGE_TYPES as CREDENTIAL_MESSAGES
from .messaging.trustping.message_types import MESSAGE_TYPES as TRUSTPING_MESSAGES
from .messaging.routing.message_types import MESSAGE_TYPES as ROUTING_MESSAGES
from .messaging.issue_credential.v1_0.message_types import (
MESSAGE_TYPES as V10_ISSUE_CREDENTIAL_MESSAGES
)
from .messaging.present_proof.v1_0.message_types import (
MESSAGE_TYPES as V10_PRESENT_PROOF_MESSAGES
)

from .messaging.problem_report.message import (
MESSAGE_TYPE as PROBLEM_REPORT,
ProblemReport,
)


def default_protocol_registry() -> ProtocolRegistry:
"""Protocol registry for default message types."""
registry = ProtocolRegistry()

registry.register_message_types(
ACTIONMENU_MESSAGES,
BASICMESSAGE_MESSAGES,
CONNECTION_MESSAGES,
DISCOVERY_MESSAGES,
INTRODUCTION_MESSAGES,
PRESENTATION_MESSAGES,
V10_PRESENT_PROOF_MESSAGES,
CREDENTIAL_MESSAGES,
V10_ISSUE_CREDENTIAL_MESSAGES,
ROUTING_MESSAGES,
TRUSTPING_MESSAGES,
{PROBLEM_REPORT: ProblemReport},
)

registry.register_controllers(ACTIONMENU_CONTROLLERS)
packages = ClassLoader.scan_subpackages("aries_cloudagent.protocols")
for pkg in packages:
try:
mod = ClassLoader.load_module(pkg + ".message_types")
except ModuleLoadError:
continue
if hasattr(mod, "MESSAGE_TYPES"):
registry.register_message_types(mod.MESSAGE_TYPES)
if hasattr(mod, "CONTROLLERS"):
registry.register_controllers(mod.CONTROLLERS)

return registry
4 changes: 2 additions & 2 deletions aries_cloudagent/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from .admin.base_server import BaseAdminServer
from .config.injection_context import InjectionContext
from .messaging.agent_message import AgentMessage
from .messaging.connections.models.connection_record import ConnectionRecord
from .connections.models.connection_record import ConnectionRecord
from .messaging.error import MessageParseError
from .messaging.message_delivery import MessageDelivery
from .messaging.models.base import BaseModelError
from .messaging.outbound_message import OutboundMessage
from .messaging.problem_report.message import ProblemReport
from .protocols.problem_report.message import ProblemReport
from .messaging.protocol_registry import ProtocolRegistry
from .messaging.request_context import RequestContext
from .messaging.responder import BaseResponder
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/holder/tests/test_indy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

import pytest

from asynctest import TestCase as AsyncTestCase
from asynctest import mock as async_mock

Expand All @@ -10,9 +12,7 @@
from aries_cloudagent.storage.record import StorageRecord
from aries_cloudagent.wallet.indy import IndyWallet

import pytest

from ...messaging.issue_credential.v1_0.messages.inner.credential_preview import (
from ...protocols.issue_credential.v1_0.messages.inner.credential_preview import (
CredentialPreview,
)

Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/ledger/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ async def send_schema(
"schema_issuer_did": public_info.did,
"schema_name": schema_id_parts[-2],
"schema_version": schema_id_parts[-1],
"epoch": int(time()),
"epoch": str(int(time())),
}
record = StorageRecord(
SCHEMA_SENT_RECORD_TYPE,
Expand Down Expand Up @@ -559,7 +559,7 @@ async def send_credential_definition(self, schema_id: str, tag: str = None):
"schema_version": schema_id_parts[-1],
"issuer_did": public_info.did,
"cred_def_id": credential_definition_id,
"epoch": int(time()),
"epoch": str(int(time())),
}
record = StorageRecord(
CRED_DEF_SENT_RECORD_TYPE,
Expand Down
19 changes: 0 additions & 19 deletions aries_cloudagent/messaging/actionmenu/message_types.py

This file was deleted.

10 changes: 0 additions & 10 deletions aries_cloudagent/messaging/basicmessage/message_types.py

This file was deleted.

Loading

0 comments on commit 2c7db80

Please sign in to comment.