Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.7.2 #483

Merged
merged 10 commits into from Sep 14, 2022
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Splunk Enterprise SDK for Python Changelog

## Version 1.7.2

### Minor changes
* [#482](https://github.com/splunk/splunk-sdk-python/pull/482) updated version checks for enabling v2 search APIs

## Version 1.7.1

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@

# The Splunk Enterprise Software Development Kit for Python

#### Version 1.7.1
#### Version 1.7.2

The Splunk Enterprise Software Development Kit (SDK) for Python contains library code designed to enable developers to build applications using the Splunk platform.

Expand Down
2 changes: 1 addition & 1 deletion splunklib/__init__.py
Expand Up @@ -31,5 +31,5 @@ def setup_logging(level, log_format=DEFAULT_LOG_FORMAT, date_format=DEFAULT_DATE
format=log_format,
datefmt=date_format)

__version_info__ = (1, 7, 1)
__version_info__ = (1, 7, 2)
__version__ = ".".join(map(str, __version_info__))
2 changes: 1 addition & 1 deletion splunklib/binding.py
Expand Up @@ -1434,7 +1434,7 @@ def request(url, message, **kwargs):
head = {
"Content-Length": str(len(body)),
"Host": host,
"User-Agent": "splunk-sdk-python/1.7.1",
"User-Agent": "splunk-sdk-python/1.7.2",
"Accept": "*/*",
"Connection": "Close",
} # defaults
Expand Down
35 changes: 29 additions & 6 deletions splunklib/client.py
Expand Up @@ -421,6 +421,7 @@ def __init__(self, **kwargs):
super(Service, self).__init__(**kwargs)
self._splunk_version = None
self._kvstore_owner = None
self._instance_type = None

@property
def apps(self):
Expand Down Expand Up @@ -572,7 +573,8 @@ 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):
if not self.disable_v2_api:
return self.post("search/v2/parser", q=query, **kwargs)
return self.get("search/parser", q=query, **kwargs)

Expand Down Expand Up @@ -695,6 +697,22 @@ def splunk_version(self):
self._splunk_version = tuple([int(p) for p in self.info['version'].split('.')])
return self._splunk_version

@property
def splunk_instance(self):
if self._instance_type is None :
splunk_info = self.info;
if hasattr(splunk_info, 'instance_type') :
self._instance_type = splunk_info['instance_type']
else:
self._instance_type = ''
return self._instance_type

@property
def disable_v2_api(self):
if self.splunk_instance == 'cloud':
return self.splunk_version < (9,0,2209)
return self.splunk_version < (9,0,2)

@property
def kvstore_owner(self):
"""Returns the KVStore owner for this instance of Splunk.
Expand Down Expand Up @@ -2722,7 +2740,8 @@ 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):
if service.disable_v2_api:
path = path.format(path=PATH_JOBS, sid=sid)
else:
path = path.format(path=PATH_JOBS_V2, sid=sid)
Expand Down Expand Up @@ -2782,7 +2801,8 @@ 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):
if self.service.disable_v2_api:
return self.get("events", **kwargs).body
return self.post("events", **kwargs).body

Expand Down Expand Up @@ -2874,7 +2894,8 @@ 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):
if self.service.disable_v2_api:
return self.get("results", **query_params).body
return self.post("results", **query_params).body

Expand Down Expand Up @@ -2919,7 +2940,8 @@ 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):
ashah-splunk marked this conversation as resolved.
Show resolved Hide resolved
if self.service.disable_v2_api:
return self.get("results_preview", **query_params).body
return self.post("results_preview", **query_params).body

Expand Down Expand Up @@ -3011,7 +3033,8 @@ 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):
if not service.disable_v2_api:
path = PATH_JOBS_V2
else:
path = PATH_JOBS
Expand Down
8 changes: 4 additions & 4 deletions tests/test_job.py
Expand Up @@ -399,10 +399,10 @@ def test_v1_job_fallback(self):
n_events = len([x for x in events_r if isinstance(x, dict)])
n_preview = len([x for x in preview_r if isinstance(x, dict)])
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])

# Fallback test for Splunk Version 9.0.2+
if not self.service.disable_v2_api:
self.assertTrue(client.PATH_JOBS_V2 in self.job.path)
self.assertEqual(n_events, n_preview, n_results)


Expand Down
5 changes: 0 additions & 5 deletions tests/test_service.py
Expand Up @@ -102,11 +102,6 @@ def test_parse(self):
# objectified form of the results, but for now there's
# nothing to test but a good response code.
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])

self.assertEqual(response.status, 200)

def test_parse_fail(self):
Expand Down