Skip to content

Commit e323dd8

Browse files
Merge pull request #483 from splunk/release/1.7.2
Release/1.7.2
2 parents db48641 + 9f1b937 commit e323dd8

File tree

7 files changed

+35
-18
lines changed

7 files changed

+35
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Splunk Enterprise SDK for Python Changelog
22

3+
## Version 1.7.2
4+
5+
### Minor changes
6+
* [#482](https://github.com/splunk/splunk-sdk-python/pull/482) Special handling related to the semantic versioning of specific Search APIs functional in Splunk Enterprise 9.0.2 and (Splunk Cloud 9.0.2209). These SDK changes will enable seamless transition between the APIs based on the version of the Splunk Enterprise in use
7+
38
## Version 1.7.1
49

510
### Bug fixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# The Splunk Enterprise Software Development Kit for Python
55

6-
#### Version 1.7.1
6+
#### Version 1.7.2
77

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

splunklib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ def setup_logging(level, log_format=DEFAULT_LOG_FORMAT, date_format=DEFAULT_DATE
3131
format=log_format,
3232
datefmt=date_format)
3333

34-
__version_info__ = (1, 7, 1)
34+
__version_info__ = (1, 7, 2)
3535
__version__ = ".".join(map(str, __version_info__))

splunklib/binding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ def request(url, message, **kwargs):
14341434
head = {
14351435
"Content-Length": str(len(body)),
14361436
"Host": host,
1437-
"User-Agent": "splunk-sdk-python/1.7.1",
1437+
"User-Agent": "splunk-sdk-python/1.7.2",
14381438
"Accept": "*/*",
14391439
"Connection": "Close",
14401440
} # defaults

splunklib/client.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ def __init__(self, **kwargs):
421421
super(Service, self).__init__(**kwargs)
422422
self._splunk_version = None
423423
self._kvstore_owner = None
424+
self._instance_type = None
424425

425426
@property
426427
def apps(self):
@@ -572,7 +573,7 @@ def parse(self, query, **kwargs):
572573
:type kwargs: ``dict``
573574
:return: A semantic map of the parsed search query.
574575
"""
575-
if self.splunk_version >= (9,):
576+
if not self.disable_v2_api:
576577
return self.post("search/v2/parser", q=query, **kwargs)
577578
return self.get("search/parser", q=query, **kwargs)
578579

@@ -695,6 +696,22 @@ def splunk_version(self):
695696
self._splunk_version = tuple([int(p) for p in self.info['version'].split('.')])
696697
return self._splunk_version
697698

699+
@property
700+
def splunk_instance(self):
701+
if self._instance_type is None :
702+
splunk_info = self.info;
703+
if hasattr(splunk_info, 'instance_type') :
704+
self._instance_type = splunk_info['instance_type']
705+
else:
706+
self._instance_type = ''
707+
return self._instance_type
708+
709+
@property
710+
def disable_v2_api(self):
711+
if self.splunk_instance.lower() == 'cloud':
712+
return self.splunk_version < (9,0,2209)
713+
return self.splunk_version < (9,0,2)
714+
698715
@property
699716
def kvstore_owner(self):
700717
"""Returns the KVStore owner for this instance of Splunk.
@@ -2722,7 +2739,7 @@ def __init__(self, service, sid, **kwargs):
27222739
# Default to v2 in Splunk Version 9+
27232740
path = "{path}{sid}"
27242741
# Formatting path based on the Splunk Version
2725-
if service.splunk_version < (9,):
2742+
if service.disable_v2_api:
27262743
path = path.format(path=PATH_JOBS, sid=sid)
27272744
else:
27282745
path = path.format(path=PATH_JOBS_V2, sid=sid)
@@ -2782,7 +2799,7 @@ def events(self, **kwargs):
27822799
kwargs['segmentation'] = kwargs.get('segmentation', 'none')
27832800

27842801
# Search API v1(GET) and v2(POST)
2785-
if self.service.splunk_version < (9,):
2802+
if self.service.disable_v2_api:
27862803
return self.get("events", **kwargs).body
27872804
return self.post("events", **kwargs).body
27882805

@@ -2874,7 +2891,7 @@ def results(self, **query_params):
28742891
query_params['segmentation'] = query_params.get('segmentation', 'none')
28752892

28762893
# Search API v1(GET) and v2(POST)
2877-
if self.service.splunk_version < (9,):
2894+
if self.service.disable_v2_api:
28782895
return self.get("results", **query_params).body
28792896
return self.post("results", **query_params).body
28802897

@@ -2919,7 +2936,7 @@ def preview(self, **query_params):
29192936
query_params['segmentation'] = query_params.get('segmentation', 'none')
29202937

29212938
# Search API v1(GET) and v2(POST)
2922-
if self.service.splunk_version < (9,):
2939+
if self.service.disable_v2_api:
29232940
return self.get("results_preview", **query_params).body
29242941
return self.post("results_preview", **query_params).body
29252942

@@ -3011,7 +3028,7 @@ class Jobs(Collection):
30113028
collection using :meth:`Service.jobs`."""
30123029
def __init__(self, service):
30133030
# Splunk 9 introduces the v2 endpoint
3014-
if service.splunk_version >= (9,):
3031+
if not service.disable_v2_api:
30153032
path = PATH_JOBS_V2
30163033
else:
30173034
path = PATH_JOBS

tests/test_job.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ def test_v1_job_fallback(self):
399399
n_events = len([x for x in events_r if isinstance(x, dict)])
400400
n_preview = len([x for x in preview_r if isinstance(x, dict)])
401401
n_results = len([x for x in results_r if isinstance(x, dict)])
402-
403-
# Fallback test for Splunk Version 9+
404-
if self.service.splunk_version[0] >= 9:
405-
self.assertGreaterEqual(9, self.service.splunk_version[0])
402+
403+
# Fallback test for Splunk Version 9.0.2+
404+
if not self.service.disable_v2_api:
405+
self.assertTrue(client.PATH_JOBS_V2 in self.job.path)
406406
self.assertEqual(n_events, n_preview, n_results)
407407

408408

tests/test_service.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ def test_parse(self):
102102
# objectified form of the results, but for now there's
103103
# nothing to test but a good response code.
104104
response = self.service.parse('search * abc="def" | dedup abc')
105-
106-
# Splunk Version 9+ using API v2: search/v2/parser
107-
if self.service.splunk_version[0] >= 9:
108-
self.assertGreaterEqual(9, self.service.splunk_version[0])
109-
110105
self.assertEqual(response.status, 200)
111106

112107
def test_parse_fail(self):

0 commit comments

Comments
 (0)