splitting http req and resp logging
also some pep8 cleanup in shell.py Change-Id: I71aa2586a0196c0a6ba64b892b56c9d221bdcc1d
This commit is contained in:
@@ -61,6 +61,13 @@ class HTTPClient(httplib2.Http):
|
|||||||
self.force_exception_to_status_code = True
|
self.force_exception_to_status_code = True
|
||||||
self.disable_ssl_certificate_validation = insecure
|
self.disable_ssl_certificate_validation = insecure
|
||||||
|
|
||||||
|
# logging setup
|
||||||
|
self.debug_log = os.environ.get('KEYSTONECLIENT_DEBUG', False)
|
||||||
|
if self.debug_log:
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
_logger.setLevel(logging.DEBUG)
|
||||||
|
_logger.addHandler(ch)
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
""" Authenticate against the keystone API.
|
""" Authenticate against the keystone API.
|
||||||
|
|
||||||
@@ -77,12 +84,8 @@ class HTTPClient(httplib2.Http):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def http_log(self, args, kwargs, resp, body):
|
def http_log_req(self, args, kwargs):
|
||||||
if os.environ.get('KEYSTONECLIENT_DEBUG', False):
|
if not self.debug_log:
|
||||||
ch = logging.StreamHandler()
|
|
||||||
_logger.setLevel(logging.DEBUG)
|
|
||||||
_logger.addHandler(ch)
|
|
||||||
elif not _logger.isEnabledFor(logging.DEBUG):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
string_parts = ['curl -i']
|
string_parts = ['curl -i']
|
||||||
@@ -99,6 +102,9 @@ class HTTPClient(httplib2.Http):
|
|||||||
_logger.debug("REQ: %s\n" % "".join(string_parts))
|
_logger.debug("REQ: %s\n" % "".join(string_parts))
|
||||||
if 'body' in kwargs:
|
if 'body' in kwargs:
|
||||||
_logger.debug("REQ BODY: %s\n" % (kwargs['body']))
|
_logger.debug("REQ BODY: %s\n" % (kwargs['body']))
|
||||||
|
|
||||||
|
def http_log_resp(self, resp, body):
|
||||||
|
if self.debug_log:
|
||||||
_logger.debug("RESP: %s\nRESP BODY: %s\n", resp, body)
|
_logger.debug("RESP: %s\nRESP BODY: %s\n", resp, body)
|
||||||
|
|
||||||
def request(self, url, method, **kwargs):
|
def request(self, url, method, **kwargs):
|
||||||
@@ -115,11 +121,11 @@ class HTTPClient(httplib2.Http):
|
|||||||
request_kwargs['headers']['Content-Type'] = 'application/json'
|
request_kwargs['headers']['Content-Type'] = 'application/json'
|
||||||
request_kwargs['body'] = json.dumps(kwargs['body'])
|
request_kwargs['body'] = json.dumps(kwargs['body'])
|
||||||
|
|
||||||
|
self.http_log_req((url, method,), request_kwargs)
|
||||||
resp, body = super(HTTPClient, self).request(url,
|
resp, body = super(HTTPClient, self).request(url,
|
||||||
method,
|
method,
|
||||||
**request_kwargs)
|
**request_kwargs)
|
||||||
|
self.http_log_resp(resp, body)
|
||||||
self.http_log((url, method,), request_kwargs, resp, body)
|
|
||||||
|
|
||||||
if body:
|
if body:
|
||||||
try:
|
try:
|
||||||
|
@@ -195,7 +195,8 @@ class OpenStackIdentityShell(object):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def _add_bash_completion_subparser(self, subparsers):
|
def _add_bash_completion_subparser(self, subparsers):
|
||||||
subparser = subparsers.add_parser('bash_completion',
|
subparser = subparsers.add_parser(
|
||||||
|
'bash_completion',
|
||||||
add_help=False,
|
add_help=False,
|
||||||
formatter_class=OpenStackHelpFormatter
|
formatter_class=OpenStackHelpFormatter
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user