From 88e1adea1af76282194c64ab2d3fe0efc5df8394 Mon Sep 17 00:00:00 2001 From: Jochman Date: Thu, 6 Feb 2020 19:08:12 +0200 Subject: [PATCH] deprecate SearchIncidents.yml --- Scripts/SearchIncidents_5.0/CHANGELOG.md | 2 - .../SearchIncidents_5.0/SearchIncidents.py | 62 ------------- .../SearchIncidents_5.0/SearchIncidents.yml | 89 ------------------- .../SearchIncidents_test.py | 44 --------- 4 files changed, 197 deletions(-) delete mode 100644 Scripts/SearchIncidents_5.0/CHANGELOG.md delete mode 100644 Scripts/SearchIncidents_5.0/SearchIncidents.py delete mode 100644 Scripts/SearchIncidents_5.0/SearchIncidents.yml delete mode 100644 Scripts/SearchIncidents_5.0/SearchIncidents_test.py diff --git a/Scripts/SearchIncidents_5.0/CHANGELOG.md b/Scripts/SearchIncidents_5.0/CHANGELOG.md deleted file mode 100644 index 9ee1d606640b..000000000000 --- a/Scripts/SearchIncidents_5.0/CHANGELOG.md +++ /dev/null @@ -1,2 +0,0 @@ -## [Unreleased] -Fixed an issue where special characters returned an error. diff --git a/Scripts/SearchIncidents_5.0/SearchIncidents.py b/Scripts/SearchIncidents_5.0/SearchIncidents.py deleted file mode 100644 index f7738251eb9e..000000000000 --- a/Scripts/SearchIncidents_5.0/SearchIncidents.py +++ /dev/null @@ -1,62 +0,0 @@ -from typing import Dict, List -import demistomock as demisto -from CommonServerPython import * -from CommonServerUserPython import * - - -special = ['n', 't', '\\', '"', '\'', '7', 'r'] - - -def check_if_found_incident(res: List): - if res and isinstance(res, list) and isinstance(res[0].get('Contents'), dict): - if 'data' not in res[0]['Contents']: - raise DemistoException(res[0].get('Contents')) - elif res[0]['Contents']['data'] is None: - raise DemistoException("Incidents not found.") - - else: - raise DemistoException(f'failed to get incidents from demisto.\nGot: {res}') - - -def is_valid_args(args: Dict): - array_args: List[str] = ['id', 'name', 'status', 'notstatus', 'reason', 'level', 'owner', 'type', 'query'] - error_msg: List[str] = [] - for _key, value in args.items(): - if _key in array_args: - value = ','.join(value) - i = 0 - while i < len(value): - if value[i] == '\\': - if value[i + 1] not in special: - error_msg.append(f'Error while parsing the argument: "{_key}" ' - f'\nSucceeded parsing untill:\n- "{value[0:i]}"') - else: - i += 1 - i += 1 - if len(error_msg) != 0: - raise DemistoException('\n'.join(error_msg)) - - return True - - -def search_incidents(args: Dict): - if is_valid_args(args): - res: List = demisto.executeCommand('getIncidents', args) - check_if_found_incident(res) - data: Dict = res[0]['Contents']['data'] - context_entry: Dict = {'foundIncidents': data} - headers: List[str] = ['id', 'name', 'severity', 'status', 'owner', 'created', 'closed'] - md: str = tableToMarkdown(name="Incidents found", t=data, headers=headers) - return_outputs(md, context_entry, res) - - -def main(): - args: Dict = demisto.args() - try: - search_incidents(args) - except DemistoException as error: - return_error(str(error), error) - - -if __name__ in ('__main__', '__builtin__', 'builtins'): - main() diff --git a/Scripts/SearchIncidents_5.0/SearchIncidents.yml b/Scripts/SearchIncidents_5.0/SearchIncidents.yml deleted file mode 100644 index 4f904ee3f296..000000000000 --- a/Scripts/SearchIncidents_5.0/SearchIncidents.yml +++ /dev/null @@ -1,89 +0,0 @@ -commonfields: - id: SearchIncidents - version: -1 -name: SearchIncidents -fromversion: 5.0.0 -script: '-' -system: false -timeout: '0' -type: python -subtype: python3 -dockerimage: demisto/python3:3.8.1.5734 -tags: -- Utility -comment: Searches Demisto incidents -enabled: true -args: -- name: id - default: true - description: A comma-separated list of incident IDs by which to filter the results. - isArray: true -- name: name - description: A comma-separated list of incident names by which to filter the results. - isArray: true -- name: status - description: ' A comma-separated list of incident statuses by which to filter the results. For example: assigned. ' - isArray: true -- name: notstatus - description: ' A comma-separated list of incident statuses to exclude from the results. For example: assigned. ' - isArray: true -- name: reason - description: A comma-separated list of incident close reasons by which to filter the results. - isArray: true -- name: fromdate - description: Filter by from date (e.g. 2006-01-02T15:04:05+07:00 or 2006-01-02T15:04:05Z) -- name: todate - description: Filter by to date (e.g. 2006-01-02T15:04:05+07:00 or 2006-01-02T15:04:05Z) -- name: fromclosedate - description: Filter by from close date (e.g. 2006-01-02T15:04:05+07:00 or 2006-01-02T15:04:05Z) -- name: toclosedate - description: Filter by to close date (e.g. 2006-01-02T15:04:05+07:00 or 2006-01-02T15:04:05Z) -- name: fromduedate - description: Filter by from due date (e.g. 2006-01-02T15:04:05+07:00 or 2006-01-02T15:04:05Z) -- name: toduedate - description: Filter by to due date (e.g. 2006-01-02T15:04:05+07:00 or 2006-01-02T15:04:05Z) -- name: level - description: Filter by Severity - isArray: true -- name: owner - description: Filter by incident owners - isArray: true -- name: details - description: Filter by incident details -- name: type - description: Filter by incident type - isArray: true -- name: query - description: Use free form query (use Lucene syntax) as filter. All other filters - will be ignored when this filter is used. - isArray: true -- name: page - description: Filter by the page number -- name: size - description: Filter by the page size (per fetch) -- name: sort - description: Sort in format of field.asc,field.desc,... -outputs: -- contextPath: foundIncidents.id - description: A list of incident IDs returned from the query. -- contextPath: foundIncidents.name - description: A list of incident names returned from the query. -- contextPath: foundIncidents.severity - description: A list of incident severities returned from the query. -- contextPath: foundIncidents.status - description: A list of incident statuses returned from the query. -- contextPath: foundIncidents.owner - description: A list of incident owners returned from the query. -- contextPath: foundIncidents.created - description: A list of the incident create date returned from the query. -- contextPath: foundIncidents.closed - description: A list of incident close dates returned from the query. -- contextPath: foundIncidents.labels - description: An array of labels per incident returned from the query. -- contextPath: foundIncidents.details - description: Details of the incidents returned from the query. -- contextPath: foundIncidents.dueDate - description: A list of incident due dates returned from the query. -- contextPath: foundIncidents.phase - description: A list of incident phases returned from the query. -deprecated: true diff --git a/Scripts/SearchIncidents_5.0/SearchIncidents_test.py b/Scripts/SearchIncidents_5.0/SearchIncidents_test.py deleted file mode 100644 index bc501a83fc92..000000000000 --- a/Scripts/SearchIncidents_5.0/SearchIncidents_test.py +++ /dev/null @@ -1,44 +0,0 @@ -from SearchIncidents import * -import pytest - -data_test_check_if_found_incident = [ - ([], 'failed to get incidents from demisto.\nGot: []'), - (None, 'failed to get incidents from demisto.\nGot: None'), - ('', 'failed to get incidents from demisto.\nGot: '), - ([{'Contents': {'data': None}}], 'Incidents not found.'), - ([{'Contents': {'data': 'test'}}], None), - ([{'Contents': {'test': 'test'}}], {'test': 'test'}), -] - - -@pytest.mark.parametrize('_input, expected_output', data_test_check_if_found_incident) -def test_check_if_found_incident(_input, expected_output): - output = str(None) - try: - check_if_found_incident(_input) - except DemistoException as error: - output = str(error) - assert output == str(expected_output), f'check_if_found_incident({_input}) returns: {output}. expected: {expected_output}' - - -data_test_is_valid_args = [ - ('\\\n', False), - ('\\s', False), - ('\\n', True), - ('\\t', True), - ('\\\\', True), - ('\\"', True), - ('\\r', True), - ('\\7', True), - ('\\\'', True), -] - - -@pytest.mark.parametrize('_input, expected_output', data_test_is_valid_args) -def test_is_valid_args(_input, expected_output): - try: - output = is_valid_args({'test': _input}) - except DemistoException: - output = False - - assert output == expected_output, f'is_valid_args({_input}) returns: {output}. expected: {expected_output}'