Skip to content

Commit

Permalink
refactor: use constants for mediation metadata strings
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Feb 22, 2022
1 parent d00050f commit 7bd1391
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
"""Connection request handler."""

from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
RequestContext,
)
from .....connections.models.conn_record import ConnRecord

from .....messaging.base_handler import BaseHandler, BaseResponder, RequestContext
from ....coordinate_mediation.v1_0.manager import MediationManager
from ..manager import ConnectionManager, ConnectionManagerError
from ..messages.connection_request import ConnectionRequest
from ..messages.problem_report import ConnectionProblemReport
Expand All @@ -30,19 +26,19 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
profile = context.profile
mgr = ConnectionManager(profile)

mediation_id = None
if context.connection_record:
async with profile.session() as session:
mediation_metadata = await context.connection_record.metadata_get(
session, "mediation", {}
session, MediationManager.METADATA_KEY, {}
)
else:
mediation_metadata = {}
mediation_id = mediation_metadata.get(MediationManager.METADATA_ID)

try:
connection = await mgr.receive_request(
context.message,
context.message_receipt,
mediation_id=mediation_metadata.get("id"),
mediation_id=mediation_id,
)

if connection.accept == ConnRecord.ACCEPT_AUTO:
Expand Down
4 changes: 3 additions & 1 deletion aries_cloudagent/protocols/connections/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ async def create_invitation(
# Save that this invitation was created with mediation
async with self.profile.session() as session:
await connection.metadata_set(
session, "mediation", {"id": mediation_record.mediation_id}
session,
MediationManager.METADATA_KEY,
{MediationManager.METADATA_ID: mediation_record.mediation_id},
)

if keylist_updates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class MediationManager:
DEFAULT_MEDIATOR_RECORD_TYPE = "default_mediator"
SEND_REQ_AFTER_CONNECTION = "send_mediation_request_on_connection"
SET_TO_DEFAULT_ON_GRANTED = "set_to_default_on_granted"
METADATA_KEY = "mediation"
METADATA_ID = "id"

def __init__(self, profile: Profile):
"""Initialize Mediation Manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from .....connections.models.conn_record import ConnRecord
from .....messaging.base_handler import BaseHandler, BaseResponder, RequestContext

from ....coordinate_mediation.v1_0.manager import MediationManager
from ....problem_report.v1_0.message import ProblemReport

from ..manager import DIDXManager, DIDXManagerError
from ..messages.request import DIDXRequest

Expand All @@ -27,15 +26,14 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
profile = context.profile
mgr = DIDXManager(profile)

mediation_id = None
if context.connection_record:
async with profile.session() as session:
mediation_metadata = await context.connection_record.metadata_get(
session, "mediation", {}
session, MediationManager.METADATA_KEY, {}
)
else:
mediation_metadata = {}
mediation_id = mediation_metadata.get(MediationManager.METADATA_ID)

mediation_id = mediation_metadata.get("id")
try:
conn_rec = await mgr.receive_request(
request=context.message,
Expand Down
4 changes: 3 additions & 1 deletion aries_cloudagent/protocols/out_of_band/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ async def create_invitation(

async with self.profile.session() as session:
await conn_rec.metadata_set(
session, "mediation", {"id": mediation_record.mediation_id}
session,
MediationManager.METADATA_KEY,
{MediationManager.METADATA_ID: mediation_record.mediation_id},
)

if keylist_updates:
Expand Down

0 comments on commit 7bd1391

Please sign in to comment.