Skip to content

Commit 880bcd6

Browse files
committed
SDK bugs
1 parent ab00567 commit 880bcd6

File tree

6 files changed

+19
-117
lines changed

6 files changed

+19
-117
lines changed

detect/v1alpha/get_detection.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
--project_id=<PROJECT_ID> \
2323
--project_instance=<PROJECT_INSTANCE> \
2424
--region=<REGION> \
25-
--detection_id=<DETECTION_ID>
25+
--detection_id=<DETECTION_ID> \
26+
--rule_id=<RULE_ID>
2627
2728
API reference:
2829
https://cloud.google.com/chronicle/docs/reference/rest/v1alpha/projects.locations.instances.legacy/legacyGetDetection
@@ -51,6 +52,7 @@ def get_detection(
5152
proj_instance: str,
5253
proj_region: str,
5354
detection_id: str,
55+
rule_id: str,
5456
) -> Mapping[str, Any]:
5557
"""Gets a Detection using the Legacy Get Detection API.
5658
@@ -60,6 +62,7 @@ def get_detection(
6062
proj_instance: Customer ID (uuid with dashes) for the Chronicle instance.
6163
proj_region: region in which the target project is located.
6264
detection_id: Identifier for the detection.
65+
rule_id: Identifier for the rule that created the detection.
6366
6467
Returns:
6568
Dictionary representation of the Detection.
@@ -78,7 +81,7 @@ def get_detection(
7881
url = f"{base_url_with_region}/v1alpha/{parent}/legacy:legacyGetDetection"
7982
# pylint: enable=line-too-long
8083

81-
query_params = {"detectionId": detection_id}
84+
query_params = {"detectionId": detection_id, "ruleId": rule_id}
8285

8386
response = http_session.request("GET", url, params=query_params)
8487
if response.status_code >= 400:
@@ -100,6 +103,10 @@ def get_detection(
100103
type=str,
101104
required=True,
102105
help="Identifier for the detection")
106+
parser.add_argument("--rule_id",
107+
type=str,
108+
required=True,
109+
help="Identifier for the rule that created the detection")
103110

104111
args = parser.parse_args()
105112

@@ -111,5 +118,6 @@ def get_detection(
111118
args.project_instance,
112119
args.region,
113120
args.detection_id,
121+
args.rule_id,
114122
)
115123
print(json.dumps(detection, indent=2))

detect/v1alpha/list_detections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def list_detections(http_session: requests.AuthorizedSession,
9494
(response.status_code >= 400).
9595
"""
9696
base_url_with_region = regions.url_always_prepend_region(
97-
CHRONICLE_API_BASE_URL, args.region)
97+
CHRONICLE_API_BASE_URL, proj_region)
9898
# pylint: disable-next=line-too-long
9999
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
100100
url = f"{base_url_with_region}/v1alpha/{parent}/legacy:legacySearchDetections"

iocs/__init__.py

Whitespace-only changes.

iocs/v1alpha/__init__.py

Whitespace-only changes.

