-
Notifications
You must be signed in to change notification settings - Fork 68
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
3 changed files
with
369 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
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
68 changes: 68 additions & 0 deletions
68
demisto_sdk/commands/validate/validators/BC_validators/BC108_was_marketplace_modified.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,68 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List, Union | ||
|
||
from demisto_sdk.commands.common.constants import GitStatuses, MarketplaceVersions | ||
from demisto_sdk.commands.content_graph.objects.integration import Integration | ||
from demisto_sdk.commands.content_graph.objects.script import Script | ||
from demisto_sdk.commands.content_graph.objects.incident_type import IncidentType | ||
from demisto_sdk.commands.content_graph.objects.mapper import Mapper | ||
from demisto_sdk.commands.content_graph.objects.indicator_field import IndicatorField | ||
from demisto_sdk.commands.content_graph.objects.indicator_type import IndicatorType | ||
from demisto_sdk.commands.content_graph.objects.incident_field import IncidentField | ||
from demisto_sdk.commands.content_graph.objects import Pack | ||
from demisto_sdk.commands.content_graph.objects import Playbook | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Union[ | ||
Integration, | ||
Script, | ||
IncidentType, | ||
Mapper, | ||
IndicatorField, | ||
IndicatorType, | ||
IncidentField, | ||
Pack, | ||
Playbook, | ||
] | ||
ALL_MARKETPLACES = list(MarketplaceVersions) | ||
|
||
|
||
class WasMarketplaceModifiedValidator(BaseValidator[ContentTypes]): | ||
error_code = "BC108" | ||
description = "Ensuring that the 'marketplaces' property hasn't been removed or added in a manner that effectively removes all others." | ||
error_message = "You can't add new marketplaces if they'll remove existing ones, or delete current marketplace content. Please undo the change or ask for a forced merge." | ||
fix_message = "" | ||
related_field = "marketplaces" | ||
is_auto_fixable = False | ||
expected_git_statuses = [GitStatuses.MODIFIED] | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
results: List[ValidationResult] = [] | ||
for content_item in content_items: | ||
|
||
new_marketplaces = content_item.marketplaces | ||
old_marketplaces = content_item.old_base_content_object.marketplaces # type: ignore | ||
|
||
# if the content is not a pack, we may want to compare to the pack marketplaces as well, since the item inherits the pack marketplaces, if not specified | ||
if not isinstance(content_item, Pack): | ||
pack_marketplaces = content_item.in_pack.marketplaces # type: ignore | ||
|
||
# If all marketplaces are included, it might be due to the field not appearing. However, in reality, it is available only in a specific marketplace inherited from the pack marketplace. | ||
# In this scenario, we will compare the pack's marketplaces as it serves as the source of truth. | ||
if set(old_marketplaces) == set(ALL_MARKETPLACES): | ||
old_marketplaces = pack_marketplaces | ||
|
||
if not (set(old_marketplaces).issubset(set(new_marketplaces))): | ||
results.append( | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message, | ||
content_object=content_item, | ||
) | ||
) | ||
|
||
return results |