Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added --sc4s-version option #802

Merged
merged 4 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(f"splunk_{splunk_type}")
artemrys marked this conversation as resolved.
Show resolved Hide resolved
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it should have a simple unit test covering this logic but I am fine moving forward with this PR.

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
Loading