Skip to content

Commit

Permalink
Merge pull request #135 from demisto/incident_types
Browse files Browse the repository at this point in the history
add incident type schema
  • Loading branch information
ronykoz authored Jan 8, 2020
2 parents dbda508 + 292fc01 commit a4894ac
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### 0.3.3
* Added backwards compatibility break error message.
* Added schema for incident types.
* Added **additionalinfo** field to as an available field for integration configuration.
* Added pack parameter for **init**.
* Fixed an issue where error would appear if name parameter is not set in **init**.
Expand Down
3 changes: 2 additions & 1 deletion demisto_sdk/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
9 changes: 5 additions & 4 deletions demisto_sdk/common/hook_validations/incident_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', 'alerts', 'events', 'playbooks', 'tickets', 'issues'}
whitelisted_field_names = {
'XDR Alert Count',
'XDR High Severity Alert Count',
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/common/hook_validations/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions demisto_sdk/common/schemas/incidenttype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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
fromVersion:
type: str
toVersion:
type: str
6 changes: 6 additions & 0 deletions demisto_sdk/common/schemas/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ mapping:
type: int
separatecontext:
type: bool
fieldMapping:
type: seq
sequence:
- type: map
allowempty: True

system:
type: bool
fromversion:
Expand Down
3 changes: 3 additions & 0 deletions demisto_sdk/validation/file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
10 changes: 5 additions & 5 deletions tests/incident_field_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestIncidentFieldsValidator:
'content': True,
}

BAD_CLI_4 = {
GOOD_CLI_4 = {
'cliName': 'Alerting feature',
'name': 'sanity name',
'content': True,
Expand Down Expand Up @@ -61,7 +61,7 @@ class TestIncidentFieldsValidator:
'content': True,
}

BAD_NAME_4 = {
GOOD_NAME_4 = {
'cliName': 'sanity name',
'name': 'Alerting feature',
'content': True,
Expand All @@ -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)
]

Expand All @@ -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
Expand Down

0 comments on commit a4894ac

Please sign in to comment.