Skip to content

Commit 239ff30

Browse files
committed
yapf format to 2 spaces; isort imports
1 parent 4f92aa9 commit 239ff30

File tree

16 files changed

+655
-678
lines changed

16 files changed

+655
-678
lines changed

detect/v1alpha/bulk_update_alerts.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,49 +66,49 @@
6666
}
6767

6868
if __name__ == "__main__":
69-
parser = update_alert.get_update_parser()
70-
# local
71-
parser.add_argument("--alert_ids_file",
72-
type=str,
73-
required=True,
74-
help="Path to file containing one alert ID per line")
69+
parser = update_alert.get_update_parser()
70+
# local
71+
parser.add_argument("--alert_ids_file",
72+
type=str,
73+
required=True,
74+
help="Path to file containing one alert ID per line")
7575

76-
# Set default values from DEFAULT_FEEDBACK
77-
parser.set_defaults(
78-
comment=DEFAULT_FEEDBACK["comment"],
79-
reason=DEFAULT_FEEDBACK["reason"],
80-
reputation=DEFAULT_FEEDBACK["reputation"],
81-
root_cause=DEFAULT_FEEDBACK["root_cause"],
82-
status=DEFAULT_FEEDBACK["status"],
83-
verdict=DEFAULT_FEEDBACK["verdict"],
84-
)
76+
# Set default values from DEFAULT_FEEDBACK
77+
parser.set_defaults(
78+
comment=DEFAULT_FEEDBACK["comment"],
79+
reason=DEFAULT_FEEDBACK["reason"],
80+
reputation=DEFAULT_FEEDBACK["reputation"],
81+
root_cause=DEFAULT_FEEDBACK["root_cause"],
82+
status=DEFAULT_FEEDBACK["status"],
83+
verdict=DEFAULT_FEEDBACK["verdict"],
84+
)
8585

86-
args = parser.parse_args()
86+
args = parser.parse_args()
8787

88-
# Validate required arguments
89-
update_alert.check_args(parser, args)
88+
# Validate required arguments
89+
update_alert.check_args(parser, args)
9090

91-
auth_session = chronicle_auth.initialize_http_session(
92-
args.credentials_file, SCOPES)
91+
auth_session = chronicle_auth.initialize_http_session(args.credentials_file,
92+
SCOPES)
9393

94-
with open(args.alert_ids_file) as alert_file:
95-
for alert_id in alert_file:
96-
result = update_alert.update_alert(
97-
auth_session,
98-
args.project_id,
99-
args.project_instance,
100-
args.region,
101-
alert_id.strip(),
102-
args.confidence_score,
103-
args.reason,
104-
args.reputation,
105-
args.priority,
106-
args.status,
107-
args.verdict,
108-
args.risk_score,
109-
args.disregarded,
110-
args.severity,
111-
args.comment,
112-
args.root_cause,
113-
)
114-
print(json.dumps(result, indent=2))
94+
with open(args.alert_ids_file) as alert_file:
95+
for alert_id in alert_file:
96+
result = update_alert.update_alert(
97+
auth_session,
98+
args.project_id,
99+
args.project_instance,
100+
args.region,
101+
alert_id.strip(),
102+
args.confidence_score,
103+
args.reason,
104+
args.reputation,
105+
args.priority,
106+
args.status,
107+
args.verdict,
108+
args.risk_score,
109+
args.disregarded,
110+
args.severity,
111+
args.comment,
112+
args.root_cause,
113+
)
114+
print(json.dumps(result, indent=2))

