Skip to content

Commit 6923500

Browse files
committed
chore: minor refactoring and formatting
1 parent d436899 commit 6923500

7 files changed

Lines changed: 24 additions & 13 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,10 @@ chronicle.activate_parser(log_type=log_type, id=parser_id)
17401740
chronicle.deactivate_parser(log_type=log_type, id=parser_id)
17411741

17421742
# Fetch parser candidates (unactivated prebuilt parsers)
1743-
candidates = chronicle.fetch_parser_candidates(log_type=log_type, parser_action="PARSER_ACTION_OPT_IN_TO_PREVIEW")
1743+
candidates = chronicle.fetch_parser_candidates(
1744+
log_type=log_type,
1745+
parser_action="PARSER_ACTION_OPT_IN_TO_PREVIEW"
1746+
)
17441747

17451748
# Copy an existing parser as a starting point
17461749
copied_parser = chronicle.copy_parser(log_type=log_type, id="pa_existing_parser")

examples/example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def example_udm_search(chronicle):
7878

7979

8080
def example_udm_search_view(chronicle):
81-
"""Example 14: UDM Search View."""
82-
print("\n=== Example 14: UDM Search View ===")
81+
"""Example 15: UDM Search View."""
82+
print("\n=== Example 15: UDM Search View ===")
8383
start_time, end_time = get_time_range()
8484

8585
try:
@@ -1454,7 +1454,7 @@ def example_fetch_parser_candidates(chronicle):
14541454

14551455
def example_rule_test(chronicle):
14561456
"""Example 14: Test a detection rule against historical data."""
1457-
print("\n=== Example 13: Test a Detection Rule Against Historical Data ===")
1457+
print("\n=== Example 14: Test a Detection Rule Against Historical Data ===")
14581458

14591459
# Define time range for testing - use a recent time period (last 7 days)
14601460
end_time = datetime.now(timezone.utc) - timedelta(minutes=15)

src/secops/chronicle/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
merge_cases,
2929
patch_case,
3030
)
31-
from secops.chronicle.models import CaseCloseReason, CasePriority, ParserAction
31+
from secops.chronicle.models import CaseCloseReason, CasePriority
3232
from secops.chronicle.client import (
3333
ChronicleClient,
3434
ValueType,
@@ -137,6 +137,7 @@
137137
ListBasis,
138138
MonthlyScheduleDetails,
139139
OneTimeScheduleDetails,
140+
ParserAction,
140141
PrevalenceData,
141142
PythonVersion,
142143
ScheduleType,

src/secops/chronicle/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,7 @@ def fetch_parser_candidates(
27832783
log_type: str,
27842784
parser_action: ParserAction | str,
27852785
) -> list[Any]:
2786-
"""Retrieves prebuilt parsers candidates.
2786+
"""Retrieves prebuilt parser candidates.
27872787
27882788
Args:
27892789
log_type: Log type of the parser

src/secops/chronicle/parser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def fetch_parser_candidates(
241241
log_type: str,
242242
parser_action: "ParserAction | str",
243243
) -> list[Any]:
244-
"""Retrieves prebuilt parsers candidates.
244+
"""Retrieves prebuilt parser candidates.
245245
246246
Args:
247247
client: ChronicleClient instance
@@ -257,9 +257,11 @@ def fetch_parser_candidates(
257257
List of candidate parsers
258258
259259
Raises:
260-
ValueError: If parser_action is an invalid string value
260+
ValueError: If log_type is empty or parser_action is an invalid string
261261
APIError: If the API request fails
262262
"""
263+
if not log_type:
264+
raise ValueError("log_type cannot be empty")
263265
if isinstance(parser_action, str) and not isinstance(
264266
parser_action, ParserAction
265267
):
@@ -275,7 +277,7 @@ def fetch_parser_candidates(
275277
data = chronicle_request(
276278
client,
277279
method="GET",
278-
endpoint_path=(f"logTypes/{log_type}/parsers:fetchParserCandidates"),
280+
endpoint_path=f"logTypes/{log_type}/parsers:fetchParserCandidates",
279281
params={"parserAction": parser_action},
280282
error_message="Failed to fetch parser candidates",
281283
)

tests/chronicle/test_parser.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ def test_fetch_parser_candidates_success(chronicle_client, mock_response):
166166
with patch.object(
167167
chronicle_client.session, "request", return_value=mock_response
168168
) as mock_request:
169-
result = fetch_parser_candidates(chronicle_client, log_type, parser_action)
169+
result = fetch_parser_candidates(
170+
chronicle_client, log_type, parser_action
171+
)
170172

171173
expected_url = (
172174
f"{chronicle_client.base_url}/{chronicle_client.instance_id}"
@@ -192,7 +194,9 @@ def test_fetch_parser_candidates_empty(chronicle_client, mock_response):
192194
with patch.object(
193195
chronicle_client.session, "request", return_value=mock_response
194196
) as mock_request:
195-
result = fetch_parser_candidates(chronicle_client, log_type, parser_action)
197+
result = fetch_parser_candidates(
198+
chronicle_client, log_type, parser_action
199+
)
196200

197201
expected_url = (
198202
f"{chronicle_client.base_url}/{chronicle_client.instance_id}"
@@ -232,7 +236,9 @@ def test_fetch_parser_candidates_with_enum(chronicle_client, mock_response):
232236
with patch.object(
233237
chronicle_client.session, "request", return_value=mock_response
234238
) as mock_request:
235-
result = fetch_parser_candidates(chronicle_client, log_type, parser_action)
239+
result = fetch_parser_candidates(
240+
chronicle_client, log_type, parser_action
241+
)
236242

237243
expected_url = (
238244
f"{chronicle_client.base_url}/{chronicle_client.instance_id}"

tests/cli/test_integration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ def test_cli_fetch_parser_candidates(cli_env, common_args):
372372

373373
assert result.returncode == 0, f"Command failed: {result.stderr}"
374374

375-
376375
output = json.loads(result.stdout)
377376
assert isinstance(output, list)
378377
print(f"\nFetched {len(output)} parser candidate(s) for OKTA")

0 commit comments

Comments
 (0)