diff --git a/src/sumo/wrapper/_auth_provider.py b/src/sumo/wrapper/_auth_provider.py index 1b45597..dc7a4c3 100644 --- a/src/sumo/wrapper/_auth_provider.py +++ b/src/sumo/wrapper/_auth_provider.py @@ -92,6 +92,11 @@ def store_shared_access_key_for_case(self, case_uuid, token): f.write(token) protect_token_cache(self._resource_id, ".sharedkey", case_uuid) + def has_case_token(self, case_uuid): + return os.path.exists( + get_token_path(self._resource_id, ".sharedkey", case_uuid) + ) + pass diff --git a/src/sumo/wrapper/sumo_client.py b/src/sumo/wrapper/sumo_client.py index b5eddaa..383b198 100644 --- a/src/sumo/wrapper/sumo_client.py +++ b/src/sumo/wrapper/sumo_client.py @@ -424,13 +424,16 @@ def create_shared_access_key_for_case(self, case_uuid): def client_for_case(self, case_uuid): """Instantiate and return new SumoClient for accessing the case identified by *case_uuid*.""" - return SumoClient( - env=self.env, - verbosity=self._verbosity, - retry_strategy=self._retry_strategy, - timeout=self._timeout, - case_uuid=case_uuid, - ) + if self.auth.has_case_token(case_uuid): + return SumoClient( + env=self.env, + verbosity=self._verbosity, + retry_strategy=self._retry_strategy, + timeout=self._timeout, + case_uuid=case_uuid, + ) + else: + return self @raise_for_status_async async def get_async(self, path: str, params: dict = None):