detect/v1alpha/create_retrohunt.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_retrohunt(
5959
start_time: datetime.datetime,
6060
end_time: datetime.datetime,
6161
) -> Mapping[str, Any]:
62-
"""Creates a retrohunt to run a detection rule over historical data.
62+
"""Creates a retrohunt to run a detection rule over historical data.
6363
6464
Args:
6565
http_session: Authorized session for HTTP requests.
@@ -80,53 +80,53 @@ def create_retrohunt(
8080
Requires the following IAM permission on the parent resource:
8181
chronicle.retrohunts.create
8282
"""
83-
base_url_with_region = regions.url_always_prepend_region(
84-
CHRONICLE_API_BASE_URL, proj_region)
85-
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
86-
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}/retrohunts"
83+
base_url_with_region = regions.url_always_prepend_region(
84+
CHRONICLE_API_BASE_URL, proj_region)
85+
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
86+
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}/retrohunts"
8787

88-
body = {
89-
"process_interval": {
90-
"start_time": datetime_converter.strftime(start_time),
91-
"end_time": datetime_converter.strftime(end_time),
92-
},
93-
}
88+
body = {
89+
"process_interval": {
90+
"start_time": datetime_converter.strftime(start_time),
91+
"end_time": datetime_converter.strftime(end_time),
92+
},
93+
}
9494

95-
response = http_session.request("POST", url, json=body)
96-
if response.status_code >= 400:
97-
print(response.text)
98-
response.raise_for_status()
95+
response = http_session.request("POST", url, json=body)
96+
if response.status_code >= 400:
97+
print(response.text)
98+
response.raise_for_status()
9999

100-
return response.json()
100+
return response.json()
101101

102102

103103
if __name__ == "__main__":
104-
parser = argparse.ArgumentParser()
105-
# common
106-
chronicle_auth.add_argument_credentials_file(parser)
107-
project_instance.add_argument_project_instance(parser)
108-
project_id.add_argument_project_id(parser)
109-
regions.add_argument_region(parser)
110-
# local
111-
parser.add_argument(
112-
"--rule_id",
113-
type=str,
114-
required=True,
115-
help='ID of rule to create retrohunt for (format: "ru_<UUID>")')
116-
parser.add_argument("--start_time",
117-
type=datetime_converter.iso8601_datetime_utc,
118-
required=True,
119-
help="Start time in UTC (format: yyyy-mm-ddThh:mm:ssZ)")
120-
parser.add_argument("--end_time",
121-
type=datetime_converter.iso8601_datetime_utc,
122-
required=True,
123-
help="End time in UTC (format: yyyy-mm-ddThh:mm:ssZ)")
124-
125-
args = parser.parse_args()
126-
127-
auth_session = chronicle_auth.initialize_http_session(
128-
args.credentials_file, SCOPES)
129-
result = create_retrohunt(auth_session, args.project_id,
130-
args.project_instance, args.region, args.rule_id,
131-
args.start_time, args.end_time)
132-
print(json.dumps(result, indent=2))
104+
parser = argparse.ArgumentParser()
105+
# common
106+
chronicle_auth.add_argument_credentials_file(parser)
107+
project_instance.add_argument_project_instance(parser)
108+
project_id.add_argument_project_id(parser)
109+
regions.add_argument_region(parser)
110+
# local
111+
parser.add_argument(
112+
"--rule_id",
113+
type=str,
114+
required=True,
115+
help='ID of rule to create retrohunt for (format: "ru_<UUID>")')
116+
parser.add_argument("--start_time",
117+
type=datetime_converter.iso8601_datetime_utc,
118+
required=True,
119+
help="Start time in UTC (format: yyyy-mm-ddThh:mm:ssZ)")
120+
parser.add_argument("--end_time",
121+
type=datetime_converter.iso8601_datetime_utc,
122+
required=True,
123+
help="End time in UTC (format: yyyy-mm-ddThh:mm:ssZ)")
124+
125+
args = parser.parse_args()
126+
127+
auth_session = chronicle_auth.initialize_http_session(args.credentials_file,
128+
SCOPES)
129+
result = create_retrohunt(auth_session, args.project_id,
130+
args.project_instance, args.region, args.rule_id,
131+
args.start_time, args.end_time)
132+
print(json.dumps(result, indent=2))

detect/v1alpha/delete_rule.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def delete_rule(
4949
proj_instance: str,
5050
rule_id: str,
5151
) -> Mapping[str, Any]:
52-
"""Deletes a rule.
52+
"""Deletes a rule.
5353
5454
Args:
5555
http_session: Authorized session for HTTP requests.
@@ -65,44 +65,44 @@ def delete_rule(
6565
requests.exceptions.HTTPError: HTTP request resulted in an error
6666
(response.status_code >= 400).
6767
"""
68-
base_url_with_region = regions.url_always_prepend_region(
69-
CHRONICLE_API_BASE_URL, args.region)
70-
# pylint: disable-next=line-too-long
71-
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
72-
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}"
68+
base_url_with_region = regions.url_always_prepend_region(
69+
CHRONICLE_API_BASE_URL, args.region)
70+
# pylint: disable-next=line-too-long
71+
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
72+
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}"
7373

74-
# See API reference links at top of this file, for response format.
75-
response = http_session.request("DELETE", url)
76-
if response.status_code >= 400:
77-
print(response.text)
78-
response.raise_for_status()
79-
return response.json()
74+
# See API reference links at top of this file, for response format.
75+
response = http_session.request("DELETE", url)
76+
if response.status_code >= 400:
77+
print(response.text)
78+
response.raise_for_status()
79+
return response.json()
8080

