Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from dbluhm/update/aca-py-0.6.0rc0
Browse files Browse the repository at this point in the history
Updates to support ACA-Py 0.6.0
  • Loading branch information
dbluhm authored Dec 18, 2020
2 parents de135c1 + 0188a96 commit 643a2fd
Show file tree
Hide file tree
Showing 21 changed files with 244 additions and 225 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ Quickstart Guide - Running locally

Requirements:
- Python 3.6 or higher
- ACA-Py @ master
- ACA-Py

> **Note:** This plugin is currently compatible only with the master branch of
> ACA-Py. Once a release including the new plugin interface is published to
> PyPI, these instructions will be updated accordingly.
### ACA-Py Version Compatibility

> TODO: Add instructions for payment plugin loading
To avoid a confusing pseudo-lock-step release, this plugin is
versioned independent of ACA-Py. Plugin releases will follow standard
[semver](semver.org) but each release will also be tagged with a mapping to an
ACA-Py version with the format `acapy-X.Y.Z-J` where `X.Y.Z` corresponds to the
ACA-Py version supported and `J` is an incrementing number for each new plugin
release that targets the same version of ACA-Py.

You should look for the most recent release tagged with the version of ACA-Py
you are using (with the highest value for `J`).

### Setup Aries Cloud Agent - Python

Expand Down Expand Up @@ -93,9 +99,12 @@ $ pip install -e .[indy]

Install this plugin into the virtual environment:
```sh
$ pip install git+https://github.com/hyperledger/aries-acapy-plugin-toolbox.git@master#egg=acapy-plugin-toolbox
$ pip install git+https://github.com/hyperledger/aries-acapy-plugin-toolbox.git@master#egg=acapy_plugin_toolbox
```

**Note:** Depending on your version of `pip`, you may need to drop the
`#egg=...` to install the plugin with the above command.

