From c2fcc7dd2f78feb51ece5a183a149f781740cb9b Mon Sep 17 00:00:00 2001 From: olichter Date: Tue, 7 Jan 2020 16:59:20 +0200 Subject: [PATCH 1/4] revert Rony's warning. --- CHANGELOG.md | 2 +- demisto_sdk/common/constants.py | 3 +- .../common/hook_validations/incident_field.py | 9 +-- .../common/hook_validations/structure.py | 1 + demisto_sdk/common/schemas/incidenttype.yml | 56 +++++++++++++++++++ demisto_sdk/common/schemas/playbook.yml | 6 ++ demisto_sdk/validation/file_validator.py | 5 +- tests/incident_field_test.py | 10 ++-- 8 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 demisto_sdk/common/schemas/incidenttype.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 469b5469213..571189afd73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### 0.3.3 * Added backwards compatibility break error message. - +* Added schema for incident types. ### 0.3.2 * Fixed the handling of classifier files in **validate**. diff --git a/demisto_sdk/common/constants.py b/demisto_sdk/common/constants.py index 90ace721199..60bb1700d45 100644 --- a/demisto_sdk/common/constants.py +++ b/demisto_sdk/common/constants.py @@ -705,7 +705,8 @@ class PB_Status: 'canvas-context-connections': JSON_ALL_CONNECTIONS_REGEXES, 'classifier': JSON_ALL_CLASSIFIER_REGEXES, 'layout': JSON_ALL_LAYOUT_REGEXES, - 'incidentfield': JSON_ALL_INCIDENT_FIELD_REGEXES + JSON_ALL_INDICATOR_FIELDS_REGEXES + 'incidentfield': JSON_ALL_INCIDENT_FIELD_REGEXES + JSON_ALL_INDICATOR_FIELDS_REGEXES, + 'incidenttype': [INCIDENT_TYPE_REGEX] } FILE_TYPES_PATHS_TO_VALIDATE = { diff --git a/demisto_sdk/common/hook_validations/incident_field.py b/demisto_sdk/common/hook_validations/incident_field.py index ce38828bb50..39f3c2b34a9 100644 --- a/demisto_sdk/common/hook_validations/incident_field.py +++ b/demisto_sdk/common/hook_validations/incident_field.py @@ -38,7 +38,8 @@ def is_valid_name(self): """Validate that the name and cliName does not contain any potential incident synonyms.""" name = self.current_file.get('name', '') cli_name = self.current_file.get('cliName', '') - bad_words = {'incident', 'case', 'alert', 'event', 'play', 'ticket', 'issue'} + bad_words = {'incident', 'case', 'alert', 'event', 'playbook', 'ticket', 'issue', + 'incidents', 'cases', 'alert', 'events', 'playbooks', 'tickets', 'issues'} whitelisted_field_names = { 'XDR Alert Count', 'XDR High Severity Alert Count', @@ -47,9 +48,9 @@ def is_valid_name(self): 'XDR Incident ID', 'Detection Ticketed' } - for word in bad_words: - if name not in whitelisted_field_names: - if word in name.lower() or word in cli_name.lower(): + if name not in whitelisted_field_names: + for word in cli_name.split() + name.split(): + if word.lower() in bad_words: print_error("The word {} cannot be used as a name/cliName, " "please update the file {}.".format(word, self.file_path)) return False diff --git a/demisto_sdk/common/hook_validations/structure.py b/demisto_sdk/common/hook_validations/structure.py index 40412d404d8..180f954ac01 100644 --- a/demisto_sdk/common/hook_validations/structure.py +++ b/demisto_sdk/common/hook_validations/structure.py @@ -71,6 +71,7 @@ def scheme_of_file_by_path(self): Returns: (str): Type of file by scheme name """ + for scheme_name, regex_list in SCHEMA_TO_REGEX.items(): if get_matching_regex(self.file_path, regex_list): return scheme_name diff --git a/demisto_sdk/common/schemas/incidenttype.yml b/demisto_sdk/common/schemas/incidenttype.yml new file mode 100644 index 00000000000..de5fb4c492a --- /dev/null +++ b/demisto_sdk/common/schemas/incidenttype.yml @@ -0,0 +1,56 @@ +type: map +mapping: + id: + type: str + required: true + version: + type: int + required: true + vcShouldIgnore: + type: bool + sortValues: + type: any + locked: + type: bool + name: + type: str + required: true + prevName: + type: str + color: + type: str + required: true + sla: + type: int + slaReminder: + type: int + playbookId: + type: str + hours: + type: int + days: + type: int + weeks: + type: int + hoursR: + type: int + daysR: + type: int + weeksR: + type: int + system: + type: bool + readonly: + type: bool + default: + type: bool + autorun: + type: bool + preProcessingScript: + type: str + closureScript: + type: str + disabled: + type: bool + reputationCalc: + type: float diff --git a/demisto_sdk/common/schemas/playbook.yml b/demisto_sdk/common/schemas/playbook.yml index b49a741d09e..4824f15fcba 100644 --- a/demisto_sdk/common/schemas/playbook.yml +++ b/demisto_sdk/common/schemas/playbook.yml @@ -162,6 +162,12 @@ mapping: type: int separatecontext: type: bool + fieldMapping: + type: seq + sequence: + - type: map + allowempty: True + system: type: bool fromversion: diff --git a/demisto_sdk/validation/file_validator.py b/demisto_sdk/validation/file_validator.py index dab58bdd592..64cc2bfbfd6 100644 --- a/demisto_sdk/validation/file_validator.py +++ b/demisto_sdk/validation/file_validator.py @@ -21,7 +21,7 @@ IMAGE_REGEX, TEST_PLAYBOOK_REGEX, DIR_LIST_FOR_REGULAR_ENTETIES, \ PACKAGE_SUPPORTING_DIRECTORIES, YML_BETA_INTEGRATIONS_REGEXES, PACKAGE_SCRIPTS_REGEXES, YML_INTEGRATION_REGEXES, \ PACKS_DIR, PACKS_DIRECTORIES, Errors, PLAYBOOKS_REGEXES_LIST, JSON_INDICATOR_AND_INCIDENT_FIELDS, PLAYBOOK_REGEX, \ - JSON_ALL_LAYOUT_REGEXES, REPUTATION_REGEX, CHECKED_TYPES_REGEXES + JSON_ALL_LAYOUT_REGEXES, REPUTATION_REGEX, CHECKED_TYPES_REGEXES, INCIDENT_TYPE_REGEX from demisto_sdk.common.hook_validations.conf_json import ConfJsonValidator from demisto_sdk.common.hook_validations.description import DescriptionValidator from demisto_sdk.common.hook_validations.id import IDSetValidator @@ -448,6 +448,9 @@ def validate_added_files(self, added_files): # noqa: C901 F'Skipping validation for file {file_path} since no validation is currently defined.', LOG_COLORS.YELLOW) + elif checked_type(file_path, CHECKED_TYPES_REGEXES): + pass + else: print_error("The file type of {} is not supported in validate command".format(file_path)) print_error("validate command supports: Integrations, Scripts, Playbooks, " diff --git a/tests/incident_field_test.py b/tests/incident_field_test.py index 1ffbf7faf3b..ef61f765694 100644 --- a/tests/incident_field_test.py +++ b/tests/incident_field_test.py @@ -31,7 +31,7 @@ class TestIncidentFieldsValidator: 'content': True, } - BAD_CLI_4 = { + GOOD_CLI_4 = { 'cliName': 'Alerting feature', 'name': 'sanity name', 'content': True, @@ -61,7 +61,7 @@ class TestIncidentFieldsValidator: 'content': True, } - BAD_NAME_4 = { + GOOD_NAME_4 = { 'cliName': 'sanity name', 'name': 'Alerting feature', 'content': True, @@ -78,12 +78,12 @@ class TestIncidentFieldsValidator: (BAD_CLI_1, False), (BAD_CLI_2, False), (BAD_CLI_3, False), - (BAD_CLI_4, False), + (GOOD_CLI_4, True), (BAD_CLI_5, False), (BAD_NAME_1, False), (BAD_NAME_2, False), (BAD_NAME_3, False), - (BAD_NAME_4, False), + (GOOD_NAME_4, True), (BAD_NAME_5, False) ] @@ -98,7 +98,7 @@ def test_is_valid_name_sanity(self, current_file, answer): validator = IncidentFieldValidator(structure) validator.current_file = current_file assert validator.is_valid_name() is answer - assert validator.is_valid_file() is answer + assert validator.is_valid_file() == answer CONTENT_1 = { 'content': True From 2db0c367773ee91a0a82698c0e367b37f0f0c863 Mon Sep 17 00:00:00 2001 From: Rony Kozakish <37589583+ronykoz@users.noreply.github.com> Date: Tue, 7 Jan 2020 17:12:15 +0200 Subject: [PATCH 2/4] Update demisto_sdk/common/hook_validations/incident_field.py --- demisto_sdk/common/hook_validations/incident_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/common/hook_validations/incident_field.py b/demisto_sdk/common/hook_validations/incident_field.py index 39f3c2b34a9..aa5b3588727 100644 --- a/demisto_sdk/common/hook_validations/incident_field.py +++ b/demisto_sdk/common/hook_validations/incident_field.py @@ -39,7 +39,7 @@ def is_valid_name(self): name = self.current_file.get('name', '') cli_name = self.current_file.get('cliName', '') bad_words = {'incident', 'case', 'alert', 'event', 'playbook', 'ticket', 'issue', - 'incidents', 'cases', 'alert', 'events', 'playbooks', 'tickets', 'issues'} + 'incidents', 'cases', 'alerts', 'events', 'playbooks', 'tickets', 'issues'} whitelisted_field_names = { 'XDR Alert Count', 'XDR High Severity Alert Count', From d8574f945288d67e164bf155b31f6b25075f718e Mon Sep 17 00:00:00 2001 From: Rony Kozakish <37589583+ronykoz@users.noreply.github.com> Date: Tue, 7 Jan 2020 17:12:22 +0200 Subject: [PATCH 3/4] Update demisto_sdk/validation/file_validator.py --- demisto_sdk/validation/file_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/validation/file_validator.py b/demisto_sdk/validation/file_validator.py index 64cc2bfbfd6..716a690ef55 100644 --- a/demisto_sdk/validation/file_validator.py +++ b/demisto_sdk/validation/file_validator.py @@ -21,7 +21,7 @@ IMAGE_REGEX, TEST_PLAYBOOK_REGEX, DIR_LIST_FOR_REGULAR_ENTETIES, \ PACKAGE_SUPPORTING_DIRECTORIES, YML_BETA_INTEGRATIONS_REGEXES, PACKAGE_SCRIPTS_REGEXES, YML_INTEGRATION_REGEXES, \ PACKS_DIR, PACKS_DIRECTORIES, Errors, PLAYBOOKS_REGEXES_LIST, JSON_INDICATOR_AND_INCIDENT_FIELDS, PLAYBOOK_REGEX, \ - JSON_ALL_LAYOUT_REGEXES, REPUTATION_REGEX, CHECKED_TYPES_REGEXES, INCIDENT_TYPE_REGEX + JSON_ALL_LAYOUT_REGEXES, REPUTATION_REGEX, CHECKED_TYPES_REGEXES from demisto_sdk.common.hook_validations.conf_json import ConfJsonValidator from demisto_sdk.common.hook_validations.description import DescriptionValidator from demisto_sdk.common.hook_validations.id import IDSetValidator From d5d13be2644f83d5e6fa1ac5936d1b70a32976a4 Mon Sep 17 00:00:00 2001 From: olichter Date: Wed, 8 Jan 2020 10:27:30 +0200 Subject: [PATCH 4/4] adding to and from version --- demisto_sdk/common/schemas/incidenttype.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/demisto_sdk/common/schemas/incidenttype.yml b/demisto_sdk/common/schemas/incidenttype.yml index de5fb4c492a..1173e103ced 100644 --- a/demisto_sdk/common/schemas/incidenttype.yml +++ b/demisto_sdk/common/schemas/incidenttype.yml @@ -54,3 +54,7 @@ mapping: type: bool reputationCalc: type: float + fromVersion: + type: str + toVersion: + type: str