Skip to content

Commit

Permalink
only consider aiohttp.ClientResponse instances when collecting respon…
Browse files Browse the repository at this point in the history
…ses related to a session

Signed-off-by: Steven Armstrong <[email protected]>
  • Loading branch information
asteven committed Mar 18, 2024
1 parent 3ddc96c commit be20ea5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kopf/_cogs/clients/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ async def wrapper(*args: Any, **kwargs: Any) -> Any:
if 'context' in kwargs:
context = kwargs['context']
response = await fn(*args, **kwargs)
# Keep track of responses which are using this context.
context.add_response(response)
if isinstance(response, aiohttp.ClientResponse):
# Keep track of responses which are using this context.
context.add_response(response)
return response

# Otherwise, attempt the execution with the vault credentials and re-authenticate on 401s.
vault: credentials.Vault = vault_var.get()
async for key, info, context in vault.extended(APIContext, 'contexts'):
try:
response = await fn(*args, **kwargs, context=context)
# Keep track of responses which are using this context.
context.add_response(response)
if isinstance(response, aiohttp.ClientResponse):
# Keep track of responses which are using this context.
context.add_response(response)
return response
except errors.APIUnauthorizedError as e:
await vault.invalidate(key, exc=e)
Expand Down

0 comments on commit be20ea5

Please sign in to comment.