Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PB126 #4349

Merged
merged 6 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changelog/4349.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changes:
- description: Added DS105 to the new validation format. Ensure that conditional tasks have more than path which is not
ShahafBenYakir marked this conversation as resolved.
Show resolved Hide resolved
the default one
ShahafBenYakir marked this conversation as resolved.
Show resolved Hide resolved
type: internal
pr_number: 4349
4 changes: 2 additions & 2 deletions demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ select = [
"IN100", "IN101", "IN102", "IN104", "IN106", "IN107", "IN108", "IN109", "IN110", "IN112", "IN113", "IN114", "IN115", "IN117", "IN118", "IN121", "IN122", "IN123", "IN124", "IN125", "IN126", "IN127", "IN130",
"IN131", "IN134", "IN135", "IN139", "IN141", "IN142", "IN144", "IN145", "IN146", "IN149", "IN150", "IN151", "IN152", "IN153", "IN154", "IN156", "IN158", "IN159", "IN160",
"IN161", "IN162",
"PB100", "PB101","PB104","PB118", "PB123",
"PB100", "PB101","PB104","PB118", "PB123", "PB126",
"DO100", "DO101", "DO102", "DO103", "DO104", "DO105", "DO106",
"DS100", "DS107",
"SC100", "SC105", "SC106", "SC109",
Expand All @@ -52,7 +52,7 @@ select = [
"IN131", "IN134", "IN135", "IN139", "IN141", "IN142", "IN144", "IN145", "IN146", "IN149", "IN150", "IN151", "IN152", "IN153", "IN154", "IN156", "IN158", "IN159", "IN160",
"IN161", "IN162",
"LO107",
"PB100", "PB101","PB104", "PB123",
"PB100", "PB101","PB104", "PB123", "PB126",
"BA100", "BA101", "BA105", "BA106", "BA110", "BA111", "BA113", "BA116", "BA118", "BA119", "BA126",
"DS100",
"PA100", "PA101", "PA102", "PA103", "PA104", "PA105", "PA107", "PA108", "PA109", "PA111", "PA113", "PA115", "PA117", "PA118", "PA119", "PA120",
Expand Down
35 changes: 33 additions & 2 deletions demisto_sdk/commands/validate/tests/PB_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from demisto_sdk.commands.validate.validators.PB_validators.PB123_is_conditional_task_has_unhandled_reply_options import (
IsAskConditionHasUnhandledReplyOptionsValidator,
)
from demisto_sdk.commands.validate.validators.PB_validators.PB126_is_default_not_only_condition import (
IsDefaultNotOnlyConditionValidator,
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -187,7 +190,6 @@ def test_is_deprecated_with_invalid_description(content_item, expected_result):


def test_IsAskConditionHasUnreachableConditionValidator():

playbook = create_playbook_object()
assert not IsAskConditionHasUnreachableConditionValidator().is_valid([playbook])
playbook.tasks = {
Expand All @@ -206,7 +208,6 @@ def test_IsAskConditionHasUnreachableConditionValidator():


def test_IsAskConditionHasUnhandledReplyOptionsValidator():

playbook = create_playbook_object()
assert not IsAskConditionHasUnhandledReplyOptionsValidator().is_valid([playbook])
playbook.tasks = {
Expand All @@ -222,3 +223,33 @@ def test_IsAskConditionHasUnhandledReplyOptionsValidator():
)
}
assert IsAskConditionHasUnhandledReplyOptionsValidator().is_valid([playbook])


def test_IsDefaultNotOnlyConditionValidator():
ShahafBenYakir marked this conversation as resolved.
Show resolved Hide resolved
playbook = create_playbook_object()
assert not IsDefaultNotOnlyConditionValidator().is_valid([playbook])
playbook.tasks = {
"0": TaskConfig(
**{
"id": "0",
"type": "condition",
"taskid": "27b9c747-b883-4878-8b60-7f352098a631",
"message": {"replyOptions": ["yes", "no"]},
"task": {"id": "27b9c747-b883-4878-8b60-7f352098a63c"},
}
)
}

assert not IsDefaultNotOnlyConditionValidator().is_valid([playbook])
playbook.tasks = {
"0": TaskConfig(
**{
"id": "0",
"type": "condition",
"taskid": "27b9c747-b883-4878-8b60-7f352098a631",
"message": {"replyOptions": ["#default#"]},
"task": {"id": "27b9c747-b883-4878-8b60-7f352098a63c"},
}
)
}
assert IsDefaultNotOnlyConditionValidator().is_valid([playbook])
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 more than path which is not the default one"
)
ShahafBenYakir marked this conversation as resolved.
Show resolved Hide resolved
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 = (
"Playbook task with id:{} only has a default option. Please remove this task or add another "
"non-default option to the task"
ShahafBenYakir marked this conversation as resolved.
Show resolved Hide resolved
)
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:
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:
validation_results.append(
ShahafBenYakir marked this conversation as resolved.
Show resolved Hide resolved
ValidationResult(
validator=self,
message=self.error_message.format(task.id),
content_object=content_item,
)
)
ShahafBenYakir marked this conversation as resolved.
Show resolved Hide resolved
return validation_results
Loading