8181

8282
if __name__ == "__main__":
83-
parser = argparse.ArgumentParser()
84-
chronicle_auth.add_argument_credentials_file(parser)
85-
regions.add_argument_region(parser)
86-
project_instance.add_argument_project_instance(parser)
87-
project_id.add_argument_project_id(parser)
88-
parser.add_argument(
89-
"-rid",
90-
"--rule_id",
91-
type=str,
92-
required=True,
93-
help='ID of rule to be deleted. In the form of "ru_<UUID>"',
94-
)
95-
args = parser.parse_args()
96-
auth_session = chronicle_auth.initialize_http_session(
97-
args.credentials_file, SCOPES)
98-
print(
99-
json.dumps(
100-
delete_rule(
101-
auth_session,
102-
args.region,
103-
args.project_id,
104-
args.project_instance,
105-
args.rule_id,
106-
),
107-
indent=2,
108-
))
83+
parser = argparse.ArgumentParser()
84+
chronicle_auth.add_argument_credentials_file(parser)
85+
regions.add_argument_region(parser)
86+
project_instance.add_argument_project_instance(parser)
87+
project_id.add_argument_project_id(parser)
88+
parser.add_argument(
89+
"-rid",
90+
"--rule_id",
91+
type=str,
92+
required=True,
93+
help='ID of rule to be deleted. In the form of "ru_<UUID>"',
94+
)
95+
args = parser.parse_args()
96+
auth_session = chronicle_auth.initialize_http_session(args.credentials_file,
97+
SCOPES)
98+
print(
99+
json.dumps(
100+
delete_rule(
101+
auth_session,
102+
args.region,
103+
args.project_id,
104+
args.project_instance,
105+
args.rule_id,
106+
),
107+
indent=2,
108+
))

detect/v1alpha/get_alert.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_alert(
5353
alert_id: str,
5454
include_detections: bool = False,
5555
) -> Mapping[str, Any]:
56-
"""Gets an Alert using the Legacy Get Alert API.
56+
"""Gets an Alert using the Legacy Get Alert API.
5757
5858
Args:
5959
http_session: Authorized session for HTTP requests.
@@ -73,49 +73,49 @@ def get_alert(
7373
Requires the following IAM permission on the parent resource:
7474
chronicle.alerts.get
7575
"""
76-
base_url_with_region = regions.url_always_prepend_region(
77-
CHRONICLE_API_BASE_URL, proj_region)
78-
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
79-
url = f"{base_url_with_region}/v1alpha/{parent}/legacy:legacyGetAlert"
76+
base_url_with_region = regions.url_always_prepend_region(
77+
CHRONICLE_API_BASE_URL, proj_region)
78+
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
79+
url = f"{base_url_with_region}/v1alpha/{parent}/legacy:legacyGetAlert"
8080

81-
query_params = {"alertId": alert_id}
82-
if include_detections:
83-
query_params["includeDetections"] = True
81+
query_params = {"alertId": alert_id}
82+
if include_detections:
83+
query_params["includeDetections"] = True
8484

85-
response = http_session.request("GET", url, params=query_params)
86-
if response.status_code >= 400:
87-
print(response.text)
88-
response.raise_for_status()
85+
response = http_session.request("GET", url, params=query_params)
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("--alert_id",
102-
type=str,
103-
required=True,
104-
help="Identifier for the alert")
105-
parser.add_argument("--include-detections",
106-
action="store_true",
107-
help="Include detections in the response")
108-
109-
args = parser.parse_args()
110-
111-
auth_session = chronicle_auth.initialize_http_session(
112-
args.credentials_file, SCOPES)
113-
alert = get_alert(
114-
auth_session,
115-
args.project_id,
116-
args.project_instance,
117-
args.region,
118-
args.alert_id,
119-
args.include_detections,
120-
)
121-
print(json.dumps(alert, 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("--alert_id",
102+
type=str,
103+
required=True,
104+
help="Identifier for the alert")
105+
parser.add_argument("--include-detections",
106+
action="store_true",
107+
help="Include detections in the response")
108+
109+
args = parser.parse_args()
110+
111+
auth_session = chronicle_auth.initialize_http_session(args.credentials_file,
112+
SCOPES)
113+
alert = get_alert(
114+
auth_session,
115+
args.project_id,
116+
args.project_instance,
117+
args.region,
118+
args.alert_id,
119+
args.include_detections,
120+
)
121+
print(json.dumps(alert, indent=2))

0 commit comments

Comments
 (0)