### Plugin Loading
Start up ACA-Py with the plugin parameter:
```sh
Expand Down
27 changes: 15 additions & 12 deletions acapy_plugin_toolbox/basicmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from marshmallow import fields

from aries_cloudagent.config.injection_context import InjectionContext
from aries_cloudagent.core.profile import ProfileSession
from aries_cloudagent.core.protocol_registry import ProtocolRegistry
from aries_cloudagent.connections.models.connection_record import (
ConnectionRecord
from aries_cloudagent.connections.models.conn_record import (
ConnRecord
)
from aries_cloudagent.messaging.base_handler import (
BaseHandler, BaseResponder, RequestContext
Expand Down Expand Up @@ -48,12 +48,12 @@


async def setup(
context: InjectionContext,
session: ProfileSession,
protocol_registry: ProblemReport = None
):
"""Setup the basicmessage plugin."""
if not protocol_registry:
protocol_registry = await context.inject(ProtocolRegistry)
protocol_registry = session.inject(ProtocolRegistry)
protocol_registry.register_message_types(
MESSAGE_TYPES
)
Expand Down Expand Up @@ -122,11 +122,11 @@ def record_tags(self) -> dict:
@classmethod
async def retrieve_by_message_id(
cls,
context: InjectionContext,
session: ProfileSession,
message_id: str) -> "BasicMessageRecord":
"""Retrieve a basic message record by message id."""
return await cls.retrieve_by_tag_filter(
context,
session,
{'message_id': message_id}
)

Expand Down Expand Up @@ -237,8 +237,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)

connection_mgr = ConnectionManager(context)
admins = await ConnectionRecord.query(
context, post_filter_positive={'their_role': 'admin'}
session = await context.session()
admins = await ConnRecord.query(
session, post_filter_positive={'their_role': 'admin'}
)

if not admins:
Expand Down Expand Up @@ -301,12 +302,13 @@ class GetHandler(BaseHandler):
@admin_only
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle received get requests."""
session = await context.session()
tag_filter = dict(filter(lambda item: item[1] is not None, {
'connection_id': context.message.connection_id,
}.items()))
msgs = sorted(
await BasicMessageRecord.query(
context,
session,
tag_filter
),
key=lambda msg: datetime_from_iso(msg.sent_time),
Expand Down Expand Up @@ -376,7 +378,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle received send requests."""
# pylint: disable=protected-access
try:
connection = await ConnectionRecord.retrieve_by_id(
connection = await ConnRecord.retrieve_by_id(
context, context.message.connection_id
)
except StorageNotFoundError:
Expand Down Expand Up @@ -442,12 +444,13 @@ class DeleteHandler(BaseHandler):
@admin_only
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle received delete requests."""
session = await context.session()
tag_filter = dict(filter(lambda item: item[1] is not None, {
'connection_id': context.message.connection_id,
'message_id': context.message.message_id,
}.items()))
msgs = await BasicMessageRecord.query(
context,
session,
tag_filter
)
if context.message.before_date:
Expand Down
41 changes: 16 additions & 25 deletions acapy_plugin_toolbox/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

from marshmallow import Schema, fields, validate

from aries_cloudagent.config.injection_context import InjectionContext
from aries_cloudagent.core.profile import ProfileSession
from aries_cloudagent.core.protocol_registry import ProtocolRegistry
from aries_cloudagent.messaging.base_handler import BaseHandler, BaseResponder, RequestContext
from aries_cloudagent.protocols.connections.v1_0.manager import ConnectionManager
from aries_cloudagent.connections.models.connection_record import (
ConnectionRecord
from aries_cloudagent.connections.models.conn_record import (
ConnRecord
)
from aries_cloudagent.protocols.connections.v1_0.messages.connection_invitation import (
ConnectionInvitation,
Expand Down Expand Up @@ -50,12 +50,12 @@


async def setup(
context: InjectionContext,
session: ProfileSession,
protocol_registry: ProtocolRegistry = None
):
"""Setup the connections plugin."""
if not protocol_registry:
protocol_registry = await context.inject(ProtocolRegistry)
protocol_registry = session.inject(ProtocolRegistry)

protocol_registry.register_message_types(
MESSAGE_TYPES
Expand All @@ -75,7 +75,6 @@ async def setup(
required=True
),
'their_did': fields.Str(required=False), # May be missing if pending
'role': fields.Str(required=False),
'raw_repr': fields.Dict(required=False)
})

Expand All @@ -87,8 +86,8 @@ async def setup(
)


def conn_record_to_message_repr(conn: ConnectionRecord) -> Dict[str, Any]:
"""Map ConnectionRecord onto Connection."""
def conn_record_to_message_repr(conn: ConnRecord) -> Dict[str, Any]:
"""Map ConnRecord onto Connection."""
def _state_map(state: str) -> str:
if state in ('active', 'response'):
return 'active'
Expand All @@ -101,7 +100,6 @@ def _state_map(state: str) -> str:
'my_did': conn.my_did,
'their_did': conn.their_did,
'state': _state_map(conn.state),
'role': conn.their_role,
'connection_id': conn.connection_id,
'raw_repr': conn.serialize()
}
Expand All @@ -122,7 +120,6 @@ def _state_map(state: str) -> str:
required=False
),
'their_did': fields.Str(required=False),
'role': fields.Str(required=False)
}
)

Expand All @@ -147,21 +144,16 @@ class GetListHandler(BaseHandler):
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle get connection list request."""

session = await context.session()
tag_filter = dict(
filter(lambda item: item[1] is not None, {
'my_did': context.message.my_did,
'their_did': context.message.their_did,
}.items())
)
post_filter_positive = dict(filter(
lambda item: item[1] is not None,
{
'their_role': context.message.role
}.items()
))
# TODO: Filter on state (needs mapping back to ACA-Py connection states)
records = await ConnectionRecord.query(
context, tag_filter, post_filter_positive
records = await ConnRecord.query(
session, tag_filter
)
results = [
Connection(**conn_record_to_message_repr(record))
Expand All @@ -179,7 +171,6 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
schema={
'connection_id': fields.Str(required=True),
'label': fields.Str(required=False),
'role': fields.Str(required=False)
}
)

Expand All @@ -190,9 +181,10 @@ class UpdateHandler(BaseHandler):
@admin_only
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle update connection request."""
session = await context.session()
try:
connection = await ConnectionRecord.retrieve_by_id(
context,
connection = await ConnRecord.retrieve_by_id(
session,
context.message.connection_id
)
except StorageNotFoundError:
Expand All @@ -205,8 +197,6 @@ async def handle(self, context: RequestContext, responder: BaseResponder):

new_label = context.message.label or connection.their_label
connection.their_label = new_label
new_role = context.message.role or connection.their_role
connection.their_role = new_role
await connection.save(context, reason="Update request received.")
conn_response = Connection(
**conn_record_to_message_repr(connection)
Expand Down Expand Up @@ -251,9 +241,10 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
await responder.send_reply(report)
return

session = await context.session()
try:
connection = await ConnectionRecord.retrieve_by_id(
context,
connection = await ConnRecord.retrieve_by_id(
session,
context.message.connection_id
)
except StorageNotFoundError:
Expand Down
19 changes: 11 additions & 8 deletions acapy_plugin_toolbox/credential_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

from marshmallow import fields

from aries_cloudagent.config.injection_context import InjectionContext
from aries_cloudagent.core.profile import ProfileSession
from aries_cloudagent.core.protocol_registry import ProtocolRegistry
from aries_cloudagent.messaging.base_handler import BaseHandler, BaseResponder, RequestContext
from aries_cloudagent.messaging.models.base_record import BaseRecord, BaseRecordSchema
from aries_cloudagent.protocols.problem_report.v1_0.message import ProblemReport
from aries_cloudagent.ledger.base import BaseLedger
from aries_cloudagent.issuer.base import BaseIssuer
from aries_cloudagent.indy.issuer import IndyIssuer
from aries_cloudagent.storage.error import StorageNotFoundError
from aries_cloudagent.config.injection_context import InjectionContext
from aries_cloudagent.messaging.util import canon
Expand Down Expand Up @@ -48,12 +48,12 @@


async def setup(
context: InjectionContext,
session: ProfileSession,
protocol_registry: ProblemReport = None
):
"""Setup the cred def plugin."""
if not protocol_registry:
protocol_registry = await context.inject(ProtocolRegistry)
protocol_registry = session.inject(ProtocolRegistry)
protocol_registry.register_message_types(
MESSAGE_TYPES
)
Expand Down Expand Up @@ -168,8 +168,9 @@ class SendCredDefHandler(BaseHandler):
@admin_only
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle received send cred def request."""
ledger: BaseLedger = await context.inject(BaseLedger)
issuer: BaseIssuer = await context.inject(BaseIssuer)
session = await context.session()
ledger: BaseLedger = session.inject(BaseLedger)
issuer: IndyIssuer = session.inject(IndyIssuer)
# If no schema record, make one
try:
schema_record = await SchemaRecord.retrieve_by_schema_id(
Expand Down Expand Up @@ -267,7 +268,8 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
except StorageNotFoundError:
pass

ledger: BaseLedger = await context.inject(BaseLedger)
session = await context.session()
ledger: BaseLedger = session.inject(BaseLedger)
async with ledger:
credential_definition = await ledger.get_credential_definition(
context.message.cred_def_id
Expand Down Expand Up @@ -341,7 +343,8 @@ class CredDefGetListHandler(BaseHandler):
@admin_only
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle get schema list request."""
records = await CredDefRecord.query(context, {})
session = await context.session()
records = await CredDefRecord.query(session, {})
cred_def_list = CredDefList(results=records)
cred_def_list.assign_thread_from(context.message)
await responder.send_reply(cred_def_list)
Loading

0 comments on commit 643a2fd

Please sign in to comment.