@@ -422,6 +422,11 @@ def __init__(self, handler=None, **kwargs):
422422 self .password = kwargs .get ("password" , "" )
423423 self .autologin = kwargs .get ("autologin" , False )
424424
425+ # FIXME: update the docstrings for this
426+ self .cookie = kwargs .get ("cookie" , _NoAuthenticationToken )
427+ if self .cookie is None : # In case someone explicitly passes cookie=None
428+ self .cookie = _NoAuthenticationToken
429+
425430 # Shared per-context request headers
426431 @property
427432 def _auth_headers (self ):
@@ -433,7 +438,9 @@ def _auth_headers(self):
433438
434439 :returns: A list of 2-tuples containing key and value
435440 """
436- if self .token is _NoAuthenticationToken :
441+ if self .cookie is not _NoAuthenticationToken :
442+ return [("cookie" , self .cookie )]
443+ elif self .token is _NoAuthenticationToken :
437444 return []
438445 else :
439446 # Ensure the token is properly formatted
@@ -756,10 +763,20 @@ def login(self):
756763 # logged in.
757764 return
758765 try :
766+ #TODO: if self.cookie is set, should we even bother with trying to get a token?
767+
759768 response = self .http .post (
760769 self .authority + self ._abspath ("/services/auth/login" ),
761770 username = self .username ,
762- password = self .password )
771+ password = self .password ,
772+ cookie = "1" ) # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
773+
774+ # TODO: Should we return at this point, or also parse the token if we get a cookie?
775+ for key , value in response .headers :
776+ if key == "set-cookie" :
777+ self .cookie = value
778+ return self
779+
763780 body = response .body .read ()
764781 session = XML (body ).findtext ("./sessionKey" )
765782 self .token = "Splunk %s" % session
0 commit comments