From 413657d72daa82e7e112da7659b804493a87a718 Mon Sep 17 00:00:00 2001 From: szymonjas <166526821+szymonjas@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:50:38 +0200 Subject: [PATCH 01/13] =?UTF-8?q?Revert=20"use=20SSL=20DEFAULT=20CONTEX,?= =?UTF-8?q?=20use=20tls=20version=20min=201.2,=20allow=20for=20usage=20of?= =?UTF-8?q?=20S=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 +- splunklib/binding.py | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8f660e8e..e97c7630 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v3 - name: Run docker-compose - run: SPLUNK_VERSION=${{matrix.splunk-version}} docker compose up -d + run: SPLUNK_VERSION=${{matrix.splunk-version}} docker-compose up -d - name: Setup Python uses: actions/setup-python@v4 diff --git a/splunklib/binding.py b/splunklib/binding.py index 25a09948..958be96e 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -465,8 +465,6 @@ class Context: :type scheme: "https" or "http" :param verify: Enable (True) or disable (False) SSL verification for https connections. :type verify: ``Boolean`` - :param self_signed_certificate: Specifies if self signed certificate is used - :type self_signed_certificate: ``Boolean`` :param sharing: The sharing mode for the namespace (the default is "user"). :type sharing: "global", "system", "app", or "user" :param owner: The owner context of the namespace (optional, the default is "None"). @@ -528,7 +526,6 @@ def __init__(self, handler=None, **kwargs): self.bearerToken = kwargs.get("splunkToken", "") self.autologin = kwargs.get("autologin", False) self.additional_headers = kwargs.get("headers", []) - self._self_signed_certificate = kwargs.get("self_signed_certificate", True) # Store any cookies in the self.http._cookies dict if "cookie" in kwargs and kwargs['cookie'] not in [None, _NoAuthenticationToken]: @@ -607,11 +604,7 @@ def connect(self): """ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if self.scheme == "https": - context = ssl.create_default_context() - context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 - context.check_hostname = not self._self_signed_certificate - context.verify_mode = ssl.CERT_NONE if self._self_signed_certificate else ssl.CERT_REQUIRED - sock = context.wrap_socket(sock, server_hostname=self.host) + sock = ssl.wrap_socket(sock) sock.connect((socket.gethostbyname(self.host), self.port)) return sock From f637ade7eeba88ed17074ae261f273b774e5168c Mon Sep 17 00:00:00 2001 From: Szymon Date: Wed, 25 Sep 2024 13:48:08 +0200 Subject: [PATCH 02/13] use SSL DEFAULT CONTEX, use tls version min 1.2, allow for usage of Self-signed certificate (cherry picked from commit 43041d14eba7423227bef7fc7548927bfb282756) --- splunklib/binding.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 958be96e..25a09948 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -465,6 +465,8 @@ class Context: :type scheme: "https" or "http" :param verify: Enable (True) or disable (False) SSL verification for https connections. :type verify: ``Boolean`` + :param self_signed_certificate: Specifies if self signed certificate is used + :type self_signed_certificate: ``Boolean`` :param sharing: The sharing mode for the namespace (the default is "user"). :type sharing: "global", "system", "app", or "user" :param owner: The owner context of the namespace (optional, the default is "None"). @@ -526,6 +528,7 @@ def __init__(self, handler=None, **kwargs): self.bearerToken = kwargs.get("splunkToken", "") self.autologin = kwargs.get("autologin", False) self.additional_headers = kwargs.get("headers", []) + self._self_signed_certificate = kwargs.get("self_signed_certificate", True) # Store any cookies in the self.http._cookies dict if "cookie" in kwargs and kwargs['cookie'] not in [None, _NoAuthenticationToken]: @@ -604,7 +607,11 @@ def connect(self): """ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if self.scheme == "https": - sock = ssl.wrap_socket(sock) + context = ssl.create_default_context() + context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 + context.check_hostname = not self._self_signed_certificate + context.verify_mode = ssl.CERT_NONE if self._self_signed_certificate else ssl.CERT_REQUIRED + sock = context.wrap_socket(sock, server_hostname=self.host) sock.connect((socket.gethostbyname(self.host), self.port)) return sock From 180cdd23057b51bd5c0b003c44ada96493db3255 Mon Sep 17 00:00:00 2001 From: Szymon Date: Tue, 29 Oct 2024 16:57:52 +0100 Subject: [PATCH 03/13] Add changelog --- CHANGELOG.md | 21 +++++++++++++++++++++ README.md | 2 +- splunklib/__init__.py | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e423e67..f37733cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Splunk Enterprise SDK for Python Changelog +## Version 2.1.0 + +### Changes +* [#516](https://github.com/splunk/splunk-sdk-python/pull/516) Added support for macros +* Remove deprecated `wrap_socket` in `Contex` class. +* Added explicit support for self signed certificates in https +* Enforce minimal required tls version in https connection +* Add support for python 3.13 + +## Version 2.0.2 + +### Minor changes +* Added six.py file back + + +## Version 2.0.1 + +### Bug fixes +* [#567](https://github.com/splunk/splunk-sdk-python/issues/567) Moved "deprecation" dependency + + ## Version 2.0.0 ### Feature updates diff --git a/README.md b/README.md index 2bbae4de..e200fc9b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # The Splunk Enterprise Software Development Kit for Python -#### Version 2.0.0 +#### Version 2.1.0 The Splunk Enterprise Software Development Kit (SDK) for Python contains library code designed to enable developers to build applications using the Splunk platform. diff --git a/splunklib/__init__.py b/splunklib/__init__.py index 2613d284..5f83b2ac 100644 --- a/splunklib/__init__.py +++ b/splunklib/__init__.py @@ -30,5 +30,5 @@ def setup_logging(level, log_format=DEFAULT_LOG_FORMAT, date_format=DEFAULT_DATE datefmt=date_format) -__version_info__ = (2, 0, 0) +__version_info__ = (2, 1, 0) __version__ = ".".join(map(str, __version_info__)) From 25c44e9098e8c48df13e080b2d0202dcf585e748 Mon Sep 17 00:00:00 2001 From: Szymon Date: Tue, 29 Oct 2024 17:04:15 +0100 Subject: [PATCH 04/13] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f37733cb..288543c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Added explicit support for self signed certificates in https * Enforce minimal required tls version in https connection * Add support for python 3.13 +* [#559](https://github.com/splunk/splunk-sdk-python/pull/559/) Add exception logging ## Version 2.0.2 From d36db5ee76b3ba1837ac0157e7386fd17a63ff7f Mon Sep 17 00:00:00 2001 From: Szymon Date: Wed, 30 Oct 2024 10:35:38 +0100 Subject: [PATCH 05/13] update ReadMe --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e200fc9b..7cd66cc2 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ The Splunk Enterprise SDK for Python contains library code, and its examples are Here's what you need to get going with the Splunk Enterprise SDK for Python. -* Python 3.7 or Python 3.9 +* Python 3.7, Python 3.9 and Python 3.13 - The Splunk Enterprise SDK for Python is compatible with python3 and has been tested with Python v3.7 and v3.9. + The Splunk Enterprise SDK for Python is compatible with python3 and has been tested with Python v3.7, v3.9 and v3.13. * Splunk Enterprise 9.2 or 8.2 From e33d919e4c03796916d0a06e26284c983976d27f Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 10 Feb 2025 16:35:16 +0100 Subject: [PATCH 06/13] Use relative imports for splunk-sdk --- splunklib/binding.py | 4 ++-- splunklib/client.py | 8 ++++---- splunklib/modularinput/event.py | 2 +- splunklib/modularinput/event_writer.py | 2 +- splunklib/searchcommands/search_command.py | 4 +--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 25a09948..c5f361b8 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -39,8 +39,8 @@ from http import client from http.cookies import SimpleCookie from xml.etree.ElementTree import XML, ParseError -from splunklib.data import record -from splunklib import __version__ +from .data import record +from . import __version__ logger = logging.getLogger(__name__) diff --git a/splunklib/client.py b/splunklib/client.py index ee390c9e..c78ea88d 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -68,9 +68,9 @@ from time import sleep from urllib import parse -from splunklib import data -from splunklib.data import record -from splunklib.binding import (AuthenticationError, Context, HTTPError, UrlEncoded, +from . import data +from .data import record +from .binding import (AuthenticationError, Context, HTTPError, UrlEncoded, _encode, _make_cookie_header, _NoAuthenticationToken, namespace) @@ -3999,4 +3999,4 @@ def batch_save(self, *documents): data = json.dumps(documents) return json.loads( - self._post('batch_save', headers=KVStoreCollectionData.JSON_HEADER, body=data).body.read().decode('utf-8')) \ No newline at end of file + self._post('batch_save', headers=KVStoreCollectionData.JSON_HEADER, body=data).body.read().decode('utf-8')) diff --git a/splunklib/modularinput/event.py b/splunklib/modularinput/event.py index 7ee7266a..bebd61e4 100644 --- a/splunklib/modularinput/event.py +++ b/splunklib/modularinput/event.py @@ -15,7 +15,7 @@ from io import TextIOBase import xml.etree.ElementTree as ET -from splunklib.utils import ensure_str +from ..utils import ensure_str class Event: diff --git a/splunklib/modularinput/event_writer.py b/splunklib/modularinput/event_writer.py index 7be3845a..7ea37ca8 100644 --- a/splunklib/modularinput/event_writer.py +++ b/splunklib/modularinput/event_writer.py @@ -15,7 +15,7 @@ import sys import traceback -from splunklib.utils import ensure_str +from ..utils import ensure_str from .event import ET diff --git a/splunklib/searchcommands/search_command.py b/splunklib/searchcommands/search_command.py index 7e8f771e..e66f70c3 100644 --- a/splunklib/searchcommands/search_command.py +++ b/splunklib/searchcommands/search_command.py @@ -34,11 +34,8 @@ from urllib.parse import urlsplit from warnings import warn from xml.etree import ElementTree -from splunklib.utils import ensure_str - # Relative imports -import splunklib from . import Boolean, Option, environment from .internals import ( CommandLineParser, @@ -53,6 +50,7 @@ RecordWriterV2, json_encode_string) from ..client import Service +from ..utils import ensure_str # ---------------------------------------------------------------------------------------------------------------------- From 75e9a43c6aed2633dca67663c74e11e5aea342f5 Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 08:44:30 +0200 Subject: [PATCH 07/13] Test fix pipeline --- .github/workflows/test.yml | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc8bd208..e65cf0f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,13 +9,36 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: - - ubuntu-latest - python: [ 3.7, 3.9, 3.13] - splunk-version: - - "8.1" - - "8.2" - - "latest" + include: + - os: ubuntu-22.04 # Only for Python 3.7 + python: 3.7 + splunk-version: "8.1" + - os: ubuntu-22.04 + python: 3.7 + splunk-version: "8.2" + - os: ubuntu-22.04 + python: 3.7 + splunk-version: "latest" + + - os: ubuntu-latest # For newer Python versions + python: 3.9 + splunk-version: "8.1" + - os: ubuntu-latest + python: 3.9 + splunk-version: "8.2" + - os: ubuntu-latest + python: 3.9 + splunk-version: "latest" + + - os: ubuntu-latest + python: 3.13 + splunk-version: "8.1" + - os: ubuntu-latest + python: 3.13 + splunk-version: "8.2" + - os: ubuntu-latest + python: 3.13 + splunk-version: "latest" fail-fast: false steps: From ef8a3b4b69597bd1ea9116c776b437304896f8f1 Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:09:00 +0200 Subject: [PATCH 08/13] Test fix pipeline --- .github/workflows/test.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e65cf0f6..7837c27a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,36 +9,31 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: + splunk-version: + - "8.1" + - "8.2" + - "latest" include: - os: ubuntu-22.04 # Only for Python 3.7 python: 3.7 - splunk-version: "8.1" - os: ubuntu-22.04 python: 3.7 - splunk-version: "8.2" - os: ubuntu-22.04 python: 3.7 - splunk-version: "latest" - os: ubuntu-latest # For newer Python versions python: 3.9 - splunk-version: "8.1" - os: ubuntu-latest python: 3.9 - splunk-version: "8.2" - os: ubuntu-latest python: 3.9 - splunk-version: "latest" - os: ubuntu-latest python: 3.13 - splunk-version: "8.1" - os: ubuntu-latest python: 3.13 - splunk-version: "8.2" - os: ubuntu-latest python: 3.13 - splunk-version: "latest" fail-fast: false steps: From e25fc1b999cc6feb5d1ecca0117f615bb6192163 Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:16:55 +0200 Subject: [PATCH 09/13] Test fix pipeline --- .github/workflows/test.yml | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7837c27a..e5ff1e2b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,31 +9,24 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: + os: + - ubuntu-latest + python: [ 3.7, 3.9, 3.13 ] splunk-version: - "8.1" - "8.2" - "latest" include: - - os: ubuntu-22.04 # Only for Python 3.7 + - os: ubuntu-22.04 python: 3.7 + splunk-version: "8.1" - os: ubuntu-22.04 python: 3.7 + splunk-version: "8.2" - os: ubuntu-22.04 python: 3.7 + splunk-version: "latest" - - os: ubuntu-latest # For newer Python versions - python: 3.9 - - os: ubuntu-latest - python: 3.9 - - os: ubuntu-latest - python: 3.9 - - - os: ubuntu-latest - python: 3.13 - - os: ubuntu-latest - python: 3.13 - - os: ubuntu-latest - python: 3.13 fail-fast: false steps: From 2586111432a10c89494fae97af0dde6eb1cb098a Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:17:47 +0200 Subject: [PATCH 10/13] Test fix pipeline --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e5ff1e2b..9ef02c94 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: matrix: os: - ubuntu-latest - python: [ 3.7, 3.9, 3.13 ] + python: [ 3.9, 3.13 ] splunk-version: - "8.1" - "8.2" From 7418861064a7c4aa8fab3f4fdf3296d0e2c04f10 Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:21:03 +0200 Subject: [PATCH 11/13] Test fix pipeline --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ef02c94..329c686c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Python CI on: - [ push, pull_request, workflow_dispatch ] + [ push, workflow_dispatch ] jobs: build: From 3b6d974dca26fd4bf29b5bf316f56b5f87b6bd90 Mon Sep 17 00:00:00 2001 From: szymonjas <166526821+szymonjas@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:01:21 +0200 Subject: [PATCH 12/13] Revert "Fix pipeline" --- .github/workflows/test.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 329c686c..dc8bd208 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Python CI on: - [ push, workflow_dispatch ] + [ push, pull_request, workflow_dispatch ] jobs: build: @@ -11,22 +11,11 @@ jobs: matrix: os: - ubuntu-latest - python: [ 3.9, 3.13 ] + python: [ 3.7, 3.9, 3.13] splunk-version: - "8.1" - "8.2" - "latest" - include: - - os: ubuntu-22.04 - python: 3.7 - splunk-version: "8.1" - - os: ubuntu-22.04 - python: 3.7 - splunk-version: "8.2" - - os: ubuntu-22.04 - python: 3.7 - splunk-version: "latest" - fail-fast: false steps: From de9f0f8685c9106d6145efc7bfae3147b0c18441 Mon Sep 17 00:00:00 2001 From: szymonjas <166526821+szymonjas@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:03:20 +0200 Subject: [PATCH 13/13] Revert "Use relative imports for splunk-sdk" --- splunklib/binding.py | 4 ++-- splunklib/client.py | 8 ++++---- splunklib/modularinput/event.py | 2 +- splunklib/modularinput/event_writer.py | 2 +- splunklib/searchcommands/search_command.py | 4 +++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index c5f361b8..25a09948 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -39,8 +39,8 @@ from http import client from http.cookies import SimpleCookie from xml.etree.ElementTree import XML, ParseError -from .data import record -from . import __version__ +from splunklib.data import record +from splunklib import __version__ logger = logging.getLogger(__name__) diff --git a/splunklib/client.py b/splunklib/client.py index c78ea88d..ee390c9e 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -68,9 +68,9 @@ from time import sleep from urllib import parse -from . import data -from .data import record -from .binding import (AuthenticationError, Context, HTTPError, UrlEncoded, +from splunklib import data +from splunklib.data import record +from splunklib.binding import (AuthenticationError, Context, HTTPError, UrlEncoded, _encode, _make_cookie_header, _NoAuthenticationToken, namespace) @@ -3999,4 +3999,4 @@ def batch_save(self, *documents): data = json.dumps(documents) return json.loads( - self._post('batch_save', headers=KVStoreCollectionData.JSON_HEADER, body=data).body.read().decode('utf-8')) + self._post('batch_save', headers=KVStoreCollectionData.JSON_HEADER, body=data).body.read().decode('utf-8')) \ No newline at end of file diff --git a/splunklib/modularinput/event.py b/splunklib/modularinput/event.py index bebd61e4..7ee7266a 100644 --- a/splunklib/modularinput/event.py +++ b/splunklib/modularinput/event.py @@ -15,7 +15,7 @@ from io import TextIOBase import xml.etree.ElementTree as ET -from ..utils import ensure_str +from splunklib.utils import ensure_str class Event: diff --git a/splunklib/modularinput/event_writer.py b/splunklib/modularinput/event_writer.py index 7ea37ca8..7be3845a 100644 --- a/splunklib/modularinput/event_writer.py +++ b/splunklib/modularinput/event_writer.py @@ -15,7 +15,7 @@ import sys import traceback -from ..utils import ensure_str +from splunklib.utils import ensure_str from .event import ET diff --git a/splunklib/searchcommands/search_command.py b/splunklib/searchcommands/search_command.py index e66f70c3..7e8f771e 100644 --- a/splunklib/searchcommands/search_command.py +++ b/splunklib/searchcommands/search_command.py @@ -34,8 +34,11 @@ from urllib.parse import urlsplit from warnings import warn from xml.etree import ElementTree +from splunklib.utils import ensure_str + # Relative imports +import splunklib from . import Boolean, Option, environment from .internals import ( CommandLineParser, @@ -50,7 +53,6 @@ RecordWriterV2, json_encode_string) from ..client import Service -from ..utils import ensure_str # ----------------------------------------------------------------------------------------------------------------------