Skip to content

Commit 80d84f8

Browse files
committed
Merge branch 'main' into improvement/test_controllers
2 parents 30e459f + b729fcd commit 80d84f8

34 files changed

+1109
-484
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ dist
44
*.egg-info
55
build
66
.env
7-
.ipynb_checkpoints/
87
.venv
9-
.vscode/
8+
.pytest_cache/*
109
__pycache__/
10+
.vscode/
11+
.coverage

aries_cloudcontroller/aries_controller.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ def __post_init__(self):
3333

3434
if self.is_multitenant:
3535
self.multitenant = MultitenancyController(
36-
self.admin_url,
37-
self.client_session)
36+
self.admin_url, self.client_session
37+
)
3838

3939
def init_webhook_server(
40-
self,
41-
webhook_host: str = None,
42-
webhook_port: int = None,
43-
webhook_base: str = ""):
40+
self, webhook_host: str = None, webhook_port: int = None, webhook_base: str = ""
41+
):
4442
"""Create a webhooklisteners
4543
4644
Args:
@@ -56,7 +54,8 @@ def init_webhook_server(
5654
webhook_host=webhook_host,
5755
webhook_port=webhook_port,
5856
webhook_base=webhook_base,
59-
is_multitenant=self.is_multitenant)
57+
is_multitenant=self.is_multitenant,
58+
)
6059

6160
async def listen_webhooks(self):
6261
try:
@@ -67,6 +66,5 @@ async def listen_webhooks(self):
6766
logger.warning(warning)
6867
raise AttributeError(warning)
6968
except Exception as exc:
70-
logger.warning(
71-
f"Listening webhooks failed! {exc!r} occurred.")
69+
logger.warning(f"Listening webhooks failed! {exc!r} occurred.")
7270
raise Exception(f"{exc!r}")

aries_cloudcontroller/aries_controller_base.py

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -57,69 +57,42 @@ def __post_init__(self):
5757
if self.api_key:
5858
self.headers.update({"X-API-Key": self.api_key})
5959

60-
self.client_session: ClientSession = ClientSession(
61-
headers=self.headers)
60+
self.client_session: ClientSession = ClientSession(headers=self.headers)
6261

6362
# Instantiate controllers
64-
self.connections = ConnectionsController(
65-
self.admin_url,
66-
self.client_session)
63+
self.connections = ConnectionsController(self.admin_url, self.client_session)
6764

68-
self.messaging = MessagingController(
69-
self.admin_url,
70-
self.client_session)
65+
self.messaging = MessagingController(self.admin_url, self.client_session)
7166

72-
self.proofs = ProofController(
73-
self.admin_url,
74-
self.client_session)
67+
self.proofs = ProofController(self.admin_url, self.client_session)
7568

76-
self.ledger = LedgerController(
77-
self.admin_url,
78-
self.client_session)
69+
self.ledger = LedgerController(self.admin_url, self.client_session)
7970

80-
self.credentials = CredentialController(
81-
self.admin_url,
82-
self.client_session)
71+
self.credentials = CredentialController(self.admin_url, self.client_session)
8372

84-
self.server = ServerController(
85-
self.admin_url,
86-
self.client_session)
73+
self.server = ServerController(self.admin_url, self.client_session)
8774

88-
self.oob = OOBController(
89-
self.admin_url,
90-
self.client_session)
75+
self.oob = OOBController(self.admin_url, self.client_session)
9176

92-
self.mediation = MediationController(
93-
self.admin_url,
94-
self.client_session)
77+
self.mediation = MediationController(self.admin_url, self.client_session)
9578

96-
self.schema = SchemaController(
97-
self.admin_url,
98-
self.client_session)
79+
self.schema = SchemaController(self.admin_url, self.client_session)
9980

100-
self.wallet = WalletController(
101-
self.admin_url,
102-
self.client_session)
81+
self.wallet = WalletController(self.admin_url, self.client_session)
10382

104-
self.definitions = DefinitionsController(
105-
self.admin_url,
106-
self.client_session)
83+
self.definitions = DefinitionsController(self.admin_url, self.client_session)
10784

10885
self.issuer = IssuerController(
10986
self.admin_url,
11087
self.client_session,
11188
self.connections,
11289
self.wallet,
113-
self.definitions)
90+
self.definitions,
91+
)
11492

115-
self.action_menu = ActionMenuController(
116-
self.admin_url,
117-
self.client_session)
93+
self.action_menu = ActionMenuController(self.admin_url, self.client_session)
11894

119-
self.revocations = RevocationController(
120-
self.admin_url,
121-
self.client_session
122-
)
95+
self.revocations = RevocationController(self.admin_url, self.client_session)
12396

12497
def init_webhook_server(self):
12598
raise NotImplementedError
@@ -140,9 +113,9 @@ def remove_api_key(self):
140113
"""Removes the API key attribute and corresponding headers
141114
from the Client Session"""
142115
self.api_key = None
143-
if 'X-API-Key' in self.client_session.headers:
144-
del self.client_session.headers['X-API-Key']
145-
del self.headers['X-API-Key']
116+
if "X-API-Key" in self.client_session.headers:
117+
del self.client_session.headers["X-API-Key"]
118+
del self.headers["X-API-Key"]
146119

147120
def register_listeners(self, listeners, defaults=True):
148121
"""Registers the webhook listners
@@ -161,23 +134,16 @@ def register_listeners(self, listeners, defaults=True):
161134
# If so lets do it consistently
162135
if defaults:
163136
if self.connections:
164-
pub.subscribe(
165-
self.connections.default_handler,
166-
"connections")
137+
pub.subscribe(self.connections.default_handler, "connections")
167138
if self.messaging:
168-
pub.subscribe(
169-
self.messaging.default_handler,
170-
"basicmessages")
139+
pub.subscribe(self.messaging.default_handler, "basicmessages")
171140
if self.proofs:
172-
pub.subscribe(
173-
self.proofs.default_handler,
174-
"present_proof")
141+
pub.subscribe(self.proofs.default_handler, "present_proof")
175142

176143
for listener in listeners:
177144
self.add_listener(listener)
178145
except Exception as exc:
179-
logger.warning(
180-
f"Register webhooks listeners failed! {exc!r} occurred.")
146+
logger.warning(f"Register webhooks listeners failed! {exc!r} occurred.")
181147

182148
def add_listener(self, listener):
183149
"""Subscribe to a listeners for a topic
@@ -189,13 +155,12 @@ def add_listener(self, listener):
189155
"topic":"topicname" key-value pairs
190156
"""
191157
try:
192-
pub_topic_path = listener['topic']
158+
pub_topic_path = listener["topic"]
193159
print("Subscribing too: " + pub_topic_path)
194160
pub.subscribe(listener["handler"], pub_topic_path)
195161
logger.debug("Lister added for topic : ", pub_topic_path)
196162
except Exception as exc:
197-
logger.warning(
198-
f"Adding webhooks listener failed! {exc!r} occurred.")
163+
logger.warning(f"Adding webhooks listener failed! {exc!r} occurred.")
199164

200165
def remove_listener(self, listener):
201166
"""Remove a listener for a topic
@@ -212,8 +177,7 @@ def remove_listener(self, listener):
212177
else:
213178
logger.debug("Listener not subscribed", listener)
214179
except Exception as exc:
215-
logger.warning(
216-
f"Removing webhooks listener failed! {exc!r} occurred.")
180+
logger.warning(f"Removing webhooks listener failed! {exc!r} occurred.")
217181

218182
def remove_all_listeners(self, topic: str = None):
219183
"""Remove all listeners for one or all topics
@@ -230,8 +194,7 @@ def remove_all_listeners(self, topic: str = None):
230194
try:
231195
pub.unsubAll(topicName=topic)
232196
except Exception as exc:
233-
logger.warning(
234-
f"Removing all webhooks listeners failed! {exc!r} occurred.")
197+
logger.warning(f"Removing all webhooks listeners failed! {exc!r} occurred.")
235198

236199
async def listen_webhooks(self):
237200
raise NotImplementedError
@@ -246,4 +209,5 @@ async def terminate(self):
246209
return
247210
except Exception as exc:
248211
logger.warning(
249-
f"Terminate webhooks listener exception!\n {exc!r} occurred.")
212+
f"Terminate webhooks listener exception!\n {exc!r} occurred."
213+
)

aries_cloudcontroller/aries_tenant_controller.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,40 @@ def __post_init__(self):
3232
and logic defined by attributes set during instantiation
3333
"""
3434

35-
if (self.wallet_id is _required):
35+
if self.wallet_id is _required:
3636
raise TypeError("__init__ missing required wallet_id (str)")
3737

38-
if (self.tenant_jwt is _required):
38+
if self.tenant_jwt is _required:
3939
raise TypeError("__init__ missing required tenant_jwt (str)")
4040

4141
super().__post_init__()
4242

4343
if self.tenant_jwt:
4444
self.headers.update(
45-
{'Authorization': 'Bearer ' + self.tenant_jwt,
46-
'content-type': "application/json"})
45+
{
46+
"Authorization": "Bearer " + self.tenant_jwt,
47+
"content-type": "application/json",
48+
}
49+
)
4750

4851
# Update the current client session instantiated in the parent class
4952
self.client_session.headers.update(self.headers)
5053

5154
def init_webhook_server(self):
5255
raise NotImplementedError(
53-
("Please, use an AriesAgentController to start a webhook server\n"
54-
"Webhook server fct is disallowed for tenant controllers."))
56+
(
57+
"Please, use an AriesAgentController to start a webhook server\n"
58+
"Webhook server fct is disallowed for tenant controllers."
59+
)
60+
)
5561

5662
def listen_webhooks(self):
5763
raise NotImplementedError(
58-
("Please, use an AriesAgentController to start a webhook server\n"
59-
"Webhook server fct is disallowed for tenant controllers."))
64+
(
65+
"Please, use an AriesAgentController to start a webhook server\n"
66+
"Webhook server fct is disallowed for tenant controllers."
67+
)
68+
)
6069

6170
def add_listener(self, listener):
6271
"""Subscribe to a listeners for a topic
@@ -71,18 +80,17 @@ def add_listener(self, listener):
7180
"topic":"topicname" key-value pairs
7281
"""
7382
try:
74-
assert (type(wallet_id) is str), "wallet_id must be a string"
75-
assert (wallet_id.__ne__("")), "Cannot add listener for empty wallet_id."
76-
pub_topic_path_base = listener['topic']
83+
assert type(wallet_id) is str, "wallet_id must be a string"
84+
assert wallet_id.__ne__(""), "Cannot add listener for empty wallet_id."
85+
pub_topic_path_base = listener["topic"]
7786
pub_topic_path = f"{self.wallet_id}.{pub_topic_path_base}"
7887
pub.subscribe(listener["handler"], pub_topic_path)
7988
logger.debug("Lister added for topic : ", pub_topic_path)
8089
except AssertionError as err:
8190
logger.error(err)
8291
raise
8392
except Exception as exc:
84-
logger.warning(
85-
f"Adding webhooks listener failed! {exc!r} occurred.")
93+
logger.warning(f"Adding webhooks listener failed! {exc!r} occurred.")
8694
raise
8795

8896
def update_wallet_id(self, wallet_id: str):
@@ -95,8 +103,8 @@ def update_wallet_id(self, wallet_id: str):
95103
The tenant wallet identifier
96104
"""
97105
try:
98-
assert (type(wallet_id) is str), "wallet_id must be a string"
99-
assert (wallet_id.__ne__("")), "wallet_id must not be empty"
106+
assert type(wallet_id) is str, "wallet_id must be a string"
107+
assert wallet_id.__ne__(""), "wallet_id must not be empty"
100108
self.wallet_id = wallet_id
101109
except AssertionError as err:
102110
logger.info(f"{err!r}")
@@ -113,35 +121,35 @@ def update_tenant_jwt(self, tenant_jwt: str, wallet_id: str):
113121
The tenant wallet identifier
114122
"""
115123
try:
116-
assert (type(tenant_jwt) is str), "tenant_jwt must be a string"
117-
assert (tenant_jwt.__ne__("")), "tenant_jwt must not be empty"
124+
assert type(tenant_jwt) is str, "tenant_jwt must be a string"
125+
assert tenant_jwt.__ne__(""), "tenant_jwt must not be empty"
118126
self.tenant_jwt = tenant_jwt
119127
self.update_wallet_id(wallet_id)
120128
self.headers.update(
121-
{'Authorization': 'Bearer ' + tenant_jwt,
122-
'content-type': "application/json"})
129+
{
130+
"Authorization": "Bearer " + tenant_jwt,
131+
"content-type": "application/json",
132+
}
133+
)
123134
self.client_session.headers.update(self.headers)
124135
except AssertionError as err:
125136
logger.info(f"{err!r}")
126137
raise
127138
except Exception as exc:
128-
logger.warning(
129-
(f"Updating tenant JW token"
130-
f" failed! {exc!r} occurred."))
139+
logger.warning((f"Updating tenant JW token" f" failed! {exc!r} occurred."))
131140
raise
132141

133142
def remove_tenant_jwt(self):
134143
"""Removes the tenant's JW Token attribute and corresponding
135144
headers from the Client Session"""
136145
try:
137146
self.tenant_jwt = None
138-
if 'Authorization' in self.client_session.headers:
139-
del self.client_session.headers['Authorization']
140-
del self.headers['Authorization']
141-
if 'content-type' in self.client_session.headers:
142-
del self.client_session.headers['content-type']
143-
del self.headers['content-type']
147+
if "Authorization" in self.client_session.headers:
148+
del self.client_session.headers["Authorization"]
149+
del self.headers["Authorization"]
150+
if "content-type" in self.client_session.headers:
151+
del self.client_session.headers["content-type"]
152+
del self.headers["content-type"]
144153
except Exception as exc:
145-
logger.warning(
146-
f"Removing JW token failed! {exc!r} occurred.")
154+
logger.warning(f"Removing JW token failed! {exc!r} occurred.")
147155
raise

0 commit comments

Comments
 (0)