Skip to content

Commit ee51300

Browse files
authored
Add ErrorReasons to 'core-action-status-get' Command (#37483)
* add errorReasons * add error_description to HR * add outputs * add RN * add polling output * change to No Tests * change output path * UT * readme * precommit * doc review
1 parent 7c02e87 commit ee51300

File tree

13 files changed

+930
-73
lines changed

13 files changed

+930
-73
lines changed

Packs/ApiModules/Scripts/CoreIRApiModule/CoreIRApiModule.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ def get_script_execution_result_files(self, action_id: str, endpoint_id: str) ->
13631363
resp_type='response',
13641364
)
13651365

1366-
def action_status_get(self, action_id) -> Dict[str, Any]:
1366+
def action_status_get(self, action_id) -> Dict[str, Dict[str, Any]]:
13671367
request_data: Dict[str, Any] = {
13681368
'group_action_id': action_id,
13691369
}
@@ -1376,7 +1376,7 @@ def action_status_get(self, action_id) -> Dict[str, Any]:
13761376
)
13771377
demisto.debug(f"action_status_get = {reply}")
13781378

1379-
return reply.get('reply').get('data')
1379+
return reply.get('reply')
13801380

13811381
@logger
13821382
def get_file(self, file_link):
@@ -1757,6 +1757,7 @@ def run_polling_command(client: CoreClient,
17571757
outputs_result_func[0].get(polling_field)
17581758
cond = result not in polling_value if stop_polling else result in polling_value
17591759
if values_raise_error and result in values_raise_error:
1760+
return_results(command_results)
17601761
raise DemistoException(f"The command {cmd} failed. Received status {result}")
17611762
if cond:
17621763
# schedule next poll
@@ -1959,24 +1960,38 @@ def action_status_get_command(client: CoreClient, args) -> CommandResults:
19591960
demisto.debug(f'action_status_get_command {action_id_list=}')
19601961
result = []
19611962
for action_id in action_id_list:
1962-
data = client.action_status_get(action_id)
1963+
reply = client.action_status_get(action_id)
1964+
data = reply.get('data') or {}
1965+
error_reasons = reply.get('errorReasons', {})
19631966

19641967
for endpoint_id, status in data.items():
1965-
result.append({
1968+
action_result = {
19661969
'action_id': action_id,
19671970
'endpoint_id': endpoint_id,
19681971
'status': status,
1969-
})
1972+
}
1973+
if error_reason := error_reasons.get(endpoint_id):
1974+
action_result['ErrorReasons'] = error_reason
1975+
action_result['error_description'] = (error_reason.get('errorDescription')
1976+
or get_missing_files_description(error_reason.get('missing_files'))
1977+
or 'An error occurred while processing the request.')
1978+
result.append(action_result)
19701979

19711980
return CommandResults(
1972-
readable_output=tableToMarkdown(name='Get Action Status', t=result, removeNull=True),
1981+
readable_output=tableToMarkdown(name='Get Action Status', t=result, removeNull=True,
1982+
headers=['action_id', 'endpoint_id', 'status', 'error_description']),
19731983
outputs_prefix=f'{args.get("integration_context_brand", "CoreApiModule")}.'
19741984
f'GetActionStatus(val.action_id == obj.action_id)',
19751985
outputs=result,
19761986
raw_response=result
19771987
)
19781988

19791989

1990+
def get_missing_files_description(missing_files):
1991+
if isinstance(missing_files, list) and len(missing_files) > 0 and isinstance(missing_files[0], dict):
1992+
return missing_files[0].get('description')
1993+
1994+
19801995
def isolate_endpoint_command(client: CoreClient, args) -> CommandResults:
19811996
endpoint_id = args.get('endpoint_id')
19821997
disconnected_should_return_error = not argToBoolean(args.get('suppress_disconnected_endpoint_error', False))

Packs/ApiModules/Scripts/CoreIRApiModule/CoreIRApiModule_test.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ def test_get_script_code_command(requests_mock):
13811381
assert raw_response == get_script_code_command_reply.get("reply")
13821382

13831383

1384-
def test_action_status_get_command(requests_mock):
1384+
def test_action_status_get_command(mocker):
13851385
"""
13861386
Given:
13871387
- An action_id
@@ -1396,18 +1396,21 @@ def test_action_status_get_command(requests_mock):
13961396
action_status_get_command_command_reply = load_test_data('./test_data/action_status_get.json')
13971397

13981398
data = action_status_get_command_command_reply.get('reply').get('data')
1399+
error_reasons = action_status_get_command_command_reply.get('reply').get('errorReasons') or {}
13991400
result = []
14001401
for item in data:
14011402
result.append({
14021403
'action_id': 1810,
14031404
'endpoint_id': item,
14041405
'status': data.get(item)
14051406
})
1406-
action_status_get_command_expected_result = result
1407+
if error_reason := error_reasons.get(item):
1408+
result[-1]['error_description'] = error_reason['errorDescription']
1409+
result[-1]['ErrorReasons'] = error_reason
14071410

1408-
requests_mock.post(f'{Core_URL}/public_api/v1/actions/get_action_status/',
1409-
json=action_status_get_command_command_reply)
1411+
action_status_get_command_expected_result = result
14101412

1413+
mocker.patch.object(CoreClient, '_http_request', return_value=action_status_get_command_command_reply)
14111414
client = CoreClient(
14121415
base_url=f'{Core_URL}/public_api/v1', headers={}
14131416
)
@@ -1416,7 +1419,8 @@ def test_action_status_get_command(requests_mock):
14161419
}
14171420

14181421
res = action_status_get_command(client, args)
1419-
assert res.readable_output == tableToMarkdown(name='Get Action Status', t=result, removeNull=True)
1422+
assert res.readable_output == tableToMarkdown(name='Get Action Status', t=result, removeNull=True,
1423+
headers=['action_id', 'endpoint_id', 'status', 'error_description'])
14201424
assert res.outputs == action_status_get_command_expected_result
14211425
assert res.raw_response == result
14221426

@@ -4511,7 +4515,6 @@ def test_run_polling_command_values_raise_error(mocker):
45114515
"""
45124516
Given -
45134517
- run_polling_command arguments.
4514-
-
45154518
45164519
When -
45174520
- Running the run_polling_command
@@ -4532,6 +4535,7 @@ def test_run_polling_command_values_raise_error(mocker):
45324535
mock_command_results.raw_response = {"status": "TIMEOUT"}
45334536
mock_command_results.return_value = mock_command_results
45344537
client.get_command_results.return_value = mock_command_results
4538+
mocker.patch('CoreIRApiModule.return_results')
45354539

45364540
with pytest.raises(DemistoException) as e:
45374541
run_polling_command(client=client,

Packs/ApiModules/Scripts/CoreIRApiModule/test_data/action_status_get.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22
"reply": {
33
"data": {
44
"aeec6a2cc92e46fab3b6f621722e9916": "COMPLETED_SUCCESSFULLY",
5-
"23a86310665d413a958926fce5b794b3": "FAILED"
5+
"23a86310665d413a958926fce5b794b3": "FAILED",
6+
"5a763600a3e44928a94ba84b6088380f": "FAILED"
7+
},
8+
"errorReasons": {
9+
"5a763600a3e44928a94ba84b6088380f": {
10+
"errorData": "{\"reportIds\":[\"0ca3c1ace7694fcd8b44b735e5ba6c04\"],\"errorText\":\"\"}",
11+
"terminated_by": "instance_id",
12+
"errorDescription": "Element not found.\r\n",
13+
"terminate_result": [
14+
{
15+
"path": null,
16+
"status": 1
17+
}
18+
]
619
}
7-
}
20+
}
21+
}
822
}

0 commit comments

Comments
 (0)