Skip to content

Commit

Permalink
Rework debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
athornton committed Aug 2, 2024
1 parent 35099a8 commit e94e901
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions src/mobu/storage/nublado.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,27 +597,34 @@ async def auth_to_hub(self) -> None:
# redirection, because httpx doesn't do that if following redirects
# automatically.
while r.is_redirect:
self._logger.debug(
"Following hub redirect",
method=r.request.method,
original_url=r.request.url.copy_with(
query=None, fragment=None
),
response_url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._lab_xsrf:
if xsrf != self._hub_xsrf:
self._hub_xsrf = xsrf
self._logger.debug(
"Set _hub_xsrf",
url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
next_url = urljoin(url, r.headers["Location"])
r = await self._client.get(next_url, follow_redirects=False)
r.raise_for_status()
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._lab_xsrf:
if xsrf != self._hub_xsrf:
if xsrf and xsrf != self._hub_xsrf:
self._hub_xsrf = xsrf
self._logger.debug(
"Set _hub_xsrf",
url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
next_url = urljoin(url, r.headers["Location"])
r = await self._client.get(next_url, follow_redirects=False)
r.raise_for_status()
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._hub_xsrf:
self._hub_xsrf = xsrf
self._logger.debug(
"Set _hub_xsrf",
url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
elif not self._hub_xsrf:
msg = "No _xsrf cookie set in login reply from JupyterHub"
raise JupyterProtocolError(msg)
Expand Down Expand Up @@ -647,29 +654,36 @@ async def auth_to_lab(self) -> None:
url, headers=headers, follow_redirects=False
)
while r.is_redirect:
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._hub_xsrf:
if xsrf != self._lab_xsrf:
self._lab_xsrf = xsrf
self._logger.debug(
"Set _lab_xsrf",
url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
next_url = urljoin(url, r.headers["Location"])
r = await self._client.get(
next_url, headers=headers, follow_redirects=False
self._logger.debug(
"Following lab redirect",
method=r.request.method,
original_url=r.request.url.copy_with(
query=None, fragment=None
),
response_url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
r.raise_for_status()
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._hub_xsrf:
if xsrf != self._lab_xsrf:
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._lab_xsrf:
self._lab_xsrf = xsrf
self._logger.debug(
"Set _lab_xsrf",
url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
next_url = urljoin(url, r.headers["Location"])
r = await self._client.get(
next_url, headers=headers, follow_redirects=False
)
r.raise_for_status()
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._lab_xsrf:
self._lab_xsrf = xsrf
self._logger.debug(
"Set _lab_xsrf",
url=r.url.copy_with(query=None, fragment=None),
status_code=r.status_code,
)
if not self._lab_xsrf:
msg = "No _xsrf cookie set in login reply from lab"
raise JupyterProtocolError(msg)
Expand Down

0 comments on commit e94e901

Please sign in to comment.