Skip to content

Commit d2d2160

Browse files
committed
Refactor endpoint initialisation loop
This change refactors the endpoint initialisation, swapping list comprehensions and functional loops to a more traditional sequential style. This allows for improved error handling and much better readability.
1 parent ce35d80 commit d2d2160

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

capi_janitor/openstack/openstack.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,18 @@ async def __aenter__(self):
187187
return self
188188
else:
189189
raise
190-
self._endpoints = {
191-
entry["type"]: next(
192-
ep["url"]
193-
for ep in entry["endpoints"]
190+
self._endpoints = {}
191+
for entry in response.json()["catalog"]:
192+
if not entry["endpoints"]:
193+
continue
194+
195+
for ep in entry["endpoints"]:
194196
if (
195-
ep["interface"] == self._interface
196-
and (not self._region or ep["region"] == self._region)
197-
)
198-
)
199-
for entry in response.json()["catalog"]
200-
if len(entry["endpoints"]) > 0
201-
}
197+
ep.get("interface") == self._interface
198+
and (not self._region or ep.get("region_id") == self._region)
199+
):
200+
self._endpoints[entry["type"]] = ep["url"]
201+
break
202202
return self
203203

204204
async def __aexit__(self, exc_type, exc_value, traceback):

0 commit comments

Comments
 (0)