Skip to content

Commit

Permalink
Merge pull request #447 from splunk/DVPL-10137
Browse files Browse the repository at this point in the history
Create job support for "output_mode:json"
  • Loading branch information
ashah-splunk committed Apr 20, 2022
2 parents 875a58d + f7f15b2 commit ce390c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions splunklib/client.py
Expand Up @@ -226,7 +226,10 @@ def _load_atom_entries(response):


# Load the sid from the body of the given response
def _load_sid(response):
def _load_sid(response, output_mode):
if output_mode == "json":
json_obj = json.loads(response.body.read())
return json_obj.get('sid')
return _load_atom(response).response.sid


Expand Down Expand Up @@ -2957,7 +2960,7 @@ def create(self, query, **kwargs):
if kwargs.get("exec_mode", None) == "oneshot":
raise TypeError("Cannot specify exec_mode=oneshot; use the oneshot method instead.")
response = self.post(search=query, **kwargs)
sid = _load_sid(response)
sid = _load_sid(response, kwargs.get("output_mode", None))
return Job(self.service, sid)

def export(self, query, **params):
Expand Down Expand Up @@ -3173,7 +3176,7 @@ def dispatch(self, **kwargs):
:return: The :class:`Job`.
"""
response = self.post("dispatch", **kwargs)
sid = _load_sid(response)
sid = _load_sid(response, kwargs.get("output_mode", None))
return Job(self.service, sid)

@property
Expand Down
5 changes: 5 additions & 0 deletions tests/test_job.py
Expand Up @@ -48,6 +48,11 @@ def test_service_search(self):
self.assertTrue(job.sid in self.service.jobs)
job.cancel()

def test_create_job_with_output_mode_json(self):
job = self.service.jobs.create(query='search index=_internal earliest=-1m | head 3', output_mode='json')
self.assertTrue(job.sid in self.service.jobs)
job.cancel()

def test_oneshot_with_garbage_fails(self):
jobs = self.service.jobs
self.assertRaises(TypeError, jobs.create, "abcd", exec_mode="oneshot")
Expand Down

0 comments on commit ce390c6

Please sign in to comment.