Skip to content

Commit

Permalink
bug-1909870: Show more specific error message for missing auth tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
smarnach committed Jul 30, 2024
1 parent a3a7fd7 commit 41803b8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions systemtests/lib/tecken_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
LOGGER = logging.getLogger(__name__)


class AuthTokenMissing(Exception):
pass


@dataclass
class Environment:
"""A target environment specification."""
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 41803b8

Please sign in to comment.