From 41803b8d805a2f2917bfdc80d1062ed50d2ff454 Mon Sep 17 00:00:00 2001 From: Sven Marnach Date: Tue, 30 Jul 2024 14:15:56 +0200 Subject: [PATCH] bug-1909870: Show more specific error message for missing auth tokens. --- systemtests/lib/tecken_client.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/systemtests/lib/tecken_client.py b/systemtests/lib/tecken_client.py index b08553f03..b098b84d8 100644 --- a/systemtests/lib/tecken_client.py +++ b/systemtests/lib/tecken_client.py @@ -15,6 +15,10 @@ LOGGER = logging.getLogger(__name__) +class AuthTokenMissing(Exception): + pass + + @dataclass class Environment: """A target environment specification.""" @@ -35,7 +39,14 @@ def env_var_name(self, try_storage: bool) -> str: return env_var_name def auth_token(self, try_storage: bool) -> str: - return os.environ.get(self.env_var_name(try_storage), None) + env_var_name = self.env_var_name(try_storage) + try: + return os.environ[env_var_name] + except KeyError: + kind = "try" if try_storage else "regular" + raise AuthTokenMissing( + f"environment variable {env_var_name} for {kind} uploads not set" + ) from None class TeckenRetry(Retry): @@ -80,7 +91,6 @@ def auth_request( ) -> Response: if not auth_token: auth_token = self.target_env.auth_token(try_storage) - assert auth_token, f"authentication token missing for {self.target_env.name}" headers = {"Auth-Token": auth_token} url = f"{self.base_url}{path}" return self.session.request(method, url, headers=headers, **kwargs)