Skip to content

Commit 08103ad

Browse files
committed
Linting fixes
1 parent 3a05a0f commit 08103ad

File tree

5 files changed

+75
-65
lines changed

5 files changed

+75
-65
lines changed

detect/v1alpha/create_retrohunt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ def create_retrohunt(
8282
"""
8383
base_url_with_region = regions.url_always_prepend_region(
8484
CHRONICLE_API_BASE_URL, proj_region)
85+
# pylint: disable=line-too-long
8586
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
8687
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}/retrohunts"
88+
# pylint: enable=line-too-long
8789

8890
body = {
8991
"process_interval": {

detect/v1alpha/get_alert.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def get_alert(
7575
"""
7676
base_url_with_region = regions.url_always_prepend_region(
7777
CHRONICLE_API_BASE_URL, proj_region)
78+
# pylint: disable=line-too-long
7879
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
7980
url = f"{base_url_with_region}/v1alpha/{parent}/legacy:legacyGetAlert"
81+
# pylint: disable=line-too-long
8082

8183
query_params = {"alertId": alert_id}
8284
if include_detections:

detect/v1alpha/get_detection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ def get_detection(
7373
"""
7474
base_url_with_region = regions.url_always_prepend_region(
7575
CHRONICLE_API_BASE_URL, proj_region)
76+
# pylint: disable=line-too-long
7677
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
7778
url = f"{base_url_with_region}/v1alpha/{parent}/legacy:legacyGetDetection"
79+
# pylint: enable=line-too-long
7880

7981
query_params = {"detectionId": detection_id}
8082

ingestion/v1alpha/event_import.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,35 @@
3737
]
3838

3939

40-
def import_events(http_session: requests.AuthorizedSession, proj_id: str,
41-
proj_instance: str, proj_region: str,
42-
json_events: str) -> None:
40+
def import_events(
41+
http_session: requests.AuthorizedSession,
42+
proj_id: str,
43+
proj_instance: str,
44+
proj_region: str,
45+
json_events: str
46+
) -> None:
4347
"""Import events into Chronicle using the Events Import API.
4448
45-
Args:
46-
http_session: Authorized session for HTTP requests.
47-
proj_id: GCP project id or number to which the target instance belongs.
48-
proj_instance: Customer ID (uuid with dashes) for the Chronicle instance.
49-
proj_region: region in which the target project is located.
50-
json_events: Events in (serialized) JSON format.
49+
Args:
50+
http_session: Authorized session for HTTP requests.
51+
proj_id: GCP project id or number to which the target instance belongs.
52+
proj_instance: Customer ID (uuid w/ dashes) for the Chronicle instance.
53+
proj_region: region in which the target project is located.
54+
json_events: Events in (serialized) JSON format.
5155
52-
Raises:
53-
requests.exceptions.HTTPError: HTTP request resulted in an error
54-
(response.status_code >= 400).
56+
Raises:
57+
requests.exceptions.HTTPError: HTTP request resulted in an error
58+
(response.status_code >= 400).
5559
56-
Requires the following IAM permission on the parent resource:
57-
chronicle.events.import
60+
Requires the following IAM permission on the parent resource:
61+
chronicle.events.import
5862
"""
5963
base_url_with_region = regions.url_always_prepend_region(
6064
CHRONICLE_API_BASE_URL, proj_region)
65+
# pylint: disable=line-too-long
6166
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
6267
url = f"{base_url_with_region}/v1alpha/{parent}/events:import"
68+
# pylint: enable=line-too-long
6369

6470
body = {
6571
"events": json.loads(json_events),

ingestion/v1alpha/events_batch_get.py

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@
3838
]
3939

4040

41-
def batch_get_events(
42-
http_session: requests.AuthorizedSession,
43-
proj_id: str,
44-
proj_instance: str,
45-
proj_region: str,
46-
event_ids: str) -> None:
47-
"""Batch get events from Chronicle using the Events BatchGet API.
41+
def batch_get_events(http_session: requests.AuthorizedSession, proj_id: str,
42+
proj_instance: str, proj_region: str,
43+
event_ids: str) -> None:
44+
"""Batch get events from Chronicle using the Events BatchGet API.
4845
4946
Args:
5047
http_session: Authorized session for HTTP requests.
@@ -60,50 +57,51 @@ def batch_get_events(
6057
Requires the following IAM permission on the parent resource:
6158
chronicle.events.batchGet
6259
"""
63-
base_url_with_region = regions.url_always_prepend_region(
64-
CHRONICLE_API_BASE_URL,
65-
proj_region
66-
)
67-
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
68-
url = f"{base_url_with_region}/v1alpha/{parent}/events:batchGet"
69-
70-
# Convert event IDs to URL-encoded Base64 and create query parameters
71-
event_ids_list = json.loads(event_ids)
72-
encoded_ids = [base64.urlsafe_b64encode(id.encode()).decode() for id in event_ids_list]
73-
query_params = "&".join([f"names={id}" for id in encoded_ids])
74-
75-
url = f"{url}?{query_params}"
76-
77-
response = http_session.request("GET", url)
78-
if response.status_code >= 400:
79-
print(response.text)
80-
response.raise_for_status()
81-
82-
print(json.dumps(response.json(), indent=2))
60+
base_url_with_region = regions.url_always_prepend_region(
61+
CHRONICLE_API_BASE_URL, proj_region)
62+
# pylint: disable=line-too-long
63+
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
64+
url = f"{base_url_with_region}/v1alpha/{parent}/events:batchGet"
65+
# pylint: enable=line-too-long
66+
67+
# Convert event IDs to URL-encoded Base64 and create query parameters
68+
event_ids_list = json.loads(event_ids)
69+
encoded_ids = [
70+
base64.urlsafe_b64encode(id.encode()).decode() for id in event_ids_list
71+
]
72+
query_params = "&".join([f"names={id}" for id in encoded_ids])
73+
74+
url = f"{url}?{query_params}"
75+
76+
response = http_session.request("GET", url)
77+
if response.status_code >= 400:
78+
print(response.text)
79+
response.raise_for_status()
80+
81+
print(json.dumps(response.json(), indent=2))
8382

8483

8584
if __name__ == "__main__":
86-
parser = argparse.ArgumentParser()
87-
# common
88-
chronicle_auth.add_argument_credentials_file(parser)
89-
project_instance.add_argument_project_instance(parser)
90-
project_id.add_argument_project_id(parser)
91-
regions.add_argument_region(parser)
92-
# local
93-
parser.add_argument(
94-
"--event_ids",
95-
type=str,
96-
required=True,
97-
help='JSON string containing a list of event IDs to retrieve (e.g., \'["id1", "id2"]\')')
98-
99-
args = parser.parse_args()
100-
auth_session = chronicle_auth.initialize_http_session(
101-
args.credentials_file,
102-
SCOPES,
103-
)
104-
batch_get_events(
105-
auth_session,
106-
args.project_id,
107-
args.project_instance,
108-
args.region,
109-
args.event_ids)
85+
parser = argparse.ArgumentParser()
86+
# common
87+
chronicle_auth.add_argument_credentials_file(parser)
88+
project_instance.add_argument_project_instance(parser)
89+
project_id.add_argument_project_id(parser)
90+
regions.add_argument_region(parser)
91+
# local
92+
parser.add_argument(
93+
"--event_ids",
94+
type=str,
95+
required=True,
96+
help=
97+
'JSON string containing a list of event IDs to '
98+
'retrieve (e.g., \'["id1", "id2"]\')'
99+
)
100+
101+
args = parser.parse_args()
102+
auth_session = chronicle_auth.initialize_http_session(
103+
args.credentials_file,
104+
SCOPES,
105+
)
106+
batch_get_events(auth_session, args.project_id, args.project_instance,
107+
args.region, args.event_ids)

0 commit comments

Comments
 (0)