Skip to content

Commit c7a20c8

Browse files
author
Shakeel Mohamed
committed
Ensure Client.connect() always returns a Service instance.
If token and/or cookie is set, without username/password, Client.connect() would return None. This change now matches the logic in Binding.connect()
1 parent a570ddb commit c7a20c8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

splunklib/binding.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ def connect(**kwargs):
942942
:param token: The current session token (optional). Session tokens can be
943943
shared across multiple service instances.
944944
:type token: ``string``
945+
:param cookie: A session cookie. When provided, you don't need to call :meth:`login`.
946+
This parameter is only supported for Splunk 6.2+.
947+
:type cookie: ``string``
945948
:param username: The Splunk account username, which is used to
946949
authenticate the Splunk instance.
947950
:type username: ``string``

splunklib/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ def _parse_atom_metadata(content):
262262

263263
return record({'access': access, 'fields': fields})
264264

265-
266265
# kwargs: scheme, host, port, app, owner, username, password
267266
def connect(**kwargs):
268267
"""This function connects and logs in to a Splunk instance.
@@ -285,6 +284,9 @@ def connect(**kwargs):
285284
:param `token`: The current session token (optional). Session tokens can be
286285
shared across multiple service instances.
287286
:type token: ``string``
287+
:param cookie: A session cookie. When provided, you don't need to call :meth:`login`.
288+
This parameter is only supported for Splunk 6.2+.
289+
:type cookie: ``string``
288290
:param autologin: When ``True``, automatically tries to log in again if the
289291
session terminates.
290292
:type autologin: ``boolean``
@@ -302,7 +304,9 @@ def connect(**kwargs):
302304
a = s.apps["my_app"]
303305
...
304306
"""
305-
return Service(**kwargs).login()
307+
s = Service(**kwargs)
308+
s.login()
309+
return s
306310

307311

308312
# In preparation for adding Storm support, we added an

0 commit comments

Comments
 (0)