From 4109c7882f4de27b39cb119d0ca587c8d1bc6a56 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 6 Jun 2022 14:23:00 +0530 Subject: [PATCH 1/2] Update binding.py --- splunklib/binding.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 4a4098df..f3a78536 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -526,23 +526,27 @@ def _auth_headers(self): :returns: A list of 2-tuples containing key and value """ + header = [] if self.has_cookies(): return [("Cookie", _make_cookie_header(list(self.get_cookies().items())))] elif self.basic and (self.username and self.password): token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii') - return [("Authorization", token)] elif self.bearerToken: token = 'Bearer %s' % self.bearerToken - return [("Authorization", token)] elif self.token is _NoAuthenticationToken: - return [] + token = [] else: # Ensure the token is properly formatted if self.token.startswith('Splunk '): token = self.token else: token = 'Splunk %s' % self.token - return [("Authorization", token)] + if token: + header.append(("Authorization", token)) + if self.get_cookies().__len__() >= 1: + header.append("Cookie", _make_cookie_header(self.get_cookies().items())) + + return header def connect(self): """Returns an open connection (socket) to the Splunk instance. From 9dbc86b2b71247f2cc23b8a741d9e96d4e0e1b4d Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Tue, 7 Jun 2022 15:26:20 +0530 Subject: [PATCH 2/2] Update binding.py --- splunklib/binding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index f3a78536..eafa2f96 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -543,7 +543,7 @@ def _auth_headers(self): token = 'Splunk %s' % self.token if token: header.append(("Authorization", token)) - if self.get_cookies().__len__() >= 1: + if self.get_cookies().__len__() > 0: header.append("Cookie", _make_cookie_header(self.get_cookies().items())) return header