Skip to content

Commit

Permalink
Merge pull request #201 from TeskaLabs/fix/cookie-entry
Browse files Browse the repository at this point in the history
Fix entrypoint with no webhook
  • Loading branch information
byewokko authored May 5, 2023
2 parents 08fcc71 + 722e73b commit 99edc6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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 99edc6e

Please sign in to comment.