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

Feature/aca py 0.7.3rc0 #116

Merged
merged 5 commits into from
Dec 16, 2021
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
5 changes: 3 additions & 2 deletions acapy_plugin_toolbox/basicmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def basic_message_event_handler(profile: Profile, event: Event):
responder = profile.inject(BaseResponder)
async with profile.session() as session:
await msg.save(session, reason="New message")
await send_to_admins(session, notification, responder, to_session_only=True)
await send_to_admins(profile, notification, responder, to_session_only=True)


class BasicMessageRecord(BaseRecord):
Expand Down Expand Up @@ -284,6 +284,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle received send requests."""
# pylint: disable=protected-access
session = await context.session()
profile = context.profile
try:
connection = await ConnRecord.retrieve_by_id(
session, context.message.connection_id
Expand All @@ -303,7 +304,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):

# Need to use a connection target, reply_to_verkey, and reply_from_verkey
# if we want to send to a socket
conn_mgr = ConnectionManager(session)
conn_mgr = ConnectionManager(profile)
targets = await conn_mgr.get_connection_targets(connection=connection)
assert isinstance(targets, list)
assert targets
Expand Down
11 changes: 5 additions & 6 deletions acapy_plugin_toolbox/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ async def connections_event_handler(profile: Profile, event: Event):
record: ConnRecord = ConnRecord.deserialize(event.payload)
if record.state == ConnRecord.State.RESPONSE:
responder = profile.inject(BaseResponder)
async with profile.session() as session:
await send_to_admins(
session, Connected(**conn_record_to_message_repr(record)), responder
)
await send_to_admins(
profile, Connected(**conn_record_to_message_repr(record)), responder
)


BaseConnectionSchema = Schema.from_dict(
Expand Down Expand Up @@ -289,8 +288,8 @@ class ReceiveInvitationHandler(BaseHandler):
@admin_only
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle recieve invitation request."""
session = await context.session()
connection_mgr = ConnectionManager(session)
profile = context.profile
connection_mgr = ConnectionManager(profile)
invitation = ConnectionInvitation.from_url(context.message.invitation)
connection = await connection_mgr.receive_invitation(
invitation,
Expand Down
6 changes: 2 additions & 4 deletions acapy_plugin_toolbox/holder/v0_1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ async def issue_credential_event_handler(profile: Profile, event: Event):
message = CredReceived(record=record)
LOGGER.debug("Prepared Message: %s", message.serialize())

async with profile.session() as session:
await send_to_admins(session, message, responder)
await send_to_admins(profile, message, responder)


async def present_proof_event_handler(profile: Profile, event: Event):
Expand All @@ -144,5 +143,4 @@ async def present_proof_event_handler(profile: Profile, event: Event):
message: PresRequestReceived = PresRequestReceived(record)
LOGGER.debug("Prepared Message: %s", message.serialize())
await message.retrieve_matching_credentials(profile)
async with profile.session() as session:
await send_to_admins(session, message, responder)
await send_to_admins(profile, message, responder)
2 changes: 2 additions & 0 deletions acapy_plugin_toolbox/http_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self, host: str, port: int, create_session, **kwargs) -> None:
inbound_http_message_handler = http.HttpTransport.inbound_message_handler
start = http.HttpTransport.start
stop = http.HttpTransport.stop
heartbeat_interval = None
timout_interval = None

async def make_application(self) -> web.Application:
"""Construct the aiohttp application."""
Expand Down
3 changes: 2 additions & 1 deletion acapy_plugin_toolbox/invitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class CreateInvitationHandler(BaseHandler):
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle create invitation request."""
session = await context.session()
connection_mgr = ConnectionManager(session)
profile = context.profile
connection_mgr = ConnectionManager(profile)
connection, invitation = await connection_mgr.create_invitation(
my_label=context.message.label,
auto_accept=context.message.auto_accept,
Expand Down
3 changes: 1 addition & 2 deletions acapy_plugin_toolbox/trustping.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ async def setup(context: InjectionContext, protocol_registry: ProtocolRegistry =
async def trust_ping_response_received(profile: Profile, event: Event):
message = ResponseReceived(connection_id=event.payload["connection_id"])
responder = profile.inject(BaseResponder)
async with profile.session() as session:
await send_to_admins(session, message, responder)
await send_to_admins(profile, message, responder)


ResponseReceived, ResponseReceivedSchema = generate_model_schema(
Expand Down
9 changes: 5 additions & 4 deletions acapy_plugin_toolbox/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from aries_cloudagent.protocols.connections.v1_0.manager import ConnectionManager
from aries_cloudagent.storage.base import BaseStorage
from aries_cloudagent.storage.error import StorageNotFoundError
from aries_cloudagent.core.profile import ProfileSession
from aries_cloudagent.core.profile import ProfileSession, Profile
from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema
from aries_cloudagent.messaging.base_handler import (
BaseHandler,
Expand Down Expand Up @@ -363,16 +363,17 @@ async def admin_connections(session: ProfileSession):


async def send_to_admins(
session: ProfileSession,
profile: Profile,
message: AgentMessage,
responder: BaseResponder,
to_session_only: bool = False,
):
"""Send a message to all admin connections."""
LOGGER.info("Sending message to admins: %s", message.serialize())
admins = await admin_connections(session)
async with profile.session() as session:
admins = await admin_connections(session)
admins = list(filter(lambda admin: admin.state == "active", admins))
connection_mgr = ConnectionManager(session)
connection_mgr = ConnectionManager(profile)
admin_targets = [
(admin, target)
for admin in admins
Expand Down
13 changes: 8 additions & 5 deletions int/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,14 @@ async def endorser_did(make_did, backchannel, accepted_taa):
"""Endorser DID factory fixture"""
did: DID = await make_did()
LOGGER.info("Publishing DID through https://selfserve.indiciotech.io")
response = httpx.post(
url="https://selfserve.indiciotech.io/nym",
json={"network": "testnet", "did": did.did, "verkey": did.verkey},
timeout=15,
)
try:
response = httpx.post(
url="https://selfserve.indiciotech.io/nym",
json={"network": "testnet", "did": did.did, "verkey": did.verkey},
timeout=15,
)
except httpx.ReadTimeout as err:
raise Exception("Failed to publish DID: {0}".format(err))
if response.is_error:
raise Exception("Failed to publish DID:", response.text)

Expand Down
5 changes: 4 additions & 1 deletion int/tests/test_basicmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ async def test_new(connection: StaticConnection):


@pytest.mark.asyncio
async def test_get(connection: StaticConnection, connection_id: str):
async def test_get(
connection: StaticConnection, connection_id: str, echo, echo_connection
):
"""Send multiple messages and verify that the proper count and content appears in messages list"""
test_content = ("Are you suggesting coconuts migrate?", "'Tis but a flesh wound.")
for content in test_content:
Expand All @@ -116,6 +118,7 @@ async def test_get(connection: StaticConnection, connection_id: str):
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/get"
}
)
await echo.get_messages(echo_connection)
assert (
get_messages["@type"]
== "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/messages"
Expand Down
1 change: 0 additions & 1 deletion int/tests/test_invitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async def test_create_invitation(connection):
},
return_route="all",
)
print(reply)
assert (
reply["@type"]
== "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-invitations/0.1/invitation"
Expand Down
Loading