Skip to content

Commit 2d1577f

Browse files
content-botzdrousecah-zachary-rouseitssapirjulieschwartz18
authored
Update Cortex Xpanse asm-list-external-websites command to include pa… (#40140) (#40707)
* Update Cortex Xpanse asm-list-external-websites command to include pagination support. * adjust Context Outputs for Command Results to include a new object for ExternalWebsiteReply that contains contextual information about the request for external websites. * added context path output for the NextPageToken underneath ExternalWebsitReply * added release notes * introduced a new CommandResults object for asm-list-external-websites since we are unable to change existing functionality of outputs_prefix of the original CommandResults. The new CommandResults object provides an additional about with context information about the request including next page token for pagination, the total results and the result count from the request. CommandResults is also using so that context is overwritten with the most recent command execution per recommended usage of . * change arg gets to use double quotes * changes requested to test file and docstring for type checking * update release note md version to 1_2_11 * modify version in pack_metadata.json * Apply suggestions from doc review * Bump version --------- Co-authored-by: zdrouse <[email protected]> Co-authored-by: cah-zachary-rouse <[email protected]> Co-authored-by: Sapir Malka <[email protected]> Co-authored-by: julieschwartz18 <[email protected]> Co-authored-by: Sapir Malka <[email protected]>
1 parent 112163d commit 2d1577f

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

Packs/CortexXpanse/Integrations/CortexXpanse/CortexXpanse.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,27 +1118,35 @@ def get_incident_command(client: Client, args: dict[str, Any]) -> CommandResults
11181118
return command_results
11191119

11201120

1121-
def list_external_websites_command(client: Client, args: Dict[str, Any]) -> CommandResults:
1121+
def list_external_websites_command(client: Client, args: Dict[str, Any]) -> list[CommandResults]:
11221122
"""
1123-
list_external_websites command: Get external websites .
1123+
asm-list-external-websites command: Get external websites.
11241124
11251125
Args:
11261126
client (Client): CortexXpanse client to use.
11271127
args (dict): all command arguments, usually passed from ``demisto.args()``.
11281128
``args['filter']`` Used for filter websites based on authentication type
11291129
``args['limit']`` Used for limit num of results
1130+
``args['use_page_token']`` Boolean value used to specify pagination
1131+
``args['next_page_token']`` String value of a page token to get the next page of results
11301132
11311133
Returns:
1132-
CommandResults: A ``CommandResults`` object that is then passed to ``return_results``
1134+
CommandResults: A list of ``CommandResults`` objects that is then passed to ``return_results``
11331135
"""
11341136
limit = int(args.get("limit", DEFAULT_SEARCH_LIMIT))
11351137
searchFilter = args.get("authentication")
1138+
use_page_token = args.get("use_page_token")
1139+
next_page_token = args.get("next_page_token")
11361140
if limit > 500:
11371141
raise ValueError("Limit cannot be more than 500, please try again")
11381142

11391143
filters = {"filters": [], "search_to": limit}
11401144
if searchFilter:
11411145
filters["filters"] = [{"field": "authentication", "operator": "contains", "value": searchFilter}]
1146+
if use_page_token:
1147+
filters["use_page_token"] = use_page_token
1148+
if next_page_token:
1149+
filters["next_page_token"] = next_page_token
11421150

11431151
response = client.get_external_websites(filters)
11441152

@@ -1152,12 +1160,30 @@ def list_external_websites_command(client: Client, args: Dict[str, Any]) -> Comm
11521160
if hosts
11531161
else "No Results"
11541162
)
1155-
command_results = CommandResults(
1163+
1164+
command_results = []
1165+
website_results = CommandResults(
11561166
outputs_prefix="ASM.ExternalWebsite", outputs_key_field="", raw_response=response, readable_output=human_readable
11571167
)
11581168

11591169
if outputs := response.get("reply", {}).get("websites", None):
1160-
command_results.outputs = outputs
1170+
reply_results = CommandResults(
1171+
outputs_prefix="ASM.ExternalWebsiteReply", outputs_key_field="", readable_output=None, replace_existing=True
1172+
)
1173+
reply_outputs = {}
1174+
if response.get("reply", {}).get("next_page_token", None):
1175+
reply_outputs["NextPageToken"] = response.get("reply", {}).get("next_page_token")
1176+
if response.get("reply", {}).get("total_count", None):
1177+
reply_outputs["TotalCount"] = response.get("reply", {}).get("total_count")
1178+
if response.get("reply", {}).get("result_count", None):
1179+
reply_outputs["ResultCount"] = response.get("reply", {}).get("result_count")
1180+
if reply_outputs:
1181+
reply_results.outputs = reply_outputs
1182+
reply_results.raw_response = reply_outputs
1183+
1184+
website_results.outputs = outputs
1185+
command_results.append(website_results)
1186+
command_results.append(reply_results)
11611187

11621188
return command_results
11631189

Packs/CortexXpanse/Integrations/CortexXpanse/CortexXpanse.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,21 @@ script:
965965
- name: limit
966966
description: Maximum number of assets to return. The maximum value is 100.
967967
defaultValue: "100"
968+
- name: use_page_token
969+
auto: PREDEFINED
970+
predefined:
971+
- "true"
972+
- "false"
973+
description: Whether to paginate the response data. Set to true to paginate and receive a token indicating the location of the next page.
974+
- name: next_page_token
975+
description: A string representing the next page location when pagination is used.
968976
outputs:
969977
- contextPath: ASM.ExternalWebsite
970978
description: A list of the websites results assets.
979+
- contextPath: ASM.ExternalWebsiteReply
980+
description: Contextual information about the request including total count, result count, and next page token.
981+
- contextPath: ASM.ExternalWebsiteReply.NextPageToken
982+
description: The next page token for the request (for pagination).
971983
description: Get external websites assets.
972984
- name: asm-reset-last-run
973985
arguments: []

Packs/CortexXpanse/Integrations/CortexXpanse/CortexXpanse_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,8 @@ def test_list_external_websites_command(requests_mock):
600600

601601
response = list_external_websites_command(client, args)
602602

603-
assert response.outputs == EXTERNAL_WEBSITES_RESULTS.get("ExternalWebsite", {}).get("websites")
604-
assert response.outputs_prefix == "ASM.ExternalWebsite"
603+
assert response[0].outputs == EXTERNAL_WEBSITES_RESULTS.get("ExternalWebsite", {}).get("websites")
604+
assert response[0].outputs_prefix == "ASM.ExternalWebsite"
605605

606606

607607
@pytest.mark.parametrize("command_name, method_name", [("asm-list-alerts", "list_alerts_command")])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#### Integrations
3+
4+
##### Cortex Xpanse
5+
6+
- Added support for pagination to the ***asm-list-external-websites*** command.
7+
- Added the *use_page_token* argument for the **asm-list-external-websites** command.
8+
- Added the *next_page_token* argument for the **asm-list-external-websites** command.

Packs/CortexXpanse/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Cortex Xpanse",
33
"description": "Content for working with Attack Surface Management (ASM).",
44
"support": "xsoar",
5-
"currentVersion": "1.2.11",
5+
"currentVersion": "1.2.12",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

0 commit comments

Comments
 (0)