Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/sumo/wrapper/_auth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
from urllib.parse import parse_qs

import httpx
import jwt
import msal
import tenacity as tn
Expand Down Expand Up @@ -90,6 +91,14 @@ def store_shared_access_key_for_case(self, case_uuid, token):
f.write(token)
protect_token_cache(self._resource_id, ".sharedkey", case_uuid)

def _store_fallback_auth(self, sumo_client):
sync_client = sumo_client._client
if sync_client is None:
sumo_client._client = httpx.Client()
token = sumo_client.get("/createfallbackauth").text
self.store_shared_access_key_for_case("fallback", token)
sumo_client._client = sync_client

def store_fallback_auth(self, sumo_client):
return

Expand Down Expand Up @@ -119,8 +128,7 @@ def __init__(self, client_id, authority, resource_id):
self._scope = scope_for_resource(resource_id)

def store_fallback_auth(self, sumo_client):
token = sumo_client.get("/createfallbackauth").text
self.store_shared_access_key_for_case("fallback", token)
self._store_fallback_auth(sumo_client)


class AuthProviderAccessToken(AuthProvider):
Expand Down Expand Up @@ -276,8 +284,7 @@ def login(self):
return

def store_fallback_auth(self, sumo_client):
token = sumo_client.get("/createfallbackauth").text
self.store_shared_access_key_for_case("fallback", token)
self._store_fallback_auth(sumo_client)


class AuthProviderDeviceCode(AuthProvider):
Expand Down
8 changes: 3 additions & 5 deletions src/sumo/wrapper/sumo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,11 @@ def _get():

self.base_url = base_url

sync_client = self._client
if sync_client is None:
self._client = httpx.Client()
self.auth.store_fallback_auth(self)
self._client = sync_client
with contextlib.suppress(Exception):
Comment thread
rwiker marked this conversation as resolved.
self.auth.store_fallback_auth(self)

def __enter__(self):

return self

def __exit__(self, *_):
Expand Down