Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow additional endpoints to be specified #276

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,17 @@ def add_arguments(self, parser: ArgumentParser):
"-e",
"--endpoint",
type=str,
nargs="+",
metavar="<endpoint>",
help="Specifies the endpoint to put into invitations and DIDDocs\
help="Specifies the endpoints to put into DIDDocs\
to inform other agents of where they should send messages destined\
for this agent. The endpoint could be one of the specified inbound\
for this agent. Each endpoint could be one of the specified inbound\
transports for this agent, or the endpoint could be that of\
another agent (e.g. 'https://example.com/agent-endpoint') if the\
routing of messages to this agent by a mediator is configured.\
The endpoint is used in the formation of a connection with another agent.",
The first endpoint specified will be used in invitations.\
The endpoints are used in the formation of a connection \
with another agent.",
)

parser.add_argument(
Expand All @@ -643,7 +646,8 @@ def get_settings(self, args: Namespace):
settings["transport.outbound_configs"] = args.outbound_transports

if args.endpoint:
settings["default_endpoint"] = args.endpoint
settings["default_endpoint"] = args.endpoint[0]
settings["additional_endpoints"] = args.endpoint[1:]
if args.label:
settings["default_label"] = args.label
return settings
Expand Down
6 changes: 6 additions & 0 deletions aries_cloudagent/config/tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ async def test_transport_settings(self):
"80",
"--outbound-transport",
"http",
"-e",
"http://default.endpoint/",
"ws://alternate.endpoint/"
]
)

assert result.inbound_transports == [["http", "0.0.0.0", "80"]]
assert result.outbound_transports == ["http"]
assert result.endpoint == ["http://default.endpoint/", "ws://alternate.endpoint/"]

settings = group.get_settings(result)

assert settings.get("transport.inbound_configs") == [["http", "0.0.0.0", "80"]]
assert settings.get("transport.outbound_configs") == ["http"]
assert settings.get("default_endpoint") == "http://default.endpoint/"
assert settings.get("additional_endpoints") == ["ws://alternate.endpoint/"]
30 changes: 19 additions & 11 deletions aries_cloudagent/protocols/connections/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from typing import Tuple
from typing import Tuple, List

from ...cache.base import BaseCache
from ...connections.models.connection_record import ConnectionRecord
Expand Down Expand Up @@ -271,9 +271,10 @@ async def create_request(

# Create connection request message
if not my_endpoint:
my_endpoint = self.context.settings.get("default_endpoint")
my_endpoints = [self.context.settings.get("default_endpoint")]
my_endpoints.extend(self.context.settings.get("additional_endpoints"))
did_doc = await self.create_did_document(
my_info, connection.inbound_connection_id, my_endpoint
my_info, connection.inbound_connection_id, my_endpoints
)
if not my_label:
my_label = self.context.settings.get("default_label")
Expand Down Expand Up @@ -450,9 +451,10 @@ async def create_response(

# Create connection response message
if not my_endpoint:
my_endpoint = self.context.settings.get("default_endpoint")
my_endpoints = [self.context.settings.get("default_endpoint")]
my_endpoints.extend(self.context.settings.get("additional_endpoints"))
did_doc = await self.create_did_document(
my_info, connection.inbound_connection_id, my_endpoint
my_info, connection.inbound_connection_id, my_endpoints
)
response = ConnectionResponse(
connection=ConnectionDetail(did=my_info.did, did_doc=did_doc)
Expand Down Expand Up @@ -608,7 +610,7 @@ async def create_static_connection(
await connection.save(self.context, reason="Created new static connection")

# Synthesize their DID doc
did_doc = await self.create_did_document(their_info, None, their_endpoint)
did_doc = await self.create_did_document(their_info, None, [their_endpoint])
await self.store_did_document(did_doc)

return connection
Expand Down Expand Up @@ -778,14 +780,14 @@ async def create_did_document(
self,
did_info: DIDInfo,
inbound_connection_id: str = None,
svc_endpoint: str = None,
svc_endpoints: List[str] = [],
) -> DIDDoc:
"""Create our DID document for a given DID.

Args:
did_info: The DID information (DID and verkey) used in the connection
inbound_connection_id: The ID of the inbound routing connection to use
svc_endpoint: A custom endpoint for the DID Document
svc_endpoints: Custom endpoints for the DID Document

Returns:
The prepared `DIDDoc` instance
Expand Down Expand Up @@ -838,13 +840,19 @@ async def create_did_document(
True,
)
routing_keys.append(rk)
svc_endpoint = service.endpoint
svc_endpoint = [service.endpoint]
break
router_id = router.inbound_connection_id

if svc_endpoint:
for endpoint_index, svc_endpoint in enumerate(svc_endpoints):
endpoint_ident = "indy" if endpoint_index == 0 else f'indy{endpoint_index}'
service = Service(
did_info.did, "indy", "IndyAgent", [pk], routing_keys, svc_endpoint
did_info.did,
endpoint_ident,
"IndyAgent",
[pk],
routing_keys,
svc_endpoint
)
did_doc.set(service)

Expand Down