Skip to content

Commit

Permalink
feat: added --sc4s-version option (#802)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
kdoroszko-splunk and artemrys authored Nov 25, 2023
1 parent 3d2f34e commit 1557b3d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- id: semgrep
uses: returntocorp/semgrep-action@v1
uses: semgrep/semgrep-action@v1
with:
publishToken: ${{ secrets.SEMGREP_PUBLISH_TOKEN }}

Expand Down
59 changes: 33 additions & 26 deletions pytest_splunk_addon/splunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ def pytest_addoption(parser):
default="514",
help="SC4S Port. default is 514",
)
group.addoption(
"--sc4s-version",
action="store",
dest="sc4s_version",
default="latest",
help="SC4S version. default is latest",
)
group.addoption(
"--thread-count",
action="store",
Expand Down Expand Up @@ -416,32 +423,12 @@ def splunk(request, file_system_prerequisite):
"""
splunk_type = request.config.getoption("splunk_type")
LOGGER.info("Get the Splunk instance of splunk_type=%s", splunk_type)
if splunk_type == "external":
request.fixturenames.append("splunk_external")
splunk_info = request.getfixturevalue("splunk_external")
elif splunk_type == "docker":
os.environ["SPLUNK_APP_PACKAGE"] = request.config.getoption("splunk_app")
try:
config = configparser.ConfigParser()
config.read(
os.path.join(
request.config.getoption("splunk_app"),
"default",
"app.conf",
)
)
os.environ["SPLUNK_APP_ID"] = config["package"]["id"]
except Exception:
os.environ["SPLUNK_APP_ID"] = "TA_package"
os.environ["SPLUNK_HEC_TOKEN"] = request.config.getoption("splunk_hec_token")
os.environ["SPLUNK_USER"] = request.config.getoption("splunk_user")
os.environ["SPLUNK_PASSWORD"] = request.config.getoption("splunk_password")
os.environ["SPLUNK_VERSION"] = request.config.getoption("splunk_version")

request.fixturenames.append("splunk_docker")
splunk_info = request.getfixturevalue("splunk_docker")
else:
raise Exception
splunk_fixture = f"splunk_{splunk_type}"
try:
request.fixturenames.append(splunk_fixture)
splunk_info = request.getfixturevalue(splunk_fixture)
except Exception as e:
raise Exception(f"Failed to get Splunk fixture ({splunk_fixture}): {e}")

yield splunk_info

Expand Down Expand Up @@ -540,6 +527,26 @@ def splunk_docker(
Returns:
dict: Details of the splunk instance including host, port, username & password.
"""
# configuration of environment variables needed by docker-compose file
os.environ["SPLUNK_APP_PACKAGE"] = request.config.getoption("splunk_app")
try:
config = configparser.ConfigParser()
config.read(
os.path.join(
request.config.getoption("splunk_app"),
"default",
"app.conf",
)
)
os.environ["SPLUNK_APP_ID"] = config["package"]["id"]
except Exception:
os.environ["SPLUNK_APP_ID"] = "TA_package"
os.environ["SPLUNK_HEC_TOKEN"] = request.config.getoption("splunk_hec_token")
os.environ["SPLUNK_USER"] = request.config.getoption("splunk_user")
os.environ["SPLUNK_PASSWORD"] = request.config.getoption("splunk_password")
os.environ["SPLUNK_VERSION"] = request.config.getoption("splunk_version")
os.environ["SC4S_VERSION"] = request.config.getoption("sc4s_version")

LOGGER.info("Starting docker_service=splunk")
if worker_id:
# get the temp directory shared by all workers
Expand Down

0 comments on commit 1557b3d

Please sign in to comment.