exceptions.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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."""
  52. class MalformedError(DefaultCredentialsError, ValueError):
  53. """An exception for malformed data."""
  54. class InvalidResource(DefaultCredentialsError, ValueError):
  55. """An exception for URL error."""
  56. class InvalidOperation(DefaultCredentialsError, ValueError):
  57. """An exception for invalid operation."""
  58. class InvalidValue(DefaultCredentialsError, ValueError):
  59. """Used to wrap general ValueError of python."""
  60. class InvalidType(DefaultCredentialsError, TypeError):
  61. """Used to wrap general TypeError of python."""
  62. class OSError(DefaultCredentialsError, EnvironmentError):
  63. """Used to wrap EnvironmentError(OSError after python3.3)."""