1# Copyright 2016 Google LLC
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.
14
15"""Exceptions used in the google.auth package."""
16
17
18class GoogleAuthError(Exception):
19 """Base class for all google.auth errors."""
20
21 def __init__(self, *args, **kwargs):
22 super(GoogleAuthError, self).__init__(*args)
23 retryable = kwargs.get("retryable", False)
24 self._retryable = retryable
25
26 @property
27 def retryable(self):
28 return self._retryable
29
30
31class TransportError(GoogleAuthError):
32 """Used to indicate an error occurred during an HTTP request."""
33
34
35class RefreshError(GoogleAuthError):
36 """Used to indicate that an refreshing the credentials' access token
37 failed."""
38
39
40class UserAccessTokenError(GoogleAuthError):
41 """Used to indicate ``gcloud auth print-access-token`` command failed."""
42
43
44class DefaultCredentialsError(GoogleAuthError):
45 """Used to indicate that acquiring default credentials failed."""
46
47
48class MutualTLSChannelError(GoogleAuthError):
49 """Used to indicate that mutual TLS channel creation is failed, or mutual
50 TLS channel credentials is missing or invalid."""
51
52
53class ClientCertError(GoogleAuthError):
54 """Used to indicate that client certificate is missing or invalid."""
55
56 @property
57 def retryable(self):
58 return False
59
60
61class OAuthError(GoogleAuthError):
62 """Used to indicate an error occurred during an OAuth related HTTP
63 request."""
64
65
66class ReauthFailError(RefreshError):
67 """An exception for when reauth failed."""
68
69 def __init__(self, message=None, **kwargs):
70 super(ReauthFailError, self).__init__(
71 "Reauthentication failed. {0}".format(message), **kwargs
72 )
73
74
75class ReauthSamlChallengeFailError(ReauthFailError):
76 """An exception for SAML reauth challenge failures."""
77
78
79class MalformedError(DefaultCredentialsError, ValueError):
80 """An exception for malformed data."""
81
82
83class InvalidResource(DefaultCredentialsError, ValueError):
84 """An exception for URL error."""
85
86
87class InvalidOperation(DefaultCredentialsError, ValueError):
88 """An exception for invalid operation."""
89
90
91class InvalidValue(DefaultCredentialsError, ValueError):
92 """Used to wrap general ValueError of python."""
93
94
95class InvalidType(DefaultCredentialsError, TypeError):
96 """Used to wrap general TypeError of python."""
97
98
99class OSError(DefaultCredentialsError, EnvironmentError):
100 """Used to wrap EnvironmentError(OSError after python3.3)."""
101
102
103class TimeoutError(GoogleAuthError):
104 """Used to indicate a timeout error occurred during an HTTP request."""
105
106
107class ResponseError(GoogleAuthError):
108 """Used to indicate an error occurred when reading an HTTP response."""