Skip to content

Commit 3a0d2cc

Browse files
authored
Merge pull request #202 from google/chore/modules-request-helper-update
updated remaining modules to use request helpers
2 parents 5aedb74 + 7986a1d commit 3a0d2cc

57 files changed

Lines changed: 3092 additions & 2638 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.39.0] - 2026-04-02
9+
### Updated
10+
- Refactored Chronicle modules to use centralized `chronicle_request` and `chronicle_paginated_request` helper functions for improved code consistency and maintainability
11+
- Standardized `as_list` parameter support across paginated API methods
12+
813
## [0.38.0] - 2026-03-31
914
### Added
1015
- CLI local configuration support with `--local` flag for config set and view commands

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "secops"
7-
version = "0.38.0"
7+
version = "0.39.0"
88
description = "Python SDK for wrapping the Google SecOps API for common use cases"
99
readme = "README.md"
1010
requires-python = ">=3.10"

src/secops/chronicle/case.py

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
CaseList,
2525
CasePriority,
2626
)
27+
from secops.chronicle.utils.format_utils import (
28+
format_resource_id,
29+
remove_none_values,
30+
)
2731
from secops.chronicle.utils.request_utils import (
2832
chronicle_paginated_request,
2933
chronicle_request,
@@ -58,32 +62,29 @@ def get_cases(
5862
Raises:
5963
APIError: If the API request fails
6064
"""
61-
params: dict[str, Any] = {"pageSize": str(page_size)}
62-
63-
if page_token:
64-
params["pageToken"] = page_token
65+
params = remove_none_values(
66+
{
67+
"pageSize": str(page_size),
68+
"pageToken": page_token,
69+
"tenantId": tenant_id,
70+
}
71+
)
6572

6673
if start_time:
6774
params["createTime.startTime"] = start_time.strftime(
6875
"%Y-%m-%dT%H:%M:%S.%fZ"
6976
)
70-
7177
if end_time:
7278
params["createTime.endTime"] = end_time.strftime(
7379
"%Y-%m-%dT%H:%M:%S.%fZ"
7480
)
75-
7681
if case_ids:
7782
for case_id in case_ids:
7883
params["caseId"] = case_id
79-
8084
if asset_identifiers:
8185
for asset in asset_identifiers:
8286
params["assetId"] = asset
8387

84-
if tenant_id:
85-
params["tenantId"] = tenant_id
86-
8788
return chronicle_request(
8889
client,
8990
method="GET",
@@ -296,17 +297,15 @@ def execute_bulk_close(
296297
f"Valid values: {valid_values}"
297298
) from ve
298299

299-
body: dict[str, Any] = {
300-
"casesIds": case_ids,
301-
"closeReason": close_reason,
302-
}
303-
304-
if root_cause is not None:
305-
body["rootCause"] = root_cause
306-
if close_comment is not None:
307-
body["closeComment"] = close_comment
308-
if dynamic_parameters is not None:
309-
body["dynamicParameters"] = dynamic_parameters
300+
body = remove_none_values(
301+
{
302+
"casesIds": case_ids,
303+
"closeReason": close_reason,
304+
"rootCause": root_cause,
305+
"closeComment": close_comment,
306+
"dynamicParameters": dynamic_parameters,
307+
}
308+
)
310309

311310
return chronicle_request(
312311
client,
@@ -363,21 +362,20 @@ def get_case(client, case_name: str, expand: str | None = None) -> Case:
363362
Raises:
364363
APIError: If the API request fails
365364
"""
366-
if not case_name.startswith("projects/"):
367-
endpoint_path = f"cases/{case_name}"
368-
else:
369-
endpoint_path = case_name
365+
endpoint_path = format_resource_id(case_name)
370366

371-
params: dict[str, Any] = {}
372-
if expand:
373-
params["expand"] = expand
367+
params = remove_none_values(
368+
{
369+
"expand": expand,
370+
}
371+
)
374372

375373
data = chronicle_request(
376374
client,
377375
method="GET",
378-
endpoint_path=endpoint_path,
376+
endpoint_path=f"cases/{endpoint_path}",
379377
api_version=APIVersion.V1BETA,
380-
params=params,
378+
params=params or None,
381379
error_message="Failed to get case",
382380
)
383381

@@ -418,15 +416,14 @@ def list_cases(
418416
Raises:
419417
APIError: If the API request fails
420418
"""
421-
extra_params: dict[str, Any] = {}
422-
if filter_query:
423-
extra_params["filter"] = filter_query
424-
if order_by:
425-
extra_params["orderBy"] = order_by
426-
if expand:
427-
extra_params["expand"] = expand
428-
if distinct_by:
429-
extra_params["distinctBy"] = distinct_by
419+
extra_params = remove_none_values(
420+
{
421+
"filter": filter_query,
422+
"orderBy": order_by,
423+
"expand": expand,
424+
"distinctBy": distinct_by,
425+
}
426+
)
430427

431428
return chronicle_paginated_request(
432429
client,
@@ -435,7 +432,7 @@ def list_cases(
435432
items_key="cases",
436433
page_size=page_size,
437434
page_token=page_token,
438-
extra_params=extra_params if extra_params else None,
435+
extra_params=extra_params or None,
439436
as_list=as_list,
440437
)
441438

@@ -500,10 +497,7 @@ def patch_case(
500497
APIError: If the API request fails
501498
ValueError: If an invalid priority value is provided
502499
"""
503-
if not case_name.startswith("projects/"):
504-
endpoint_path = f"cases/{case_name}"
505-
else:
506-
endpoint_path = case_name
500+
endpoint_path = format_resource_id(case_name)
507501

508502
if "priority" in case_data and isinstance(case_data["priority"], str):
509503
case_priority = case_data["priority"]
@@ -519,17 +513,19 @@ def patch_case(
519513
f"Valid values: {valid_values}"
520514
) from ve
521515

522-
params: dict[str, Any] = {}
523-
if update_mask:
524-
params["updateMask"] = update_mask
516+
params = remove_none_values(
517+
{
518+
"updateMask": update_mask,
519+
}
520+
)
525521

526522
data = chronicle_request(
527523
client,
528524
method="PATCH",
529-
endpoint_path=endpoint_path,
525+
endpoint_path=f"cases/{endpoint_path}",
530526
api_version=APIVersion.V1BETA,
531527
json=case_data,
532-
params=params if params else None,
528+
params=params or None,
533529
error_message="Failed to patch case",
534530
)
535531

0 commit comments

Comments
 (0)