exceptions.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. """Exceptions used in the google.auth package."""
  15. class GoogleAuthError(Exception):
  16. """Base class for all google.auth errors."""
  17. def __init__(self, *args, **kwargs):
  18. super(GoogleAuthError, self).__init__(*args)
  19. retryable = kwargs.get("retryable", False)
  20. self._retryable = retryable
  21. @property
  22. def retryable(self):
  23. return self._retryable
  24. class TransportError(GoogleAuthError):
  25. """Used to indicate an error occurred during an HTTP request."""
  26. class RefreshError(GoogleAuthError):
  27. """Used to indicate that an refreshing the credentials' access token
  28. failed."""
  29. class UserAccessTokenError(GoogleAuthError):
  30. """Used to indicate ``gcloud auth print-access-token`` command failed."""
  31. class DefaultCredentialsError(GoogleAuthError):
  32. """Used to indicate that acquiring default credentials failed."""
  33. class MutualTLSChannelError(GoogleAuthError):
  34. """Used to indicate that mutual TLS channel creation is failed, or mutual
  35. TLS channel credentials is missing or invalid."""
  36. class ClientCertError(GoogleAuthError):
  37. """Used to indicate that client certificate is missing or invalid."""
  38. @property
  39. def retryable(self):
  40. return False
  41. class OAuthError(GoogleAuthError):
  42. """Used to indicate an error occurred during an OAuth related HTTP
  43. request."""
  44. class ReauthFailError(RefreshError):
  45. """An exception for when reauth failed."""
  46. def __init__(self, message=None, **kwargs):
  47. super(ReauthFailError, self).__init__(
  48. "Reauthentication failed. {0}".format(message), **kwargs
  49. )
  50. class ReauthSamlChallengeFailError(ReauthFailError):
  51. """An exception for SAML reauth challenge failures."""