sdk/commands/detect.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@ def detections():
170170
required=True,
171171
help="Identifier for the detection.",
172172
)
173+
@click.option(
174+
"--rule-id",
175+
required=True,
176+
help="Identifier for the rule that created the detection.",
177+
)
173178
def get_detection_cmd(credentials_file, project_id, project_instance, region,
174-
detection_id):
179+
detection_id, rule_id):
175180
"""Get a detection by ID."""
176181
auth_session = chronicle_auth.initialize_http_session(
177182
credentials_file,
@@ -183,6 +188,7 @@ def get_detection_cmd(credentials_file, project_id, project_instance, region,
183188
project_instance,
184189
region,
185190
detection_id,
191+
rule_id,
186192
)
187193
print(json.dumps(detection, indent=2))
188194

@@ -211,9 +217,9 @@ def list_detections_cmd(credentials_file, project_id, project_instance, region,
211217
)
212218
result = list_detections.list_detections(
213219
auth_session,
220+
region,
214221
project_id,
215222
project_instance,
216-
region,
217223
filter,
218224
page_size,
219225
page_token,

sdk/commands/lists.py

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
from lists.v1alpha import create_list
2424
from lists.v1alpha import get_list
2525
from lists.v1alpha import patch_list
26-
from reference_lists.v1alpha import create_reference_list
27-
from reference_lists.v1alpha import get_reference_list
28-
from reference_lists.v1alpha import list_reference_lists
2926
from sdk.commands.common import add_common_options
3027

3128
SCOPES = [
@@ -137,116 +134,7 @@ def patch_list_cmd(credentials_file, project_id, project_instance, region,
137134
print(json.dumps(result, indent=2))
138135

139136

140-
@lists.group()
141-
def reference():
142-
"""Reference Lists API commands."""
143-
pass
144-
145-
146-
@reference.command("create")
147-
@add_common_options
148-
@click.option(
149-
"--reference-list-id",
150-
required=True,
151-
help="ID to use for the new reference list.",
152-
)
153-
@click.option(
154-
"--entries",
155-
required=True,
156-
help="JSON array of strings to add to the reference list.",
157-
)
158-
@click.option(
159-
"--syntax-type",
160-
type=click.Choice([
161-
"REFERENCE_LIST_SYNTAX_TYPE_UNSPECIFIED",
162-
"REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING",
163-
"REFERENCE_LIST_SYNTAX_TYPE_REGEX", "REFERENCE_LIST_SYNTAX_TYPE_CIDR"
164-
]),
165-
default="REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING",
166-
help="Type of entries in the list.",
167-
)
168-
@click.option(
169-
"--scope-names",
170-
help="Optional JSON array of scope names.",
171-
)
172-
@click.option(
173-
"--description",
174-
help="Optional description of the reference list.",
175-
)
176-
def create_reference_list_cmd(credentials_file, project_id, project_instance,
177-
region, reference_list_id, entries, syntax_type,
178-
scope_names, description):
179-
"""Create a new reference list."""
180-
auth_session = chronicle_auth.initialize_http_session(
181-
credentials_file,
182-
SCOPES,
183-
)
184137

185-
entries_list = json.loads(entries)
186-
scope_names_list = json.loads(scope_names) if scope_names else None
187138

188-
result = create_reference_list.create_reference_list(
189-
auth_session,
190-
project_id,
191-
project_instance,
192-
region,
193-
reference_list_id,
194-
entries_list,
195-
syntax_type,
196-
scope_names_list,
197-
description,
198-
)
199-
print(json.dumps(result, indent=2))
200139

201140

202-
@reference.command("get")
203-
@add_common_options
204-
@click.option(
205-
"--reference-list-id",
206-
required=True,
207-
help="ID of the reference list to retrieve.",
208-
)
209-
def get_reference_list_cmd(credentials_file, project_id, project_instance,
210-
region, reference_list_id):
211-
"""Get a reference list by ID."""
212-
auth_session = chronicle_auth.initialize_http_session(
213-
credentials_file,
214-
SCOPES,
215-
)
216-
result = get_reference_list.get_reference_list(
217-
auth_session,
218-
project_id,
219-
project_instance,
220-
region,
221-
reference_list_id,
222-
)
223-
print(json.dumps(result, indent=2))
224-
225-
226-
@reference.command("list")
227-
@add_common_options
228-
@click.option(
229-
"--page-size",
230-
type=int,
231-
help="Optional maximum number of reference lists to return.",
232-
)
233-
@click.option(
234-
"--page-token",
235-
help="Optional page token from a previous response for pagination.",
236-
)
237-
def list_reference_lists_cmd(credentials_file, project_id, project_instance,
238-
region, page_size, page_token):
239-
"""List reference lists."""
240-
auth_session = chronicle_auth.initialize_http_session(
241-
credentials_file,
242-
SCOPES,
243-
)
244-
result = list_reference_lists.list_reference_lists(
245-
auth_session,
246-
project_id,
247-
project_instance,
248-
region,
249-
page_size,
250-
page_token,
251-
)
252-
print(json.dumps(result, indent=2))

0 commit comments

Comments
 (0)