Skip to content

Commit ee8262e

Browse files
committed
Finish refactor controllers.
* change 4. tutorials acordingly * TODO: refactor 1. 2. 3. tutorials
1 parent bf1c991 commit ee8262e

File tree

8 files changed

+191
-207
lines changed

8 files changed

+191
-207
lines changed

libs/aries-basic-controller/aries_basic_controller/aries_controller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def init_webhook_server(
6161
async def listen_webhooks(self):
6262
try:
6363
await self.webhook_server.listen_webhooks()
64+
logger.info("Webhook server started.")
6465
except AttributeError:
6566
logger.warning("Missing webhook listener.")
6667
except Exception as exc:

libs/aries-basic-controller/aries_basic_controller/aries_controller_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class AriesAgentControllerBase(ABC):
3636
admin_url : str
3737
The URL for the Admin API
3838
api_key : str
39-
The API key
39+
The API key (default is None)
4040
"""
4141

4242
admin_url: str
43-
api_key: str
43+
api_key: str = None
4444

4545
def __post_init__(self):
4646
"""Constructs additional attributes and logic
@@ -54,7 +54,7 @@ def __post_init__(self):
5454
# Construct headers for Client Session and the session itself
5555
self.headers = {}
5656

57-
if self.api_key not in [None, ""]:
57+
if self.api_key:
5858
self.headers.update({"X-API-Key": self.api_key})
5959

6060
self.client_session: ClientSession = ClientSession(

libs/aries-basic-controller/aries_basic_controller/aries_tenant_controller.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
logger = logging.getLogger("aries_tenant_controller")
99

10+
_required = object()
11+
1012

1113
@dataclass
1214
class AriesTenantController(AriesAgentControllerBase):
@@ -22,14 +24,20 @@ class AriesTenantController(AriesAgentControllerBase):
2224
The tenant JW token
2325
"""
2426

25-
wallet_id: str
26-
tenant_jwt: str
27+
wallet_id: str = _required
28+
tenant_jwt: str = _required
2729

2830
def __post_init__(self):
2931
"""Constructs additional attributes,
3032
and logic defined by attributes set during instantiation
3133
"""
3234

35+
if (self.wallet_id is _required):
36+
raise TypeError("__init__ missing required wallet_id (str)")
37+
38+
if (self.tenant_jwt is _required):
39+
raise TypeError("__init__ missing required tenant_jwt (str)")
40+
3341
super().__post_init__()
3442

3543
if self.tenant_jwt:

tutorials/4. Multitenancy/notebooks/external/Configure External Agent.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"metadata": {},
6161
"outputs": [],
6262
"source": [
63-
"agent_controller.webhook_listener(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT, webhook_base=WEBHOOK_BASE)"
63+
"agent_controller.init_webhook_server(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT, webhook_base=WEBHOOK_BASE)"
6464
]
6565
},
6666
{
@@ -453,8 +453,7 @@
453453
"metadata": {},
454454
"outputs": [],
455455
"source": [
456-
"response = await agent_controller.terminate()\n",
457-
"print(response)"
456+
"await agent_controller.terminate()"
458457
]
459458
},
460459
{

tutorials/4. Multitenancy/notebooks/mediator/Configure Mediator.ipynb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"outputs": [],
7676
"source": [
7777
"# Based on the aca-py agent you wish to control\n",
78-
"agent_controller = AriesAgentController(admin_url=ADMIN_URL, mediation=True)"
78+
"agent_controller = AriesAgentController(admin_url=ADMIN_URL)"
7979
]
8080
},
8181
{
@@ -84,7 +84,7 @@
8484
"metadata": {},
8585
"outputs": [],
8686
"source": [
87-
"agent_controller.webhook_listener(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT, webhook_base=WEBHOOK_BASE)"
87+
"agent_controller.init_webhook_server(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT, webhook_base=WEBHOOK_BASE)"
8888
]
8989
},
9090
{
@@ -107,7 +107,7 @@
107107
"outputs": [],
108108
"source": [
109109
"loop = asyncio.get_event_loop()\n",
110-
"loop.create_task(agent_controller.webhook_listener.listen_webhooks())\n",
110+
"loop.create_task(agent_controller.listen_webhooks())\n",
111111
"\n",
112112
"def connection_handler(payload):\n",
113113
" print(\"Connection Handler Called\")\n",
@@ -199,6 +199,15 @@
199199
" print(\"State\", record[\"state\"])"
200200
]
201201
},
202+
{
203+
"cell_type": "code",
204+
"execution_count": null,
205+
"metadata": {},
206+
"outputs": [],
207+
"source": [
208+
"await agent_controller.connections.accept_connection(record[\"connection_id\"])"
209+
]
210+
},
202211
{
203212
"cell_type": "markdown",
204213
"metadata": {},

0 commit comments

Comments
 (0)