From 68811046a7ed309e3328ecd8851aee3818467ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Hru=C5=A1ka?= Date: Fri, 5 May 2023 17:02:16 +0200 Subject: [PATCH 1/2] Fix entrypoint with no webhook --- seacatauth/cookie/handler.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/seacatauth/cookie/handler.py b/seacatauth/cookie/handler.py index 44d449ba..0ec70ce5 100644 --- a/seacatauth/cookie/handler.py +++ b/seacatauth/cookie/handler.py @@ -262,7 +262,8 @@ async def nginx_anonymous(self, request): # Trigger webhook and add custom HTTP headers try: data = await self._fetch_webhook_data(client, session) - response.headers.update(data.get("response_headers", {})) + if data is not None: + response.headers.update(data.get("response_headers", {})) except exceptions.ClientResponseError as e: L.error("Webhook responded with error.", struct_data={ "status": e.Status, "text": e.Data}) @@ -427,7 +428,8 @@ async def _bouncer(self, request, parameters): # Trigger webhook and set custom client response headers try: data = await self._fetch_webhook_data(client, session) - response.headers.update(data.get("response_headers", {})) + if data is not None: + response.headers.update(data.get("response_headers", {})) except exceptions.ClientResponseError as e: L.error("Webhook responded with error.", struct_data={ "status": e.Status, "text": e.Data}) @@ -458,14 +460,15 @@ async def _fetch_webhook_data(self, client, session): ``` """ cookie_webhook_uri = client.get("cookie_webhook_uri") - if cookie_webhook_uri is not None: - async with aiohttp.ClientSession() as http_session: - # TODO: Better serialization - userinfo = await self.CookieService.OpenIdConnectService.build_userinfo(session) - data = asab.web.rest.json.JSONDumper(pretty=False)(userinfo) - async with http_session.put(cookie_webhook_uri, data=data, headers={ - "Content-Type": "application/json"}) as resp: - if resp.status != 200: - text = await resp.text() - raise exceptions.ClientResponseError(resp.status, text) - return await resp.json() + if cookie_webhook_uri is None: + return None + async with aiohttp.ClientSession() as http_session: + # TODO: Better serialization + userinfo = await self.CookieService.OpenIdConnectService.build_userinfo(session) + data = asab.web.rest.json.JSONDumper(pretty=False)(userinfo) + async with http_session.put(cookie_webhook_uri, data=data, headers={ + "Content-Type": "application/json"}) as resp: + if resp.status != 200: + text = await resp.text() + raise exceptions.ClientResponseError(resp.status, text) + return await resp.json() From 722e73b0d87eda471109b9ee20676444422af7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Hru=C5=A1ka?= Date: Fri, 5 May 2023 17:03:10 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7b6189b..c119eeb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Reintroduce metrics (#198, PLUM Sprint 230421) - Allow batman to be configured without basic auth (#199, PLUM Sprint 230421) - Include client cookie name in client detail (#200, PLUM Sprint 230421) +- Fix cookie entrypoint when no webhook is configured (#201, PLUM Sprint 230421) ### Features - Filter resource list by resource type using the `exclude` query parameter (#196, PLUM Sprint 230421)