Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/auth/exceptions.py: 92.59%
27 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-11-01 16:30 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-11-01 16:30 +0000
1# Copyright (C) 2023 Bloomberg LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# <http://www.apache.org/licenses/LICENSE-2.0>
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15from buildgrid.server.exceptions import ServerError
18class AuthError(ServerError):
19 pass
22class MissingTokenError(AuthError):
23 def __init__(self) -> None:
24 super().__init__("Missing authentication header field")
27class InvalidAuthorizationHeaderError(AuthError):
28 def __init__(self) -> None:
29 super().__init__("Invalid authentication header field")
32class InvalidTokenError(AuthError):
33 def __init__(self) -> None:
34 super().__init__("Invalid authentication token")
37class SigningKeyNotFoundError(AuthError):
38 def __init__(self, message: str) -> None:
39 super().__init__(f"Cannot find signing key for token: {message}")
42class ExpiredTokenError(AuthError):
43 def __init__(self) -> None:
44 super().__init__("Expired authentication token")
47class UnboundedTokenError(AuthError):
48 def __init__(self, context: str = "") -> None:
49 message = "Unbounded authentication token"
50 if context:
51 message = f"{message}: {context}"
52 super().__init__(message)
55class UnexpectedTokenParsingError(AuthError):
56 def __init__(self) -> None:
57 super().__init__("Unexpected error parsing authentication token")