Add in a more verbose exception message
Add in a more verbose message to include credential username, password, and tenant_name when an invalid credential exception is raised. Co-Authored-By: Matthew Treinish <mtreinish@kortar.org> Change-Id: I8133eb68303eae7492734ad5ea77cf5474a8263f
This commit is contained in:

committed by
Matthew Treinish

parent
307df12b98
commit
d51fa191b2
@@ -43,7 +43,18 @@ class AuthProvider(object):
|
|||||||
if self.check_credentials(credentials):
|
if self.check_credentials(credentials):
|
||||||
self.credentials = credentials
|
self.credentials = credentials
|
||||||
else:
|
else:
|
||||||
raise TypeError("Invalid credentials")
|
if isinstance(credentials, Credentials):
|
||||||
|
password = credentials.get('password')
|
||||||
|
message = "Credentials are: " + str(credentials)
|
||||||
|
if password is None:
|
||||||
|
message += " Password is not defined."
|
||||||
|
else:
|
||||||
|
message += " Password is defined."
|
||||||
|
raise exceptions.InvalidCredentials(message)
|
||||||
|
else:
|
||||||
|
raise TypeError("credentials object is of type %s, which is"
|
||||||
|
" not a valid Credentials object type." %
|
||||||
|
credentials.__class__.__name__)
|
||||||
self.cache = None
|
self.cache = None
|
||||||
self.alt_auth_data = None
|
self.alt_auth_data = None
|
||||||
self.alt_part = None
|
self.alt_part = None
|
||||||
@@ -521,7 +532,8 @@ class Credentials(object):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Represent only attributes included in self.ATTRIBUTES"""
|
"""Represent only attributes included in self.ATTRIBUTES"""
|
||||||
_repr = dict((k, getattr(self, k)) for k in self.ATTRIBUTES)
|
attrs = [attr for attr in self.ATTRIBUTES if attr is not 'password']
|
||||||
|
_repr = dict((k, getattr(self, k)) for k in attrs)
|
||||||
return str(_repr)
|
return str(_repr)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
Reference in New Issue
Block a user