Skip to content

Commit d091844

Browse files
committed
Merge branch 'develop' into py3-code-migration
2 parents d18b735 + f8b1586 commit d091844

File tree

13 files changed

+66
-27
lines changed

13 files changed

+66
-27
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout source
12-
uses: actions/checkout@v2.3.2
12+
uses: actions/checkout@v3
1313
- name: Set up Python
14-
uses: actions/setup-python@v2
14+
uses: actions/setup-python@v4
1515
with:
1616
python-version: 3.7
1717
- name: Install dependencies
1818
run: pip install twine
1919
- name: Build package
2020
run: python setup.py sdist
2121
- name: Publish package to PyPI
22-
uses: pypa/gh-action-pypi-publish@v1.3.1
22+
uses: pypa/gh-action-pypi-publish@v1.8.8
2323
with:
2424
user: __token__
2525
password: ${{ secrets.pypi_password }}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ jobs:
2020

2121
steps:
2222
- name: Checkout code
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2424

2525
- name: Run docker-compose
2626
run: SPLUNK_VERSION=${{matrix.splunk-version}} docker-compose up -d
2727

2828
- name: Setup Python
29-
uses: actions/setup-python@v2
29+
uses: actions/setup-python@v4
3030
with:
3131
python-version: ${{ matrix.python }}
3232

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
* Updated CI test matrix to run with Python versions - 3.7, 3.9 and 3.10.7
1414
* Refactored Code throwing `deprecation` warnings
1515
* Refactored Code violating Pylint rules
16+
## Version 1.7.4
17+
18+
### Bug fixes
19+
* [#532](https://github.com/splunk/splunk-sdk-python/pull/532) update encoding errors mode to 'replace' [[issue#505](https://github.com/splunk/splunk-sdk-python/issues/505)]
20+
* [#507](https://github.com/splunk/splunk-sdk-python/pull/507) masked sensitive data in logs [[issue#506](https://github.com/splunk/splunk-sdk-python/issues/506)]
21+
22+
### Minor changes
23+
* [#530](https://github.com/splunk/splunk-sdk-python/pull/530) Update GitHub CI build status in README and removed RTD(Read The Docs) reference
1624

1725
## Version 1.7.3
1826

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[![Build Status](https://travis-ci.org/splunk/splunk-sdk-python.svg?branch=master)](https://travis-ci.org/splunk/splunk-sdk-python)
2-
[![Documentation Status](https://readthedocs.org/projects/splunk-python-sdk/badge/?version=latest)](https://splunk-python-sdk.readthedocs.io/en/latest/?badge=latest)
1+
[![Build Status](https://github.com/splunk/splunk-sdk-python/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/splunk/splunk-sdk-python/actions/workflows/test.yml)
2+
3+
[Reference Docs](https://dev.splunk.com/enterprise/reference)
34

45
# The Splunk Enterprise Software Development Kit for Python
56

6-
#### Version 1.7.3
7+
#### Version 1.7.4
78

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

@@ -127,7 +128,7 @@ The Splunk Enterprise SDK for Python contains a collection of unit tests. To run
127128

128129
You can also run individual test files, which are located in **/splunk-sdk-python/tests**. To run a specific test, enter:
129130

130-
make specific_test_name
131+
make test_specific
131132

132133
The test suite uses Python's standard library, the built-in `unittest` library, `pytest`, and `tox`.
133134

scripts/test_specific.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
echo "To run a specific test:"
2-
echo " tox -e py27,py37 [test_file_path]::[test_name]"
2+
echo " tox -e py27,py37 [test_file_path]::[TestClassName]::[test_method]"
3+
echo "For Example, To run 'test_autologin' testcase from 'test_service.py' file run"
4+
echo " tox -e py37 -- tests/test_service.py::ServiceTestCase::test_autologin"

splunklib/binding.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"""
2626

2727
import io
28+
import json
2829
import logging
2930
import socket
3031
import ssl
@@ -57,6 +58,10 @@
5758
"namespace"
5859
]
5960

61+
SENSITIVE_KEYS = ['Authorization', 'Cookie', 'action.email.auth_password', 'auth', 'auth_password', 'clear_password', 'clientId',
62+
'crc-salt', 'encr_password', 'oldpassword', 'passAuth', 'password', 'session', 'suppressionKey',
63+
'token']
64+
6065
# If you change these, update the docstring
6166
# on _authority as well.
6267
DEFAULT_HOST = "localhost"
@@ -76,6 +81,28 @@ def new_f(*args, **kwargs):
7681
return new_f
7782

7883

84+
def mask_sensitive_data(data):
85+
'''
86+
Masked sensitive fields data for logging purpose
87+
'''
88+
if not isinstance(data, dict):
89+
try:
90+
data = json.loads(data)
91+
except Exception as ex:
92+
return data
93+
94+
# json.loads will return "123"(str) as 123(int), so return the data if it's not 'dict' type
95+
if not isinstance(data, dict):
96+
return data
97+
mdata = {}
98+
for k, v in data.items():
99+
if k in SENSITIVE_KEYS:
100+
mdata[k] = "******"
101+
else:
102+
mdata[k] = mask_sensitive_data(v)
103+
return mdata
104+
105+
79106
def _parse_cookies(cookie_str, dictionary):
80107
"""Tries to parse any key-value pairs of cookies in a string,
81108
then updates the the dictionary with any key-value pairs found.
@@ -635,7 +662,7 @@ def delete(self, path_segment, owner=None, app=None, sharing=None, **query):
635662
"""
636663
path = self.authority + self._abspath(path_segment, owner=owner,
637664
app=app, sharing=sharing)
638-
logger.debug("DELETE request to %s (body: %s)", path, repr(query))
665+
logger.debug("DELETE request to %s (body: %s)", path, mask_sensitive_data(query))
639666
response = self.http.delete(path, self._auth_headers, **query)
640667
return response
641668

@@ -698,7 +725,7 @@ def get(self, path_segment, owner=None, app=None, headers=None, sharing=None, **
698725

699726
path = self.authority + self._abspath(path_segment, owner=owner,
700727
app=app, sharing=sharing)
701-
logger.debug("GET request to %s (body: %s)", path, repr(query))
728+
logger.debug("GET request to %s (body: %s)", path, mask_sensitive_data(query))
702729
all_headers = headers + self.additional_headers + self._auth_headers
703730
response = self.http.get(path, all_headers, **query)
704731
return response
@@ -777,12 +804,7 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *
777804

778805
path = self.authority + self._abspath(path_segment, owner=owner, app=app, sharing=sharing)
779806

780-
# To avoid writing sensitive data in debug logs
781-
endpoint_having_sensitive_data = ["/storage/passwords"]
782-
if any(endpoint in path for endpoint in endpoint_having_sensitive_data):
783-
logger.debug("POST request to %s ", path)
784-
else:
785-
logger.debug("POST request to %s (body: %s)", path, repr(query))
807+
logger.debug("POST request to %s (body: %s)", path, mask_sensitive_data(query))
786808
all_headers = headers + self.additional_headers + self._auth_headers
787809
response = self.http.post(path, all_headers, **query)
788810
return response
@@ -849,8 +871,7 @@ def request(self, path_segment, method="GET", headers=None, body={},
849871

850872
all_headers = headers + self.additional_headers + self._auth_headers
851873
logger.debug("%s request to %s (headers: %s, body: %s)",
852-
method, path, str(all_headers), repr(body))
853-
874+
method, path, str(mask_sensitive_data(dict(all_headers))), mask_sensitive_data(body))
854875
if body:
855876
body = _encode(**body)
856877

splunklib/modularinput/event_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def write_xml_document(self, document):
7272
7373
:param document: An ``ElementTree`` object.
7474
"""
75-
self._out.write(ensure_str(ET.tostring(document)))
75+
self._out.write(ensure_str(ET.tostring(document), errors="replace"))
7676
self._out.flush()
7777

7878
def close(self):

splunklib/searchcommands/search_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ def _read_chunk(istream):
919919
except Exception as error:
920920
raise RuntimeError(f'Failed to read body of length {body_length}: {error}')
921921

922-
return metadata, splunklib.ensure_str(body)
922+
return metadata, splunklib.ensure_str(body,errors="replace")
923923

924924
_header = re.compile(r'chunked\s+1.0\s*,\s*(\d+)\s*,\s*(\d+)\s*\n')
925925

tests/searchcommands/test_csc_apps.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
# under the License.
1616

1717
import unittest
18+
import pytest
19+
1820
from tests import testlib
1921
from splunklib import results
2022

21-
23+
@pytest.mark.smoke
2224
class TestCSC(testlib.SDKTestCase):
2325

2426
def test_eventing_app(self):

tests/test_binding.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def test_got_updated_cookie_with_get(self):
633633
self.assertEqual(list(new_cookies.values())[0], list(old_cookies.values())[0])
634634
self.assertTrue(found)
635635

636+
@pytest.mark.smoke
636637
def test_login_fails_with_bad_cookie(self):
637638
# We should get an error if using a bad cookie
638639
try:
@@ -641,6 +642,7 @@ def test_login_fails_with_bad_cookie(self):
641642
except AuthenticationError as ae:
642643
self.assertEqual(str(ae), "Login failed.")
643644

645+
@pytest.mark.smoke
644646
def test_login_with_multiple_cookies(self):
645647
# We should get an error if using a bad cookie
646648
new_context = binding.Context()

0 commit comments

Comments
 (0)