Skip to content

Commit 1557b3d

Browse files
feat: added --sc4s-version option (#802)
* feat: added --sc4s-version option * ci: rename semgrep * chore: refactor splunk fixture * chore: code refinement by use of splunk_fixture variable --------- Co-authored-by: Artem Rys <[email protected]>
1 parent 3d2f34e commit 1557b3d

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

.github/workflows/build-test-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
steps:
6969
- uses: actions/checkout@v3
7070
- id: semgrep
71-
uses: returntocorp/semgrep-action@v1
71+
uses: semgrep/semgrep-action@v1
7272
with:
7373
publishToken: ${{ secrets.SEMGREP_PUBLISH_TOKEN }}
7474

pytest_splunk_addon/splunk.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ def pytest_addoption(parser):
199199
default="514",
200200
help="SC4S Port. default is 514",
201201
)
202+
group.addoption(
203+
"--sc4s-version",
204+
action="store",
205+
dest="sc4s_version",
206+
default="latest",
207+
help="SC4S version. default is latest",
208+
)
202209
group.addoption(
203210
"--thread-count",
204211
action="store",
@@ -416,32 +423,12 @@ def splunk(request, file_system_prerequisite):
416423
"""
417424
splunk_type = request.config.getoption("splunk_type")
418425
LOGGER.info("Get the Splunk instance of splunk_type=%s", splunk_type)
419-
if splunk_type == "external":
420-
request.fixturenames.append("splunk_external")
421-
splunk_info = request.getfixturevalue("splunk_external")
422-
elif splunk_type == "docker":
423-
os.environ["SPLUNK_APP_PACKAGE"] = request.config.getoption("splunk_app")
424-
try:
425-
config = configparser.ConfigParser()
426-
config.read(
427-
os.path.join(
428-
request.config.getoption("splunk_app"),
429-
"default",
430-
"app.conf",
431-
)
432-
)
433-
os.environ["SPLUNK_APP_ID"] = config["package"]["id"]
434-
except Exception:
435-
os.environ["SPLUNK_APP_ID"] = "TA_package"
436-
os.environ["SPLUNK_HEC_TOKEN"] = request.config.getoption("splunk_hec_token")
437-
os.environ["SPLUNK_USER"] = request.config.getoption("splunk_user")
438-
os.environ["SPLUNK_PASSWORD"] = request.config.getoption("splunk_password")
439-
os.environ["SPLUNK_VERSION"] = request.config.getoption("splunk_version")
440-
441-
request.fixturenames.append("splunk_docker")
442-
splunk_info = request.getfixturevalue("splunk_docker")
443-
else:
444-
raise Exception
426+
splunk_fixture = f"splunk_{splunk_type}"
427+
try:
428+
request.fixturenames.append(splunk_fixture)
429+
splunk_info = request.getfixturevalue(splunk_fixture)
430+
except Exception as e:
431+
raise Exception(f"Failed to get Splunk fixture ({splunk_fixture}): {e}")
445432

446433
yield splunk_info
447434

@@ -540,6 +527,26 @@ def splunk_docker(
540527
Returns:
541528
dict: Details of the splunk instance including host, port, username & password.
542529
"""
530+
# configuration of environment variables needed by docker-compose file
531+
os.environ["SPLUNK_APP_PACKAGE"] = request.config.getoption("splunk_app")
532+
try:
533+
config = configparser.ConfigParser()
534+
config.read(
535+
os.path.join(
536+
request.config.getoption("splunk_app"),
537+
"default",
538+
"app.conf",
539+
)
540+
)
541+
os.environ["SPLUNK_APP_ID"] = config["package"]["id"]
542+
except Exception:
543+
os.environ["SPLUNK_APP_ID"] = "TA_package"
544+
os.environ["SPLUNK_HEC_TOKEN"] = request.config.getoption("splunk_hec_token")
545+
os.environ["SPLUNK_USER"] = request.config.getoption("splunk_user")
546+
os.environ["SPLUNK_PASSWORD"] = request.config.getoption("splunk_password")
547+
os.environ["SPLUNK_VERSION"] = request.config.getoption("splunk_version")
548+
os.environ["SC4S_VERSION"] = request.config.getoption("sc4s_version")
549+
543550
LOGGER.info("Starting docker_service=splunk")
544551
if worker_id:
545552
# get the temp directory shared by all workers

0 commit comments

Comments
 (0)