Skip to content

Commit f1080cf

Browse files
committed
Merge branch 'develop' into py3-code-migration
2 parents 5094e0e + affb72e commit f1080cf

File tree

176 files changed

+844
-18733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+844
-18733
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,20 @@ jobs:
1717
- "latest"
1818
fail-fast: false
1919

20-
services:
21-
splunk:
22-
image: splunk/splunk:${{matrix.splunk-version}}
23-
env:
24-
SPLUNK_START_ARGS: --accept-license
25-
SPLUNK_HEC_TOKEN: 11111111-1111-1111-1111-1111111111113
26-
SPLUNK_PASSWORD: changed!
27-
SPLUNK_APPS_URL: https://github.com/splunk/sdk-app-collection/releases/download/v1.1.0/sdkappcollection.tgz
28-
ports:
29-
- 8000:8000
30-
- 8088:8088
31-
- 8089:8089
32-
3320
steps:
34-
- uses: actions/checkout@v2
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
24+
- name: Run docker-compose
25+
run: SPLUNK_VERSION=${{matrix.splunk-version}} docker-compose up -d
26+
3527
- name: Setup Python
3628
uses: actions/setup-python@v2
3729
with:
3830
python-version: ${{ matrix.python }}
31+
3932
- name: Install tox
4033
run: pip install tox
34+
4135
- name: Test Execution
4236
run: tox -e py

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
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+
8+
## Version 1.7.1
9+
10+
### Bug fixes
11+
* [#471](https://github.com/splunk/splunk-sdk-python/pull/471) Fixed support of Load Balancer "sticky sessions" (persistent cookies) [[issue#438](https://github.com/splunk/splunk-sdk-python/issues/438)]
12+
13+
### Minor changes
14+
* [#466](https://github.com/splunk/splunk-sdk-python/pull/466) tests for CSC apps
15+
* [#467](https://github.com/splunk/splunk-sdk-python/pull/467) Added 'kwargs' parameter for Saved Search History function
16+
* [#475](https://github.com/splunk/splunk-sdk-python/pull/475) README updates
17+
18+
## Version 1.7.0
19+
20+
### New features and APIs
21+
* [#468](https://github.com/splunk/splunk-sdk-python/pull/468) SDK Support for splunkd search API changes
22+
23+
### Bug fixes
24+
* [#464](https://github.com/splunk/splunk-sdk-python/pull/464) updated checks for wildcards in StoragePasswords [[issue#458](https://github.com/splunk/splunk-sdk-python/issues/458)]
25+
26+
### Minor changes
27+
* [#463](https://github.com/splunk/splunk-sdk-python/pull/463) Preserve thirdparty cookies
28+
329
## Version 1.6.20
430

531
### New features and APIs

README.md

Lines changed: 4 additions & 2 deletions
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.6.20
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

@@ -28,7 +28,9 @@ Here's what you need to get going with the Splunk Enterprise SDK for Python.
2828

2929
The Splunk Enterprise SDK for Python has been tested with Python v2.7 and v3.7.
3030

31-
* Splunk Enterprise
31+
* Splunk Enterprise 9.0 or 8.2
32+
33+
The Splunk Enterprise SDK for Python has been tested with Splunk Enterprise 9.0 and 8.2
3234

3335
If you haven't already installed Splunk Enterprise, download it [here](http://www.splunk.com/download).
3436
For more information, see the Splunk Enterprise [_Installation Manual_](https://docs.splunk.com/Documentation/Splunk/latest/Installation).

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ services:
1818
interval: 5s
1919
timeout: 5s
2020
retries: 20
21+
volumes:
22+
- "./tests/searchcommands/test_apps/eventing_app:/opt/splunk/etc/apps/eventing_app"
23+
- "./tests/searchcommands/test_apps/generating_app:/opt/splunk/etc/apps/generating_app"
24+
- "./tests/searchcommands/test_apps/reporting_app:/opt/splunk/etc/apps/reporting_app"
25+
- "./tests/searchcommands/test_apps/streaming_app:/opt/splunk/etc/apps/streaming_app"
26+
- "./splunklib:/opt/splunk/etc/apps/eventing_app/lib/splunklib"
27+
- "./splunklib:/opt/splunk/etc/apps/generating_app/lib/splunklib"
28+
- "./splunklib:/opt/splunk/etc/apps/reporting_app/lib/splunklib"
29+
- "./splunklib:/opt/splunk/etc/apps/streaming_app/lib/splunklib"

splunklib/binding.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,22 +532,24 @@ def _auth_headers(self):
532532
header = []
533533
if self.has_cookies():
534534
return [("Cookie", _make_cookie_header(list(self.get_cookies().items())))]
535-
if self.basic and (self.username and self.password):
536-
encoded_username_password = b64encode(f"{self.username}:{self.password}".encode('utf-8')).decode('ascii')
537-
token = f'Basic {encoded_username_password}'
538-
return [("Authorization", token)]
539-
if self.bearerToken:
540-
token = f"Bearer {self.bearerToken}"
541-
return [("Authorization", token)]
542-
if self.token is _NoAuthenticationToken:
543-
return []
535+
elif self.basic and (self.username and self.password):
536+
token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii')
537+
elif self.bearerToken:
538+
token = 'Bearer %s' % self.bearerToken
539+
elif self.token is _NoAuthenticationToken:
540+
token = []
544541
else:
545542
# Ensure the token is properly formatted
546543
if self.token.startswith('Splunk '):
547544
token = self.token
548545
else:
549-
token = f"Splunk {self.token}"
550-
return [("Authorization", token)]
546+
token = 'Splunk %s' % self.token
547+
if token:
548+
header.append(("Authorization", token))
549+
if self.get_cookies():
550+
header.append(("Cookie", _make_cookie_header(list(self.get_cookies().items()))))
551+
552+
return header
551553

552554
def connect(self):
553555
"""Returns an open connection (socket) to the Splunk instance.
@@ -1441,7 +1443,7 @@ def request(url, message, **kwargs):
14411443
head = {
14421444
"Content-Length": str(len(body)),
14431445
"Host": host,
1444-
"User-Agent": "splunk-sdk-python/1.6.20",
1446+
"User-Agent": "splunk-sdk-python/1.7.2",
14451447
"Accept": "*/*",
14461448
"Connection": "Close",
14471449
} # defaults

splunklib/client.py

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ def __init__(self, **kwargs):
415415
super().__init__(**kwargs)
416416
self._splunk_version = None
417417
self._kvstore_owner = None
418+
self._instance_type = None
418419

419420
@property
420421
def apps(self):
@@ -565,7 +566,7 @@ def parse(self, query, **kwargs):
565566
:type kwargs: ``dict``
566567
:return: A semantic map of the parsed search query.
567568
"""
568-
if self.splunk_version >= (9,):
569+
if not self.disable_v2_api:
569570
return self.post("search/v2/parser", q=query, **kwargs)
570571
return self.get("search/parser", q=query, **kwargs)
571572

@@ -688,6 +689,22 @@ def splunk_version(self):
688689
self._splunk_version = tuple(int(p) for p in self.info['version'].split('.'))
689690
return self._splunk_version
690691

692+
@property
693+
def splunk_instance(self):
694+
if self._instance_type is None :
695+
splunk_info = self.info;
696+
if hasattr(splunk_info, 'instance_type') :
697+
self._instance_type = splunk_info['instance_type']
698+
else:
699+
self._instance_type = ''
700+
return self._instance_type
701+
702+
@property
703+
def disable_v2_api(self):
704+
if self.splunk_instance.lower() == 'cloud':
705+
return self.splunk_version < (9,0,2209)
706+
return self.splunk_version < (9,0,2)
707+
691708
@property
692709
def kvstore_owner(self):
693710
"""Returns the KVStore owner for this instance of Splunk.
@@ -1186,6 +1203,36 @@ def reload(self):
11861203
self.post("_reload")
11871204
return self
11881205

1206+
def acl_update(self, **kwargs):
1207+
"""To update Access Control List (ACL) properties for an endpoint.
1208+
1209+
:param kwargs: Additional entity-specific arguments (required).
1210+
1211+
- "owner" (``string``): The Splunk username, such as "admin". A value of "nobody" means no specific user (required).
1212+
1213+
- "sharing" (``string``): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system" (required).
1214+
1215+
:type kwargs: ``dict``
1216+
1217+
**Example**::
1218+
1219+
import splunklib.client as client
1220+
service = client.connect(...)
1221+
saved_search = service.saved_searches["name"]
1222+
saved_search.acl_update(sharing="app", owner="nobody", app="search", **{"perms.read": "admin, nobody"})
1223+
"""
1224+
if "body" not in kwargs:
1225+
kwargs = {"body": kwargs}
1226+
1227+
if "sharing" not in kwargs["body"]:
1228+
raise ValueError("Required argument 'sharing' is missing.")
1229+
if "owner" not in kwargs["body"]:
1230+
raise ValueError("Required argument 'owner' is missing.")
1231+
1232+
self.post("acl", **kwargs)
1233+
self.refresh()
1234+
return self
1235+
11891236
@property
11901237
def state(self):
11911238
"""Returns the entity's state record.
@@ -2704,7 +2751,7 @@ def __init__(self, service, sid, **kwargs):
27042751
# Default to v2 in Splunk Version 9+
27052752
path = "{path}{sid}"
27062753
# Formatting path based on the Splunk Version
2707-
if service.splunk_version < (9,):
2754+
if service.disable_v2_api:
27082755
path = path.format(path=PATH_JOBS, sid=sid)
27092756
else:
27102757
path = path.format(path=PATH_JOBS_V2, sid=sid)
@@ -2764,7 +2811,7 @@ def events(self, **kwargs):
27642811
kwargs['segmentation'] = kwargs.get('segmentation', 'none')
27652812

27662813
# Search API v1(GET) and v2(POST)
2767-
if self.service.splunk_version < (9,):
2814+
if self.service.disable_v2_api:
27682815
return self.get("events", **kwargs).body
27692816
return self.post("events", **kwargs).body
27702817

@@ -2856,7 +2903,7 @@ def results(self, **query_params):
28562903
query_params['segmentation'] = query_params.get('segmentation', 'none')
28572904

28582905
# Search API v1(GET) and v2(POST)
2859-
if self.service.splunk_version < (9,):
2906+
if self.service.disable_v2_api:
28602907
return self.get("results", **query_params).body
28612908
return self.post("results", **query_params).body
28622909

@@ -2901,7 +2948,7 @@ def preview(self, **query_params):
29012948
query_params['segmentation'] = query_params.get('segmentation', 'none')
29022949

29032950
# Search API v1(GET) and v2(POST)
2904-
if self.service.splunk_version < (9,):
2951+
if self.service.disable_v2_api:
29052952
return self.get("results_preview", **query_params).body
29062953
return self.post("results_preview", **query_params).body
29072954

@@ -2994,7 +3041,7 @@ class Jobs(Collection):
29943041

29953042
def __init__(self, service):
29963043
# Splunk 9 introduces the v2 endpoint
2997-
if service.splunk_version >= (9,):
3044+
if not service.disable_v2_api:
29983045
path = PATH_JOBS_V2
29993046
else:
30003047
path = PATH_JOBS
@@ -3275,12 +3322,15 @@ def fired_alerts(self):
32753322
item=AlertGroup)
32763323
return c
32773324

3278-
def history(self):
3325+
def history(self, **kwargs):
32793326
"""Returns a list of search jobs corresponding to this saved search.
32803327
3328+
:param `kwargs`: Additional arguments (optional).
3329+
:type kwargs: ``dict``
3330+
32813331
:return: A list of :class:`Job` objects.
32823332
"""
3283-
response = self.get("history")
3333+
response = self.get("history", **kwargs)
32843334
entries = _load_atom_entries(response)
32853335
if entries is None: return []
32863336
jobs = []

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Splunk Test Suite
22

33
The test suite uses Python's standard library and the built-in **unittest**
4-
library. If you're using Python 2.7, you're all set. However, if you are using
4+
library. If you're using Python 2.7 or Python 3.7, you're all set. However, if you are using
55
Python 2.6, you'll also need to install the **unittest2** library to get the
66
additional features that were added to Python 2.7 (just run `pip install
77
unittest2` or `easy_install unittest2`).

tests/searchcommands/recordings/scpv1/Splunk-6.3/countmatches.execute.dispatch_dir/args.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/searchcommands/recordings/scpv1/Splunk-6.3/countmatches.execute.dispatch_dir/custom_prop.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/searchcommands/recordings/scpv1/Splunk-6.3/countmatches.execute.dispatch_dir/externSearchResultsInfo.csv

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)