Skip to content

Commit c5719f4

Browse files
committed
Merge branch 'main' into YOMA-257/extra_admin_APIs
2 parents ac977ca + 77dea5a commit c5719f4

File tree

11 files changed

+116
-56
lines changed

11 files changed

+116
-56
lines changed

.github/workflows/create-release-changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
release:
8-
if: startsWith(github.ref, 'refs/tags/')
8+
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event.base_ref == 'refs/heads/main' }}
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Build Changelog

.github/workflows/python-publish.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ on:
99

1010
jobs:
1111
deploy:
12-
12+
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event.base_ref == 'refs/heads/main' }}
1313
runs-on: ubuntu-latest
14-
1514
steps:
1615
- uses: actions/checkout@v2
1716
- name: Set up Python

aries_cloudcontroller/aries_controller.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from .controllers.multitenant import MultitenancyController
66

77
import logging
8+
import ipaddress
89

9-
logger = logging.getLogger("aries_controller")
10+
logger = logging.getLogger(__name__)
1011

1112

1213
@dataclass
@@ -36,35 +37,34 @@ def __post_init__(self):
3637
self.admin_url, self.client_session
3738
)
3839

39-
def init_webhook_server(
40-
self, webhook_host: str = None, webhook_port: int = None, webhook_base: str = ""
40+
async def init_webhook_server(
41+
self, webhook_host: str, webhook_port: int, webhook_base: str = ""
4142
):
42-
"""Create a webhooklisteners
43+
"""Create a webhook listeners
4344
4445
Args:
4546
----
4647
webhook_host : str
47-
The url of the webhook host (default is None)
48+
The url of the webhook host
4849
webhook_port : int
49-
The exposed port for webhooks on the host (default is None)
50+
The exposed port for webhooks on the host
5051
webhook_base : str
5152
The base url for webhooks (default is "")
5253
"""
53-
self.webhook_server: AriesWebhookServer = AriesWebhookServer(
54-
webhook_host=webhook_host,
55-
webhook_port=webhook_port,
56-
webhook_base=webhook_base,
57-
is_multitenant=self.is_multitenant,
58-
)
59-
60-
async def listen_webhooks(self):
54+
assert type(webhook_host) is str
55+
assert ipaddress.ip_address(webhook_host)
56+
assert type(webhook_port) is int
6157
try:
58+
self.webhook_server: AriesWebhookServer = AriesWebhookServer(
59+
webhook_host=webhook_host,
60+
webhook_port=webhook_port,
61+
webhook_base=webhook_base,
62+
is_multitenant=self.is_multitenant,
63+
)
6264
await self.webhook_server.listen_webhooks()
63-
logger.info("Webhook server started.")
64-
except AttributeError:
65-
warning = "Webhook server not initialised."
66-
logger.warning(warning)
67-
raise AttributeError(warning)
65+
logger.info(
66+
f"Webhook server started on {self.webhook_server.webhook_host}."
67+
)
6868
except Exception as exc:
69-
logger.warning(f"Listening webhooks failed! {exc!r} occurred.")
69+
logger.error(f"Listening webhooks failed! {exc!r} occurred.")
7070
raise Exception(f"{exc!r}")

aries_cloudcontroller/aries_controller_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import logging
2525

26-
logger = logging.getLogger("aries_controller")
26+
logger = logging.getLogger(__name__)
2727

2828

2929
@dataclass
@@ -158,8 +158,8 @@ def add_listener(self, listener):
158158
"topic":"topicname" key-value pairs
159159
"""
160160
try:
161-
pub_topic_path = listener["topic"]
162-
print("Subscribing too: " + pub_topic_path)
161+
pub_topic_path = listener['topic']
162+
logger.INFO("Subscribing too: " + pub_topic_path)
163163
pub.subscribe(listener["handler"], pub_topic_path)
164164
logger.debug("Lister added for topic : ", pub_topic_path)
165165
except Exception as exc:

aries_cloudcontroller/aries_tenant_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import logging
77

8-
logger = logging.getLogger("aries_tenant_controller")
8+
logger = logging.getLogger(__name__)
99

1010
_required = object()
1111

aries_cloudcontroller/aries_webhook_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pubsub import pub
77
import logging
88

9-
logger = logging.getLogger("aries_webhook_server")
9+
logger = logging.getLogger(__name__)
1010

1111

1212
@dataclass

aries_cloudcontroller/controllers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ..helpers.utils import log_msg
1616

17-
EVENT_LOGGER = logging.getLogger("event")
17+
EVENT_LOGGER = logging.getLogger("__name__")
1818

1919

2020
class repr_json:

aries_cloudcontroller/controllers/connections.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async def create_invitation(
7777
auto_accept: bool = None,
7878
public: str = None,
7979
multi_use: str = None,
80+
invite_options: {} = None,
8081
):
8182
params = {}
8283
if alias:
@@ -87,10 +88,29 @@ async def create_invitation(
8788
params["public"] = public
8889
if multi_use:
8990
params["multi_use"] = multi_use
90-
91-
invite_details = await self.admin_POST(
92-
"/connections/create-invitation", params=params
93-
)
91+
if invite_options:
92+
"""A dictionary of the form:
93+
{
94+
"mediation_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
95+
"metadata": {},
96+
"recipient_keys": [
97+
"H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
98+
],
99+
"routing_keys": [
100+
"H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
101+
],
102+
"service_endpoint": "http://192.168.56.102:8020"
103+
}
104+
"""
105+
invite_details = await self.admin_POST(
106+
"/connections/create-invitation",
107+
params=params,
108+
json_data=invite_options,
109+
)
110+
else:
111+
invite_details = await self.admin_POST(
112+
"/connections/create-invitation", params=params
113+
)
94114
connection = Connection(invite_details["connection_id"], "invitation")
95115
self.connections.append(connection)
96116
return invite_details

aries_cloudcontroller/controllers/issuer.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,19 @@ async def send_request_for_record(self, cred_ex_id):
126126

127127
# Send holder a credential
128128
async def issue_credential(self, cred_ex_id, comment, attributes):
129-
body = {
130-
"comment": comment,
131-
"credential_preview": {"@type": CRED_PREVIEW, "attributes": attributes},
132-
}
133-
return await self.admin_POST(
134-
f"{self.base_url}/records/{cred_ex_id}/issue", json_data=body
135-
)
129+
try:
130+
body = {
131+
"comment": comment,
132+
"credential_preview": {"@type": CRED_PREVIEW, "attributes": attributes},
133+
}
134+
return await self.admin_POST(
135+
f"{self.base_url}/records/{cred_ex_id}/issue", json_data=body
136+
)
137+
except Exception as e:
138+
exc_msg = f"Could not issue credentials: {e!r}"
139+
logger.warn(exc_msg)
140+
self.send_problem_report(pres_ex_id=self.pres_ex_id, explanation=f"{e!r}")
141+
raise e(exc_msg)
136142

137143
# Store a received credential
138144
async def store_credential(self, cred_ex_id, credential_id: str = None):
@@ -161,7 +167,7 @@ async def remove_record(self, cred_ex_id):
161167
return await self.admin_DELETE(f"{self.base_url}/records/{cred_ex_id}")
162168

163169
# Send a problem report for a credential exchange
164-
async def problem_report(self, cred_ex_id, explanation: str):
170+
async def send_problem_report(self, cred_ex_id, explanation: str):
165171
body = {"explain_ltxt": explanation}
166172

167173
return await self.admin_POST(

aries_cloudcontroller/controllers/proof.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ async def get_presentation_credentials(
8080
)
8181

8282
# Send a problem report for presentation exchange
83-
async def send_problem_report(self, pres_ex_id, request):
83+
async def send_problem_report(self, pres_ex_id, explanation: str):
84+
body = {"explain_ltxt": explanation}
8485
return await self.admin_POST(
85-
f"{self.base_url}/records/{pres_ex_id}/problem-report", json_data=request
86+
f"{self.base_url}/records/{pres_ex_id}/problem-report",
87+
json_data=body,
8688
)
8789

8890
# Sends a proof presentation

tests/test_aries_controller.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class TestAriesAgentController:
1212

1313
admin_url = "0.0.0.0"
14-
webhook_host = ""
14+
webhook_host = "0.0.0.0"
1515
webhook_port = 8000
1616
webhook_base = ""
1717

@@ -42,7 +42,9 @@ async def test_init_args_multi_true(self):
4242
@pytest.mark.asyncio
4343
async def test_init_webhook_server(self):
4444
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
45-
ac.init_webhook_server(self.webhook_host, self.webhook_port, self.webhook_base)
45+
await ac.init_webhook_server(
46+
self.webhook_host, self.webhook_port, self.webhook_base
47+
)
4648
assert type(ac.webhook_server) == AriesWebhookServer
4749
assert ac.webhook_server.webhook_base == self.webhook_base
4850
assert ac.webhook_server.webhook_port == self.webhook_port
@@ -51,22 +53,53 @@ async def test_init_webhook_server(self):
5153
await ac.terminate()
5254

5355
@pytest.mark.asyncio
54-
async def test_listen_webhooks_error(self, caplog):
55-
caplog.set_level(logging.WARNING)
56-
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
57-
with pytest.raises(AttributeError) as ae:
58-
await ac.listen_webhooks()
59-
assert "Webhook server not initialised." in str(ae.value)
60-
assert "Webhook server not initialised." in caplog.text
61-
await ac.terminate()
56+
async def test_init_webhook_server_args_host_type(self):
57+
with pytest.raises(AssertionError):
58+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
59+
await ac.init_webhook_server(
60+
webhook_host=1234, webhook_port=1234, webhook_base=self.webhook_base
61+
)
62+
63+
@pytest.mark.asyncio
64+
async def test_init_webhook_server_invalid_ip(self):
65+
with pytest.raises(
66+
ValueError, match="does not appear to be an IPv4 or IPv6 address"
67+
):
68+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
69+
await ac.init_webhook_server(
70+
webhook_host="12345.123456.1234.0",
71+
webhook_port=1234,
72+
webhook_base=self.webhook_base,
73+
)
74+
75+
@pytest.mark.asyncio
76+
async def test_init_webhook_server_empty_invalid_ip(self):
77+
with pytest.raises(
78+
ValueError, match="does not appear to be an IPv4 or IPv6 address"
79+
):
80+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
81+
await ac.init_webhook_server(
82+
webhook_host="", webhook_port=1234, webhook_base=self.webhook_base
83+
)
84+
85+
@pytest.mark.asyncio
86+
async def test_init_webhook_server_args_port(self):
87+
with pytest.raises(AssertionError):
88+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
89+
await ac.init_webhook_server(
90+
webhook_host=self.webhook_host,
91+
webhook_port="1234",
92+
webhook_base=self.webhook_base,
93+
)
6294

6395
@pytest.mark.asyncio
6496
async def test_init_webhook_server_terminate(self, caplog):
6597
caplog.set_level(logging.INFO)
6698
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
67-
ac.init_webhook_server(self.webhook_host, self.webhook_port, self.webhook_base)
68-
await ac.listen_webhooks()
69-
assert "Webhook server started." in caplog.text
99+
await ac.init_webhook_server(
100+
self.webhook_host, self.webhook_port, self.webhook_base
101+
)
102+
assert "Webhook server started" in caplog.text
70103
res = await ac.webhook_server.terminate()
71104
assert "Webhook server terminated." in caplog.text
72105
assert res is None

0 commit comments

Comments
 (0)