Skip to content

Commit f9a41cd

Browse files
committed
feat: remove eventgen.conf support
1 parent 81f783f commit f9a41cd

File tree

3 files changed

+14
-48
lines changed

3 files changed

+14
-48
lines changed

pytest_splunk_addon/standard_lib/sample_generation/eventgen_parser.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@
1717
import re
1818
import logging
1919
from splunk_appinspect import App
20-
from .rule import Rule, raise_warning
20+
from .rule import raise_warning
2121
from . import SampleStanza
2222

2323
LOGGER = logging.getLogger("pytest-splunk-addon")
24-
import warnings
2524

2625

2726
class EventgenParser:
2827
"""
2928
This class represents the entire eventgen.conf file and handles parsing mechanism of eventgen and the rules.
3029
3130
Args:
32-
addon_path (str): Path to the Splunk App
31+
addon_path: Path to the Splunk App
3332
"""
3433

3534
conf_name = " "
3635

37-
def __init__(self, addon_path, config_path=None):
36+
def __init__(self, addon_path: str, config_path: str):
3837
self._app = App(addon_path, python_analyzer_enable=False)
3938
self.config_path = config_path
4039
self._eventgen = None
@@ -84,31 +83,14 @@ def eventgen(self):
8483
path = self._app.get_filename(
8584
relative_path, "pytest-splunk-addon-data.conf"
8685
)
87-
88-
elif os.path.exists(os.path.join(self.config_path, "eventgen.conf")):
89-
90-
self._eventgen = self._app.get_config(
91-
"eventgen.conf", dir=relative_path
92-
)
93-
self.conf_name = "eventgen"
94-
path = self._app.get_filename(relative_path, "eventgen.conf")
95-
96-
else:
97-
self._eventgen = self._app.get_config("eventgen.conf")
98-
self.conf_name = "eventgen"
99-
path = self._app.get_filename("default", "eventgen.conf")
100-
LOGGER.info(
101-
"Using Eventgen path: {e}\nUsing Conf file name: {c}".format(
102-
e=path, c=self.conf_name
86+
LOGGER.info(
87+
f"Using Eventgen path: {path}\nUsing Conf file name: {self.conf_name}"
10388
)
104-
)
10589
return self._eventgen
10690

10791
except OSError:
108-
LOGGER.warning("pytest-splunk-addon-data.conf/eventgen.conf not Found")
109-
raise FileNotFoundError(
110-
"pytest-splunk-addon-data.conf/eventgen.conf not Found"
111-
)
92+
LOGGER.warning("pytest-splunk-addon-data.conf not found")
93+
raise FileNotFoundError("pytest-splunk-addon-data.conf not found")
11294

11395
def get_sample_stanzas(self):
11496
"""

pytest_splunk_addon/standard_lib/sample_generation/sample_generator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def get_samples(self):
4444
Generate SampleEvent object
4545
"""
4646
if not SampleGenerator.sample_stanzas:
47-
eventgen_parser = EventgenParser(
48-
self.addon_path, config_path=self.config_path
49-
)
47+
eventgen_parser = EventgenParser(self.addon_path, self.config_path)
5048
sample_stanzas = list(eventgen_parser.get_sample_stanzas())
5149
SampleGenerator.conf_name = eventgen_parser.conf_name
5250
with ThreadPoolExecutor(min(20, max(len(sample_stanzas), 1))) as t:

tests/unit/tests_standard_lib/tests_sample_generation/test_eventgen_parser.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,11 @@ def test_path_to_samples(self, eventgen_parser, exist_path):
6969
), patch("os.path.abspath", lambda x: x), patch("os.sep", "/"):
7070
assert ep.path_to_samples == path
7171

72-
@pytest.mark.parametrize(
73-
"exist_path, expected, args, kwargs",
74-
[
75-
(
76-
f"{CONFIG_PATH}/pytest-splunk-addon-data.conf",
77-
DATA_CONFIG,
78-
("pytest-splunk-addon-data.conf",),
79-
{"dir": "relpath_/config/path"},
80-
),
81-
(
82-
f"{CONFIG_PATH}/eventgen.conf",
83-
DATA_CONFIG,
84-
("eventgen.conf",),
85-
{"dir": "relpath_/config/path"},
86-
),
87-
(f"{CONFIG_PATH}/other", DATA_CONFIG, ("eventgen.conf",), {}),
88-
],
89-
)
90-
def test_eventgen(self, eventgen_parser, exist_path, expected, args, kwargs):
72+
def test_eventgen(self, eventgen_parser):
73+
exist_path = f"{CONFIG_PATH}/pytest-splunk-addon-data.conf"
74+
expected = DATA_CONFIG
75+
args = ("pytest-splunk-addon-data.conf",)
76+
kwargs = {"dir": "relpath_/config/path"}
9177
ep = eventgen_parser(ADDON_PATH, CONFIG_PATH)
9278
path = exist_path
9379
app_mock = MagicMock(spec=App)
@@ -104,7 +90,7 @@ def test_eventgen_os_error(self, eventgen_parser):
10490
with patch("os.path.exists", MagicMock(side_effect=OSError)):
10591
with pytest.raises(
10692
FileNotFoundError,
107-
match="pytest-splunk-addon-data.conf/eventgen.conf not Found",
93+
match="pytest-splunk-addon-data.conf not found",
10894
):
10995
ep.eventgen
11096

0 commit comments

Comments
 (0)