From 0954e01af0a45b03f8992e986b39a1ed22ed8920 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Tue, 30 Jan 2024 20:31:04 +1100 Subject: [PATCH] Better expose request ids. --- shakenfist_client/apiclient.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shakenfist_client/apiclient.py b/shakenfist_client/apiclient.py index 2c68f10..cd40ca1 100644 --- a/shakenfist_client/apiclient.py +++ b/shakenfist_client/apiclient.py @@ -119,6 +119,7 @@ def __init__(self, base_url=None, verbose=False, if logger: LOG = logger + self.most_recent_request_id = None self.sync_request_timeout = sync_request_timeout LOG.debug('Client initially configured with apiurl of %s for namespace %s ' @@ -192,8 +193,10 @@ def _actual_request_url(self, method, url, data=None, allow_redirects=True, stream=False): url = self.base_url + url - h = {'Authorization': self.cached_auth, - 'User-Agent': get_user_agent()} + h = { + 'Authorization': self.cached_auth, + 'User-Agent': get_user_agent() + } if data: if request_body_is_binary: h['Content-Type'] = 'application/octet-stream' @@ -208,6 +211,11 @@ def _actual_request_url(self, method, url, data=None, LOG.debug('-------------------------------------------------------') LOG.debug('API client requested: %s %s' % (method, url)) + for hkey in h: + if hkey == 'Authorization' and h[hkey]: + LOG.debug('Header: Authorization = Bearer *****') + else: + LOG.debug('Header: %s = %s' % (hkey, h[hkey])) if data: if request_body_is_binary: LOG.debug('Data: ...%d bytes of binary omitted...' % len(data)) @@ -219,6 +227,10 @@ def _actual_request_url(self, method, url, data=None, LOG.debug('API client response: code = %s (took %.02f seconds)' % (r.status_code, (end_time - start_time))) + self.most_recent_request_id = r.headers['X-Request-ID'] + for hkey in r.headers: + LOG.debug('Header: %s = %s' % (hkey, r.headers[hkey])) + if not stream and r.text: if response_body_is_binary: LOG.debug('Data: ...%d bytes of binary omitted...'