From ac960d14683f46d14a64d6fa6f67e563a19042e6 Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 08:44:30 +0200 Subject: [PATCH 1/9] 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 dc8bd2089..e65cf0f63 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 4321362b9173a8ad1548057cff569c4b5a5c8e54 Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:09:00 +0200 Subject: [PATCH 2/9] 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 e65cf0f63..7837c27a7 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 f9d42017b22efe97c8c55d95e66f7c194daabc1c Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:16:55 +0200 Subject: [PATCH 3/9] 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 7837c27a7..e5ff1e2b6 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 9e62653c31244eb95a80a2bd2351742143a6f4d0 Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:17:47 +0200 Subject: [PATCH 4/9] 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 e5ff1e2b6..9ef02c94d 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 f91300f17d19109a63c6f9916df6825d9b97019c Mon Sep 17 00:00:00 2001 From: Jakub Ramatowski Date: Thu, 3 Apr 2025 12:21:03 +0200 Subject: [PATCH 5/9] 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 9ef02c94d..329c686c4 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 178656dd7ec0085fe694ae105e99d8df835e9484 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 10 Feb 2025 16:35:16 +0100 Subject: [PATCH 6/9] 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 25a099489..c5f361b8a 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 ee390c9ed..c78ea88d1 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 7ee7266ab..bebd61e46 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 7be3845ab..7ea37ca81 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 7e8f771e1..e66f70c33 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 743c8b6c1013ed5104f509bd59fb429432b4ac31 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 7/9] 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 c5f361b8a..25a099489 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 c78ea88d1..ee390c9ed 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 bebd61e46..7ee7266ab 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 7ea37ca81..7be3845ab 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 e66f70c33..7e8f771e1 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 # ---------------------------------------------------------------------------------------------------------------------- From c0e0aa7fb91eb5b6a263774441b2b513c63df3a1 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 8/9] 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 329c686c4..dc8bd2089 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 310f653d0f77283610fbda14d7162c9bbb8eb5b2 Mon Sep 17 00:00:00 2001 From: maszyk99 Date: Fri, 27 Jun 2025 20:30:25 +0200 Subject: [PATCH 9/9] SDK-23: check if developer added custom map method --- splunklib/searchcommands/internals.py | 2 +- splunklib/searchcommands/reporting_command.py | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/splunklib/searchcommands/internals.py b/splunklib/searchcommands/internals.py index abceac30f..5f20c3faf 100644 --- a/splunklib/searchcommands/internals.py +++ b/splunklib/searchcommands/internals.py @@ -554,7 +554,7 @@ def write_record(self, record): def write_records(self, records): self._ensure_validity() - records = list(records) + records = [] if records is NotImplemented else list(records) write_record = self._write_record for record in records: write_record(record) diff --git a/splunklib/searchcommands/reporting_command.py b/splunklib/searchcommands/reporting_command.py index 5df3dc7e7..e455a159a 100644 --- a/splunklib/searchcommands/reporting_command.py +++ b/splunklib/searchcommands/reporting_command.py @@ -77,21 +77,26 @@ def map(self, records): """ return NotImplemented - def prepare(self): - - phase = self.phase + def _has_custom_method(self, method_name): + method = getattr(self.__class__, method_name, None) + base_method = getattr(ReportingCommand, method_name, None) + return callable(method) and (method is not base_method) - if phase == 'map': - # noinspection PyUnresolvedReferences - self._configuration = self.map.ConfigurationSettings(self) + def prepare(self): + if self.phase == 'map': + if self._has_custom_method('map'): + phase_method = getattr(self.__class__, 'map') + self._configuration = phase_method.ConfigurationSettings(self) + else: + self._configuration = self.ConfigurationSettings(self) return - if phase == 'reduce': + if self.phase == 'reduce': streaming_preop = chain((self.name, 'phase="map"', str(self._options)), self.fieldnames) self._configuration.streaming_preop = ' '.join(streaming_preop) return - raise RuntimeError(f'Unrecognized reporting command phase: {json_encode_string(str(phase))}') + raise RuntimeError(f'Unrecognized reporting command phase: {json_encode_string(str(self.phase))}') def reduce(self, records): """ Override this method to produce a reporting data structure.