correctly set the Authorization header for non-async log handling

see: #5276
This commit is contained in:
Ryan Petrello
2017-02-09 15:01:06 -05:00
parent c82e86cc78
commit 1b9a2e4a36
2 changed files with 88 additions and 20 deletions

View File

@@ -52,7 +52,10 @@ class BaseHTTPSHandler(logging.Handler):
self.async = kwargs.get('async', True)
for fd in PARAM_NAMES:
setattr(self, fd, kwargs.get(fd, None))
self.session = FuturesSession()
if self.async:
self.session = FuturesSession()
else:
self.session = requests.Session()
self.add_auth_information()
@classmethod
@@ -126,7 +129,6 @@ class BaseHTTPSHandler(logging.Handler):
return []
try:
payload = self.format(record)
host = self.get_http_host()
# Special action for System Tracking, queue up multiple log messages
if self.indv_facts:
@@ -139,21 +141,26 @@ class BaseHTTPSHandler(logging.Handler):
for key in facts_dict:
fact_payload = copy(payload_data)
fact_payload.update(facts_dict[key])
async_futures.append(
self.session.post(host, **self.get_post_kwargs(fact_payload))
)
if self.async:
async_futures.append(self._send(fact_payload))
else:
self._send(fact_payload)
return async_futures
if self.async:
return [self.session.post(host, **self.get_post_kwargs(payload))]
return [self._send(payload)]
requests.post(host, auth=requests.auth.HTTPBasicAuth(self.username, self.password), **self.get_post_kwargs(payload))
self._send(payload)
return []
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
def _send(self, payload):
return self.session.post(self.get_http_host(),
**self.get_post_kwargs(payload))
class HTTPSHandler(object):