Skip to content

Commit 33e45fc

Browse files
committed
Presubmit fixes
1 parent b654695 commit 33e45fc

File tree

11 files changed

+152
-145
lines changed

11 files changed

+152
-145
lines changed

datatap/delete_datatap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2025 Google LLC
3+
# Copyright 2022 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

datatap/delete_datatap_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2022 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -62,4 +62,4 @@ def test_delete_datatap(self, mock_response, mock_session):
6262

6363
if __name__ == "__main__":
6464
unittest.main()
65-
65+

datatap/list_datatap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2025 Google LLC
3+
# Copyright 2022 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

datatap/update_datatap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2025 Google LLC
3+
# Copyright 2022 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

detect/v1alpha/enable_rule.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@
3333
import argparse
3434
import json
3535
from typing import Any, Mapping
36-
36+
from google.auth.transport import requests
3737
from common import chronicle_auth
3838
from common import project_id
3939
from common import project_instance
4040
from common import regions
41-
from google.auth.transport import requests
4241

4342
CHRONICLE_API_BASE_URL = "https://chronicle.googleapis.com"
4443
SCOPES = [
@@ -53,14 +52,15 @@ def enable_rule(
5352
proj_region: str,
5453
rule_id: str,
5554
) -> Mapping[str, Any]:
56-
"""Enables a detection rule.
55+
"""Enables a detection rule.
5756
5857
Args:
5958
http_session: Authorized session for HTTP requests.
6059
proj_id: GCP project id or number to which the target instance belongs.
6160
proj_instance: Customer ID (uuid with dashes) for the Chronicle instance.
6261
proj_region: region in which the target project is located.
63-
rule_id: Unique ID of the detection rule to enable (in the format "ru_<UUID>").
62+
rule_id: Unique ID of the detection rule to enable
63+
(in the format "ru_<UUID>").
6464
6565
Returns:
6666
Dictionary containing the rule's deployment information.
@@ -72,41 +72,41 @@ def enable_rule(
7272
Requires the following IAM permission on the parent resource:
7373
chronicle.rules.updateDeployment
7474
"""
75-
base_url_with_region = regions.url_always_prepend_region(
76-
CHRONICLE_API_BASE_URL, proj_region)
77-
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
78-
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}/deployment"
75+
base_url_with_region = regions.url_always_prepend_region(
76+
CHRONICLE_API_BASE_URL, proj_region)
77+
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
78+
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}/deployment"
7979

80-
body = {
81-
"enabled": True, # Set to False to disable the rule
82-
}
83-
params = {"update_mask": "enabled"}
80+
body = {
81+
"enabled": True, # Set to False to disable the rule
82+
}
83+
params = {"update_mask": "enabled"}
8484

85-
response = http_session.request("PATCH", url, params=params, json=body)
86-
if response.status_code >= 400:
87-
print(response.text)
88-
response.raise_for_status()
85+
response = http_session.request("PATCH", url, params=params, json=body)
86+
if response.status_code >= 400:
87+
print(response.text)
88+
response.raise_for_status()
8989

90-
return response.json()
90+
return response.json()
9191

9292

9393
if __name__ == "__main__":
94-
parser = argparse.ArgumentParser()
95-
# common
96-
chronicle_auth.add_argument_credentials_file(parser)
97-
project_instance.add_argument_project_instance(parser)
98-
project_id.add_argument_project_id(parser)
99-
regions.add_argument_region(parser)
100-
# local
101-
parser.add_argument("--rule_id",
102-
type=str,
103-
required=True,
104-
help='ID of rule to enable (format: "ru_<UUID>")')
105-
106-
args = parser.parse_args()
107-
108-
auth_session = chronicle_auth.initialize_http_session(
109-
args.credentials_file, SCOPES)
110-
result = enable_rule(auth_session, args.project_id, args.project_instance,
111-
args.region, args.rule_id)
112-
print(json.dumps(result, indent=2))
94+
parser = argparse.ArgumentParser()
95+
# common
96+
chronicle_auth.add_argument_credentials_file(parser)
97+
project_instance.add_argument_project_instance(parser)
98+
project_id.add_argument_project_id(parser)
99+
regions.add_argument_region(parser)
100+
# local
101+
parser.add_argument("--rule_id",
102+
type=str,
103+
required=True,
104+
help='ID of rule to enable (format: "ru_<UUID>")')
105+
106+
args = parser.parse_args()
107+
108+
auth_session = chronicle_auth.initialize_http_session(
109+
args.credentials_file, SCOPES)
110+
result = enable_rule(auth_session, args.project_id, args.project_instance,
111+
args.region, args.rule_id)
112+
print(json.dumps(result, indent=2))

detect/v2/disable_live_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2025 Google LLC
3+
# Copyright 2021 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

detect/v2/list_curated_rule_detections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2025 Google LLC
3+
# Copyright 2023 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

lists/list_lists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2025 Google LLC
3+
# Copyright 2021 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

search/v1alpha/asset_events_find.py

Lines changed: 105 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@ def find_asset_events(http_session: requests.AuthorizedSession,
5252
end_time: str,
5353
reference_time: Optional[str] = None,
5454
max_results: Optional[int] = None) -> None:
55-
"""Find asset events in Chronicle using the Legacy Find Asset Events API.
55+
"""Find asset events in Chronicle using the Legacy Find Asset Events API.
5656
5757
Args:
5858
http_session: Authorized session for HTTP requests.
5959
proj_id: GCP project id or number to which the target instance belongs.
60-
proj_instance: Customer ID (uuid with dashes) for the Chronicle instance.
60+
proj_instance: Customer ID (uuid with dashes) for the instance.
6161
proj_region: region in which the target project is located.
62-
asset_indicator: JSON string containing the asset indicator to search for.
62+
asset_indicator: JSON str containing the asset indicator to search for.
6363
start_time: Start time in RFC3339 format (e.g., "2024-01-01T00:00:00Z").
6464
end_time: End time in RFC3339 format (e.g., "2024-01-02T00:00:00Z").
65-
reference_time: Optional reference time in RFC3339 format for asset aliasing.
66-
max_results: Optional maximum number of results to return (default: 10000, max: 250000).
65+
reference_time: Optional reference time in RFC3339 format for
66+
asset aliasing.
67+
max_results: Optional maximum number of results to return
68+
(default: 10000, max: 250000).
6769
6870
Raises:
6971
requests.exceptions.HTTPError: HTTP request resulted in an error
@@ -73,100 +75,104 @@ def find_asset_events(http_session: requests.AuthorizedSession,
7375
Requires the following IAM permission on the instance resource:
7476
chronicle.legacies.legacyFindAssetEvents
7577
"""
76-
# Validate and parse the times to ensure they're in RFC3339 format
77-
for time_str in [start_time, end_time, reference_time
78-
] if reference_time else [start_time, end_time]:
79-
try:
80-
datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%SZ")
81-
except ValueError as e:
82-
if "does not match format" in str(e):
83-
raise ValueError(
84-
f"Time '{time_str}' must be in RFC3339 format (e.g., '2024-01-01T00:00:00Z')"
85-
) from e
86-
raise
87-
88-
base_url_with_region = regions.url_always_prepend_region(
89-
CHRONICLE_API_BASE_URL, proj_region)
90-
instance = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
91-
url = f"{base_url_with_region}/v1alpha/{instance}/legacy:legacyFindAssetEvents"
92-
93-
# Build query parameters
94-
params = [
95-
f"assetIndicator={asset_indicator}",
96-
f"timeRange.startTime={start_time}", f"timeRange.endTime={end_time}"
97-
]
98-
99-
if reference_time:
100-
params.append(f"referenceTime={reference_time}")
101-
102-
if max_results:
103-
# Ensure max_results is within bounds
104-
max_results = min(max(1, max_results), MAX_RESULTS_LIMIT)
105-
params.append(f"maxResults={max_results}")
106-
107-
url = f"{url}?{'&'.join(params)}"
108-
109-
response = http_session.request("GET", url)
110-
if response.status_code >= 400:
111-
print(response.text)
112-
response.raise_for_status()
113-
114-
result = response.json()
115-
print(json.dumps(result, indent=2))
116-
117-
if result.get("more_data_available"):
118-
print(
119-
"\nWarning: More data is available but was not returned due to maxResults limit."
120-
)
121-
122-
if result.get("uri"):
123-
print("\nBackstory UI URLs:")
124-
for uri in result["uri"]:
125-
print(f" {uri}")
126-
127-
128-
if __name__ == "__main__":
129-
parser = argparse.ArgumentParser()
130-
# common
131-
chronicle_auth.add_argument_credentials_file(parser)
132-
project_instance.add_argument_project_instance(parser)
133-
project_id.add_argument_project_id(parser)
134-
regions.add_argument_region(parser)
135-
# local
136-
parser.add_argument(
137-
"--asset_indicator",
138-
type=str,
139-
required=True,
140-
help=
141-
"JSON string containing the asset indicator (e.g., '{\"hostname\": \"example.com\"}')"
142-
)
143-
parser.add_argument(
144-
"--start_time",
145-
type=str,
146-
required=True,
147-
help="Start time in RFC3339 format (e.g., '2024-01-01T00:00:00Z')")
148-
parser.add_argument(
149-
"--end_time",
150-
type=str,
151-
required=True,
152-
help="End time in RFC3339 format (e.g., '2024-01-02T00:00:00Z')")
153-
parser.add_argument(
154-
"--reference_time",
155-
type=str,
156-
help="Optional reference time in RFC3339 format for asset aliasing")
157-
parser.add_argument(
158-
"--max_results",
159-
type=int,
160-
help=
161-
f"Maximum number of results to return (default: {DEFAULT_MAX_RESULTS}, max: {MAX_RESULTS_LIMIT})"
78+
# Validate and parse the times to ensure they're in RFC3339 format
79+
for time_str in [start_time, end_time, reference_time
80+
] if reference_time else [start_time, end_time]:
81+
try:
82+
datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%SZ")
83+
except ValueError as e:
84+
if "does not match format" in str(e):
85+
raise ValueError(
86+
f"Time '{time_str}' must be in RFC3339 format "
87+
"(e.g., '2024-01-01T00:00:00Z')"
88+
) from e
89+
raise
90+
91+
base_url_with_region = regions.url_always_prepend_region(
92+
CHRONICLE_API_BASE_URL, proj_region)
93+
instance = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
94+
url = f"{base_url_with_region}/v1alpha/{instance}/legacy:legacyFindAssetEvents"
95+
96+
# Build query parameters
97+
params = [
98+
f"assetIndicator={asset_indicator}", f"timeRange.startTime={start_time}",
99+
f"timeRange.endTime={end_time}"
100+
]
101+
102+
if reference_time:
103+
params.append(f"referenceTime={reference_time}")
104+
105+
if max_results:
106+
# Ensure max_results is within bounds
107+
max_results = min(max(1, max_results), MAX_RESULTS_LIMIT)
108+
params.append(f"maxResults={max_results}")
109+
110+
url = f"{url}?{'&'.join(params)}"
111+
112+
response = http_session.request("GET", url)
113+
if response.status_code >= 400:
114+
print(response.text)
115+
response.raise_for_status()
116+
117+
result = response.json()
118+
print(json.dumps(result, indent=2))
119+
120+
if result.get("more_data_available"):
121+
print(
122+
"\nWarning: More data is available but was not returned due to "
123+
"maxResults limit."
162124
)
163125

164-
args = parser.parse_args()
126+
if result.get("uri"):
127+
print("\nBackstory UI URLs:")
128+
for uri in result["uri"]:
129+
print(f" {uri}")
165130

166-
auth_session = chronicle_auth.initialize_http_session(
167-
args.credentials_file,
168-
SCOPES,
169-
)
170-
find_asset_events(auth_session, args.project_id, args.project_instance,
171-
args.region, args.asset_indicator, args.start_time,
172-
args.end_time, args.reference_time, args.max_results)
131+
132+
if __name__ == "__main__":
133+
parser = argparse.ArgumentParser()
134+
# common
135+
chronicle_auth.add_argument_credentials_file(parser)
136+
project_instance.add_argument_project_instance(parser)
137+
project_id.add_argument_project_id(parser)
138+
regions.add_argument_region(parser)
139+
# local
140+
parser.add_argument(
141+
"--asset_indicator",
142+
type=str,
143+
required=True,
144+
help=
145+
"JSON string containing the asset indicator "
146+
"(e.g., '{\"hostname\": \"example.com\"}')"
147+
)
148+
parser.add_argument(
149+
"--start_time",
150+
type=str,
151+
required=True,
152+
help="Start time in RFC3339 format (e.g., '2024-01-01T00:00:00Z')")
153+
parser.add_argument(
154+
"--end_time",
155+
type=str,
156+
required=True,
157+
help="End time in RFC3339 format (e.g., '2024-01-02T00:00:00Z')")
158+
parser.add_argument(
159+
"--reference_time",
160+
type=str,
161+
help="Optional reference time in RFC3339 format for asset aliasing")
162+
parser.add_argument(
163+
"--max_results",
164+
type=int,
165+
help=
166+
"Maximum number of results to return "
167+
f"(default: {DEFAULT_MAX_RESULTS}, max: {MAX_RESULTS_LIMIT})"
168+
)
169+
170+
args = parser.parse_args()
171+
172+
auth_session = chronicle_auth.initialize_http_session(
173+
args.credentials_file,
174+
SCOPES,
175+
)
176+
find_asset_events(auth_session, args.project_id, args.project_instance,
177+
args.region, args.asset_indicator, args.start_time,
178+
args.end_time, args.reference_time, args.max_results)

service_management/get_gcp_association.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2025 Google LLC
3+
# Copyright 2021 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)