Skip to content

Commit 874c1ab

Browse files
author
Shakeel Mohamed
committed
Make index.attach() work with cookie headers
index.attach() uses the receivers/stream endpoint.
1 parent 6597fb9 commit 874c1ab

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

splunklib/binding.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ def f():
224224
"""
225225
@wraps(request_fun)
226226
def wrapper(self, *args, **kwargs):
227-
if self.token is _NoAuthenticationToken:
227+
# TODO: verify this logic is correct with tests
228+
if self.token is _NoAuthenticationToken and \
229+
self.cookie is _NoAuthenticationToken:
228230
# Not yet logged in.
229231
if self.autologin and self.username and self.password:
230232
# This will throw an uncaught

splunklib/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import socket
6868
import contextlib
6969

70-
from binding import Context, HTTPError, AuthenticationError, namespace, UrlEncoded, _encode
70+
from binding import Context, HTTPError, AuthenticationError, namespace, UrlEncoded, _encode, _NoAuthenticationToken
7171
from data import record
7272
import data
7373

@@ -1900,9 +1900,6 @@ def attach(self, host=None, source=None, sourcetype=None):
19001900
if sourcetype is not None: args['sourcetype'] = sourcetype
19011901
path = UrlEncoded(PATH_RECEIVERS_STREAM + "?" + urllib.urlencode(args), skip_encode=True)
19021902

1903-
# FIXME: BUG, can't seem to use receivers/stream by writing Cookie: xyz
1904-
# but it works fine with with the Authorization: xyz header
1905-
19061903
# Since we need to stream to the index connection, we have to keep
19071904
# the connection open and use the Splunk extension headers to note
19081905
# the input mode
@@ -1913,6 +1910,10 @@ def attach(self, host=None, source=None, sourcetype=None):
19131910
"Authorization: %s\r\n" % self.service.token,
19141911
"X-Splunk-Input-Mode: Streaming\r\n",
19151912
"\r\n"]
1913+
# If we have a cookie, use it instead of "Authorization: ..."
1914+
if self.service.cookie is not _NoAuthenticationToken:
1915+
headers[3] = "Cookie: %s\r\n" % self.service.cookie
1916+
19161917
for h in headers:
19171918
sock.write(h)
19181919
return sock

0 commit comments

Comments
 (0)