-
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.
Merge branch 'master' into sf-handle-untracked-files-in-contrib-pr
- Loading branch information
Showing
11 changed files
with
448 additions
and
10 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 a fix where the `auto_update_docker_image` field was not updated correctly in the the content-graph. | ||
type: fix | ||
pr_number: 4287 |
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: Moved PB109 to the new validate format. The validation checks that taskid field and id field under task field contains equal values. | ||
type: internal | ||
pr_number: 4358 |
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: Converted PB106 validation to new validation format. The validation checks if the playbook uses a specific instance. | ||
type: internal | ||
pr_number: 4360 |
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: Converted PB115 validation to new validation format. The validation checks if the 'quietmode' field of all tasks in playbook are not in default value. | ||
type: internal | ||
pr_number: 4366 |
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
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
63 changes: 63 additions & 0 deletions
63
...sto_sdk/commands/validate/validators/PB_validators/PB106_is_playbook_using_an_instance.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,63 @@ | ||
from __future__ import annotations | ||
|
||
from typing import ClassVar, Dict, Iterable, List | ||
|
||
from demisto_sdk.commands.content_graph.objects.base_playbook import TaskConfig | ||
from demisto_sdk.commands.content_graph.objects.playbook import Playbook | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
FixResult, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Playbook | ||
|
||
|
||
class IsPlayBookUsingAnInstanceValidator(BaseValidator[ContentTypes]): | ||
invalid_tasks: ClassVar[dict] = {} | ||
error_code = "PB106" | ||
description = "Validate whether the playbook does not use an instance. If the Playbook use an instance it is not valid." | ||
rationale = "If the playbook uses a specific instance it can leads to errors because not all the users have the same instance." | ||
error_message = "Playbook should not use specific instance for tasks: {0}." | ||
fix_message = "Removed The 'using' statement from the following tasks tasks: {0}." | ||
related_field = "using" | ||
is_auto_fixable = True | ||
|
||
def is_playbook_using_an_instance( | ||
self, content_item: ContentTypes | ||
) -> list[TaskConfig]: | ||
content_item_tasks: Dict[str, TaskConfig] = content_item.tasks | ||
invalid_tasks: list[TaskConfig] = [] | ||
for _, task in content_item_tasks.items(): | ||
scriptargs = task.scriptarguments | ||
if scriptargs and scriptargs.get("using"): | ||
invalid_tasks.append(task) | ||
self.invalid_tasks[content_item.name] = invalid_tasks | ||
return invalid_tasks | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
return [ | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message.format( | ||
", ".join([task.taskid for task in invalid_tasks]) | ||
), | ||
content_object=content_item, | ||
) | ||
for content_item in content_items | ||
if (invalid_tasks := self.is_playbook_using_an_instance(content_item)) | ||
] | ||
|
||
def fix(self, content_item: ContentTypes) -> FixResult: | ||
invalid_tasks = self.invalid_tasks[content_item.name] | ||
for invalid_task in invalid_tasks: | ||
scriptargs = invalid_task.scriptarguments | ||
if scriptargs and scriptargs.get("using", {}): | ||
scriptargs.pop("using") | ||
return FixResult( | ||
validator=self, | ||
message=self.fix_message.format( | ||
", ".join([task.taskid for task in invalid_tasks]) | ||
), | ||
content_object=content_item, | ||
) |
Oops, something went wrong.