Skip to content

Commit

Permalink
Fix entrypoint with no webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
byewokko committed May 5, 2023
1 parent 08fcc71 commit 6881104
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions seacatauth/cookie/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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()

0 comments on commit 6881104

Please sign in to comment.