Skip to content

Commit 0b3399e

Browse files
committed
fix line-too-long
1 parent 08103ad commit 0b3399e

26 files changed

+1404
-783
lines changed

detect/v1alpha/batch_update_curated_rule_set_deployments.py

Lines changed: 90 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def batch_update_curated_rule_set_deployments(
6060
proj_instance: str,
6161
proj_region: str,
6262
) -> Mapping[str, Any]:
63-
"""Batch updates multiple curated rule set deployments.
63+
"""Batch updates multiple curated rule set deployments.
6464
6565
Args:
6666
http_session: Authorized session for HTTP requests.
@@ -78,96 +78,95 @@ def batch_update_curated_rule_set_deployments(
7878
Requires the following IAM permission on the parent resource:
7979
chronicle.curatedRuleSetDeployments.update
8080
"""
81-
base_url_with_region = regions.url_always_prepend_region(
82-
CHRONICLE_API_BASE_URL, proj_region)
83-
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
84-
85-
# We use "-" in the URL because we provide category and rule_set IDs
86-
# in the request data
87-
url = f"{base_url_with_region}/v1alpha/{parent}/curatedRuleSetCategories/-/curatedRuleSets/-/curatedRuleSetDeployments:batchUpdate"
88-
89-
def make_deployment_name(category: str, rule_set: str,
90-
precision: str) -> str:
91-
"""Helper function to create a deployment name."""
92-
return f"{parent}/curatedRuleSetCategories/{category}/curatedRuleSets/{rule_set}/curatedRuleSetDeployments/{precision}"
93-
94-
# Example deployment configurations - update these with actual IDs
95-
# Deployment A
96-
category_a = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
97-
rule_set_a = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
98-
precision_a = "broad"
99-
100-
# Deployment B
101-
category_b = "cccccccc-cccc-cccc-cccc-cccccccccccc"
102-
rule_set_b = "dddddddd-dddd-dddd-dddd-dddddddddddd"
103-
precision_b = "precise"
104-
105-
print("\nNOTE: Using example category/rule_set/precision IDs.")
106-
print("Please update the script with actual IDs before use.\n")
107-
108-
json_data = {
109-
"parent":
110-
f"{parent}/curatedRuleSetCategories/-/curatedRuleSets/-",
111-
"requests": [
112-
{
113-
"curated_rule_set_deployment": {
114-
"name":
115-
make_deployment_name(
116-
category_a,
117-
rule_set_a,
118-
precision_a,
119-
),
120-
"enabled":
121-
True,
122-
"alerting":
123-
False,
124-
},
125-
"update_mask": {
126-
"paths": ["alerting", "enabled"],
127-
},
128-
},
129-
{
130-
"curated_rule_set_deployment": {
131-
"name":
132-
make_deployment_name(
133-
category_b,
134-
rule_set_b,
135-
precision_b,
136-
),
137-
"enabled":
138-
True,
139-
"alerting":
140-
True,
141-
},
142-
"update_mask": {
143-
"paths": ["alerting", "enabled"],
144-
},
145-
},
146-
],
147-
}
148-
149-
response = http_session.request("POST", url, json=json_data)
150-
if response.status_code >= 400:
151-
print(response.text)
152-
response.raise_for_status()
153-
154-
return response.json()
81+
base_url_with_region = regions.url_always_prepend_region(
82+
CHRONICLE_API_BASE_URL, proj_region)
83+
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
84+
85+
# We use "-" in the URL because we provide category and rule_set IDs
86+
# in the request data
87+
url = f"{base_url_with_region}/v1alpha/{parent}/curatedRuleSetCategories/-/curatedRuleSets/-/curatedRuleSetDeployments:batchUpdate"
88+
89+
def make_deployment_name(category: str, rule_set: str, precision: str) -> str:
90+
"""Helper function to create a deployment name."""
91+
return f"{parent}/curatedRuleSetCategories/{category}/curatedRuleSets/{rule_set}/curatedRuleSetDeployments/{precision}"
92+
93+
# Example deployment configurations - update these with actual IDs
94+
# Deployment A
95+
category_a = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
96+
rule_set_a = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
97+
precision_a = "broad"
98+
99+
# Deployment B
100+
category_b = "cccccccc-cccc-cccc-cccc-cccccccccccc"
101+
rule_set_b = "dddddddd-dddd-dddd-dddd-dddddddddddd"
102+
precision_b = "precise"
103+
104+
print("\nNOTE: Using example category/rule_set/precision IDs.")
105+
print("Please update the script with actual IDs before use.\n")
106+
107+
json_data = {
108+
"parent":
109+
f"{parent}/curatedRuleSetCategories/-/curatedRuleSets/-",
110+
"requests": [
111+
{
112+
"curated_rule_set_deployment": {
113+
"name":
114+
make_deployment_name(
115+
category_a,
116+
rule_set_a,
117+
precision_a,
118+
),
119+
"enabled":
120+
True,
121+
"alerting":
122+
False,
123+
},
124+
"update_mask": {
125+
"paths": ["alerting", "enabled"],
126+
},
127+
},
128+
{
129+
"curated_rule_set_deployment": {
130+
"name":
131+
make_deployment_name(
132+
category_b,
133+
rule_set_b,
134+
precision_b,
135+
),
136+
"enabled":
137+
True,
138+
"alerting":
139+
True,
140+
},
141+
"update_mask": {
142+
"paths": ["alerting", "enabled"],
143+
},
144+
},
145+
],
146+
}
147+
148+
response = http_session.request("POST", url, json=json_data)
149+
if response.status_code >= 400:
150+
print(response.text)
151+
response.raise_for_status()
152+
153+
return response.json()
155154

156155

157156
if __name__ == "__main__":
158-
parser = argparse.ArgumentParser()
159-
# common
160-
chronicle_auth.add_argument_credentials_file(parser)
161-
project_id.add_argument_project_id(parser)
162-
project_instance.add_argument_project_instance(parser)
163-
regions.add_argument_region(parser)
164-
165-
args = parser.parse_args()
166-
167-
auth_session = chronicle_auth.initialize_http_session(
168-
args.credentials_file, SCOPES)
169-
result = batch_update_curated_rule_set_deployments(auth_session,
170-
args.project_id,
171-
args.project_instance,
172-
args.region)
173-
print(json.dumps(result, indent=2))
157+
parser = argparse.ArgumentParser()
158+
# common
159+
chronicle_auth.add_argument_credentials_file(parser)
160+
project_id.add_argument_project_id(parser)
161+
project_instance.add_argument_project_instance(parser)
162+
regions.add_argument_region(parser)
163+
164+
args = parser.parse_args()
165+
166+
auth_session = chronicle_auth.initialize_http_session(args.credentials_file,
167+
SCOPES)
168+
result = batch_update_curated_rule_set_deployments(auth_session,
169+
args.project_id,
170+
args.project_instance,
171+
args.region)
172+
print(json.dumps(result, indent=2))

detect/v1alpha/create_rule.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def create_rule(
6060
proj_region: str,
6161
rule_file_path: str,
6262
) -> Mapping[str, Any]:
63-
"""Creates a new detection rule to find matches in logs.
63+
"""Creates a new detection rule to find matches in logs.
6464
6565
Args:
6666
http_session: Authorized session for HTTP requests.
@@ -79,41 +79,41 @@ def create_rule(
7979
Requires the following IAM permission on the parent resource:
8080
chronicle.rules.create
8181
"""
82-
base_url_with_region = regions.url_always_prepend_region(
83-
CHRONICLE_API_BASE_URL, proj_region)
84-
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
85-
url = f"{base_url_with_region}/v1alpha/{parent}/rules"
82+
base_url_with_region = regions.url_always_prepend_region(
83+
CHRONICLE_API_BASE_URL, proj_region)
84+
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
85+
url = f"{base_url_with_region}/v1alpha/{parent}/rules"
8686

87-
body = {
88-
"text": rule_file_path.read(),
89-
}
87+
body = {
88+
"text": rule_file_path.read(),
89+
}
9090

91-
response = http_session.request("POST", url, json=body)
92-
if response.status_code >= 400:
93-
print(response.text)
94-
response.raise_for_status()
91+
response = http_session.request("POST", url, json=body)
92+
if response.status_code >= 400:
93+
print(response.text)
94+
response.raise_for_status()
9595

96-
return response.json()
96+
return response.json()
9797

9898

9999
if __name__ == "__main__":
100-
parser = argparse.ArgumentParser()
101-
# common
102-
chronicle_auth.add_argument_credentials_file(parser)
103-
project_instance.add_argument_project_instance(parser)
104-
project_id.add_argument_project_id(parser)
105-
regions.add_argument_region(parser)
106-
# local
107-
parser.add_argument(
108-
"--rule_file",
109-
type=argparse.FileType("r"),
110-
required=True,
111-
help="Path to file containing the rule content, or - for STDIN")
112-
113-
args = parser.parse_args()
114-
115-
auth_session = chronicle_auth.initialize_http_session(
116-
args.credentials_file, SCOPES)
117-
new_rule = create_rule(auth_session, args.project_id, args.project_instance,
118-
args.region, args.rule_file)
119-
print(json.dumps(new_rule, indent=2))
100+
parser = argparse.ArgumentParser()
101+
# common
102+
chronicle_auth.add_argument_credentials_file(parser)
103+
project_instance.add_argument_project_instance(parser)
104+
project_id.add_argument_project_id(parser)
105+
regions.add_argument_region(parser)
106+
# local
107+
parser.add_argument(
108+
"--rule_file",
109+
type=argparse.FileType("r"),
110+
required=True,
111+
help="Path to file containing the rule content, or - for STDIN")
112+
113+
args = parser.parse_args()
114+
115+
auth_session = chronicle_auth.initialize_http_session(args.credentials_file,
116+
SCOPES)
117+
new_rule = create_rule(auth_session, args.project_id, args.project_instance,
118+
args.region, args.rule_file)
119+
print(json.dumps(new_rule, indent=2))

detect/v1alpha/enable_rule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def enable_rule(
105105

106106
args = parser.parse_args()
107107

108-
auth_session = chronicle_auth.initialize_http_session(
109-
args.credentials_file, SCOPES)
108+
auth_session = chronicle_auth.initialize_http_session(args.credentials_file,
109+
SCOPES)
110110
result = enable_rule(auth_session, args.project_id, args.project_instance,
111-
args.region, args.rule_id)
111+
args.region, args.rule_id)
112112
print(json.dumps(result, indent=2))

detect/v1alpha/get_rule.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_rule(
5252
http_session: Authorized session for HTTP requests.
5353
proj_id: GCP project id or number to which the target instance belongs.
5454
proj_instance: Customer ID (uuid with dashes) for the Chronicle instance.
55-
proj_region: region in which the target project is located.
55+
proj_region: Region where the target project is located.
5656
rule_id: Unique ID of the detection rule to retrieve ("ru_<UUID>" or
5757
"ru_<UUID>@v_<seconds>_<nanoseconds>"). If a version suffix isn't
5858
specified we use the rule's latest version.
@@ -69,8 +69,10 @@ def get_rule(
6969
"""
7070
base_url_with_region = regions.url_always_prepend_region(
7171
CHRONICLE_API_BASE_URL, proj_region)
72+
# pylint: disable=line-too-long
7273
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
7374
url = f"{base_url_with_region}/v1alpha/{parent}/rules/{rule_id}"
75+
# pylint: enable=line-too-lon
7476

7577
response = http_session.request("GET", url)
7678
if response.status_code >= 400:
@@ -88,13 +90,11 @@ def get_rule(
8890
project_id.add_argument_project_id(parser)
8991
regions.add_argument_region(parser)
9092
# local
91-
parser.add_argument(
92-
"--rule_id",
93-
type=str,
94-
required=True,
95-
help=
96-
'Unique ID of the rule to retrieve ("ru_<UUID>" or "ru_<UUID>@v_<seconds>_<nanoseconds>")'
97-
)
93+
parser.add_argument("--rule_id",
94+
type=str,
95+
required=True,
96+
help='Rule ID to retrieve ("ru_<UUID>" '
97+
'or "ru_<UUID>@v_<seconds>_<nanoseconds>")')
9898

9999
args = parser.parse_args()
100100

0 commit comments

Comments
 (0)