-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added PB126 * added changelog * fixed cr comments * More fixes * More fixes
- Loading branch information
1 parent
2fa7ee2
commit 62fa385
Showing
4 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
changes: | ||
- description: Added PB126 to the new validation format. Ensure that conditional tasks have more than path which is not the default one | ||
type: internal | ||
pr_number: 4349 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...sto_sdk/commands/validate/validators/PB_validators/PB126_is_default_not_only_condition.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List | ||
|
||
from demisto_sdk.commands.common.constants import PlaybookTaskType | ||
from demisto_sdk.commands.content_graph.objects.playbook import Playbook | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Playbook | ||
|
||
|
||
class IsDefaultNotOnlyConditionValidator(BaseValidator[ContentTypes]): | ||
error_code = "PB126" | ||
description = ( | ||
"Ensure that conditional tasks have an execution path besides for the default." | ||
) | ||
rationale = ( | ||
"We want to ensure that conditional tasks have more than path which is not the default one o/w it " | ||
"make no sense to have such." | ||
) | ||
error_message = ( | ||
"The following playbook conditional tasks only have a default option: {}. Please remove these tasks or add " | ||
"another non-default option to each task." | ||
) | ||
related_field = "conditions" | ||
is_auto_fixable = False | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
validation_results = [] | ||
for content_item in content_items: | ||
failed_tasks = [] | ||
for task in content_item.tasks.values(): | ||
if ( | ||
task.type == PlaybookTaskType.CONDITION | ||
and task.message | ||
and task.message.get("replyOptions") | ||
): | ||
reply_options = set( | ||
map(str.upper, task.message.get("replyOptions", [])) | ||
) | ||
if len(reply_options) == 1 and "#default#".upper() in reply_options: | ||
failed_tasks.append(f"Task: {task.id}") | ||
if failed_tasks: | ||
validation_results.append( | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message.format(failed_tasks), | ||
content_object=content_item, | ||
) | ||
) | ||
return validation_results |