-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate Silent Playbook name/id (#4662)
* added validate * added unittest * added changelog * fixed comments * pre commit
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 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 validation checks whether the silent playbook name id and the isSilent key are set correctly. | ||
type: feature | ||
pr_number: 4662 |
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
46 changes: 46 additions & 0 deletions
46
demisto_sdk/commands/validate/validators/PB_validators/PB130_is_silent_playbook.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,46 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List, Union | ||
|
||
from demisto_sdk.commands.content_graph.objects.playbook import Playbook | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Union[Playbook] | ||
|
||
|
||
class IsSilentPlaybookValidator(BaseValidator[ContentTypes]): | ||
error_code = "PB130" | ||
description = "Validate that the name and ID of a silent-Playbook contain the silent prefix and include the field isSilent: true" | ||
rationale = "In silent-Playbook the name and ID prefix should be silent and also include the field isSilent: true" | ||
error_message = "Silent-Playbook should have silent as a prefix in the name and ID, as well as the field isSilent: true, one of them is missing." | ||
related_field = "" | ||
is_auto_fixable = False | ||
|
||
def obtain_invalid_content_items( | ||
self, content_items: Iterable[ContentTypes] | ||
) -> List[ValidationResult]: | ||
return [ | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message, | ||
content_object=content_item, | ||
) | ||
for content_item in content_items | ||
if ( | ||
content_item.data.get("isSilent") | ||
or any( | ||
content_item.data.get(key, "").startswith("silent") | ||
for key in ["name", "id"] | ||
) | ||
) | ||
and not ( | ||
content_item.data.get("isSilent") | ||
and all( | ||
content_item.data.get(key, "").startswith("silent") | ||
for key in ["name", "id"] | ||
) | ||
) | ||
] |