-
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.
- Loading branch information
Showing
5 changed files
with
74 additions
and
1 deletion.
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 the `defaultDataSource` field to the pack metadata. | ||
type: feature | ||
pr_number: 4139 |
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
48 changes: 48 additions & 0 deletions
48
demisto_sdk/commands/validate/validators/PA_validators/PA131_is_default_datasource.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,48 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List, Union | ||
|
||
from demisto_sdk.commands.common.constants import MarketplaceVersions | ||
from demisto_sdk.commands.content_graph.objects.integration import Integration | ||
from demisto_sdk.commands.content_graph.objects.pack import Pack | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Union[Pack, Integration] | ||
|
||
|
||
class IsDefaultDataSourceProvidedValidator(BaseValidator[ContentTypes]): | ||
error_code = "PA131" | ||
description = "Validate that the pack_metadata contains a default datasource if there are more than one datasource." | ||
rationale = "Wizards and other tools rely on the default datasource to be set." | ||
error_message = "Pack metadata does not contain a default datasource. Please fill in a default datasource." | ||
related_field = "defaultDatasource" | ||
is_auto_fixable = False | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
datasource_count = 0 | ||
for content_item in content_items: | ||
if content_item == Integration: | ||
fetch_incidents_command = False | ||
for command in content_item.commands: # type: ignore | ||
if command.name == "fetch-incidents": | ||
fetch_incidents_command = True | ||
break | ||
if MarketplaceVersions.MarketplaceV2 in content_item.marketplaces and ( | ||
( | ||
content_item.is_fetch or content_item.is_fetch_events or content_item.is_mappable or content_item.is_fetch_events_and_assets # type: ignore | ||
) | ||
or fetch_incidents_command | ||
): | ||
datasource_count += 1 | ||
return [ | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message, | ||
content_object=content_item, | ||
) | ||
if datasource_count > 1 and not content_item.default_data_source # type: ignore | ||
else None | ||
] |