Skip to content

Commit

Permalink
Merge pull request #482 from splunk/revert-v2-changes
Browse files Browse the repository at this point in the history
updated version checks for v2 search APIs
  • Loading branch information
ashah-splunk committed Sep 2, 2022
2 parents 0d9995d + 8af61cb commit 0db743d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions splunklib/client.py
Expand Up @@ -572,7 +572,7 @@ def parse(self, query, **kwargs):
:type kwargs: ``dict``
:return: A semantic map of the parsed search query.
"""
if self.splunk_version >= (9,):
if self.splunk_version >= (9,0,2):
return self.post("search/v2/parser", q=query, **kwargs)
return self.get("search/parser", q=query, **kwargs)

Expand Down Expand Up @@ -2722,7 +2722,7 @@ def __init__(self, service, sid, **kwargs):
# Default to v2 in Splunk Version 9+
path = "{path}{sid}"
# Formatting path based on the Splunk Version
if service.splunk_version < (9,):
if service.splunk_version < (9,0,2):
path = path.format(path=PATH_JOBS, sid=sid)
else:
path = path.format(path=PATH_JOBS_V2, sid=sid)
Expand Down Expand Up @@ -2782,7 +2782,7 @@ def events(self, **kwargs):
kwargs['segmentation'] = kwargs.get('segmentation', 'none')

# Search API v1(GET) and v2(POST)
if self.service.splunk_version < (9,):
if self.service.splunk_version < (9,0,2):
return self.get("events", **kwargs).body
return self.post("events", **kwargs).body

Expand Down Expand Up @@ -2874,7 +2874,7 @@ def results(self, **query_params):
query_params['segmentation'] = query_params.get('segmentation', 'none')

# Search API v1(GET) and v2(POST)
if self.service.splunk_version < (9,):
if self.service.splunk_version < (9,0,2):
return self.get("results", **query_params).body
return self.post("results", **query_params).body

Expand Down Expand Up @@ -2919,7 +2919,7 @@ def preview(self, **query_params):
query_params['segmentation'] = query_params.get('segmentation', 'none')

# Search API v1(GET) and v2(POST)
if self.service.splunk_version < (9,):
if self.service.splunk_version < (9,0,2):
return self.get("results_preview", **query_params).body
return self.post("results_preview", **query_params).body

Expand Down Expand Up @@ -3011,7 +3011,7 @@ class Jobs(Collection):
collection using :meth:`Service.jobs`."""
def __init__(self, service):
# Splunk 9 introduces the v2 endpoint
if service.splunk_version >= (9,):
if service.splunk_version >= (9,0,2):
path = PATH_JOBS_V2
else:
path = PATH_JOBS
Expand Down
4 changes: 2 additions & 2 deletions tests/test_job.py
Expand Up @@ -401,8 +401,8 @@ def test_v1_job_fallback(self):
n_results = len([x for x in results_r if isinstance(x, dict)])

# Fallback test for Splunk Version 9+
if self.service.splunk_version[0] >= 9:
self.assertGreaterEqual(9, self.service.splunk_version[0])
if self.service.splunk_version >= (9,0,2):
self.assertGreaterEqual((9,0,2), self.service.splunk_version)
self.assertEqual(n_events, n_preview, n_results)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_service.py
Expand Up @@ -104,8 +104,8 @@ def test_parse(self):
response = self.service.parse('search * abc="def" | dedup abc')

# Splunk Version 9+ using API v2: search/v2/parser
if self.service.splunk_version[0] >= 9:
self.assertGreaterEqual(9, self.service.splunk_version[0])
if self.service.splunk_version >= (9,0,2):
self.assertGreaterEqual((9,0,2), self.service.splunk_version)

self.assertEqual(response.status, 200)

Expand Down

0 comments on commit 0db743d

Please sign in to comment.