Skip to content

Commit

Permalink
Merge 1753740 into 623aceb
Browse files Browse the repository at this point in the history
  • Loading branch information
omerKarkKatz committed Apr 11, 2024
2 parents 623aceb + 1753740 commit 4623c20
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 41 deletions.
4 changes: 4 additions & 0 deletions .changelog/4218.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed an issue where `xsoar_on_prem` tag, was not removed as part of the parsing process.
type: fix
pr_number: 4218
12 changes: 12 additions & 0 deletions demisto_sdk/commands/content_graph/parsers/base_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import Optional

from demisto_sdk.commands.common.constants import MarketplaceVersions
from demisto_sdk.commands.common.content_constant_paths import (
CONTENT_PATH,
)
Expand Down Expand Up @@ -39,3 +40,14 @@ def node_id(self) -> str:
@property
def source_repo(self) -> Optional[str]:
return CONTENT_PATH.name

@staticmethod
def update_marketplaces_set_with_xsoar_values(marketplaces_set: set) -> set:
if MarketplaceVersions.XSOAR in marketplaces_set:
marketplaces_set.add(MarketplaceVersions.XSOAR_SAAS)

if MarketplaceVersions.XSOAR_ON_PREM in marketplaces_set:
marketplaces_set.add(MarketplaceVersions.XSOAR)
marketplaces_set.remove(MarketplaceVersions.XSOAR_ON_PREM)

return marketplaces_set
26 changes: 9 additions & 17 deletions demisto_sdk/commands/content_graph/parsers/content_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,19 @@ def get_marketplaces(self, data: dict) -> List[MarketplaceVersions]:
MarketplaceVersions(mp) for mp in data.get("marketplaces", [])
]:
marketplaces = file_marketplaces
marketplaces = list(
ContentItemParser.update_marketplaces_set_with_xsoar_values(
set(marketplaces)
)
)
else:
# update_marketplaces_set_with_xsoar_values is already handeled as part of pack parser.
marketplaces = self.pack_marketplaces

marketplaces_set = set(marketplaces).intersection(self.supported_marketplaces)
marketplaces_set = self.update_marketplaces_set_with_xsoar_values(
marketplaces_set
marketplaces_intersection = set(marketplaces).intersection(
self.supported_marketplaces
)
return sorted(marketplaces_set)

@staticmethod
def update_marketplaces_set_with_xsoar_values(marketplaces_set: set) -> set:
if (
MarketplaceVersions.XSOAR in marketplaces_set
and MarketplaceVersions.XSOAR_ON_PREM not in marketplaces_set
):
marketplaces_set.add(MarketplaceVersions.XSOAR_SAAS)

if MarketplaceVersions.XSOAR_ON_PREM in marketplaces_set:
marketplaces_set.add(MarketplaceVersions.XSOAR)

return marketplaces_set
return sorted(marketplaces_intersection)

@property
@abstractmethod
Expand Down
28 changes: 13 additions & 15 deletions demisto_sdk/commands/content_graph/parsers/pack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from functools import cached_property
from pathlib import Path
from typing import Any, Dict, Iterator, List, Optional
from typing import Any, Dict, Iterator, List, Optional, Set

import regex
from git import InvalidGitRepositoryError
Expand Down Expand Up @@ -119,6 +119,7 @@ class PackMetadataParser:
"""A pack metadata parser."""

def __init__(self, path: Path, metadata: Dict[str, Any]) -> None:
self._metadata: Dict[str, Any] = metadata
self.name: str = metadata.get("name", "")
self.display_name: str = metadata.get("name", "")
self.description: str = metadata.get("description", "")
Expand Down Expand Up @@ -151,19 +152,6 @@ def __init__(self, path: Path, metadata: Dict[str, Any]) -> None:
self.keywords: List[str] = metadata.get("keywords", [])
self.search_rank: int = 0
self.videos: List[str] = metadata.get("videos", [])
self.marketplaces: List[str] = (
metadata.get("marketplaces") or PACK_DEFAULT_MARKETPLACES
)
if MarketplaceVersions.XSOAR.value in self.marketplaces:
# Since we want xsoar-saas and xsoar to contain the same content items.
self.marketplaces.append(MarketplaceVersions.XSOAR_SAAS.value)

if MarketplaceVersions.XSOAR_ON_PREM.value in self.marketplaces:
self.marketplaces.append(MarketplaceVersions.XSOAR.value)

marketplaces_set = set(self.marketplaces)
self.marketplaces = sorted(marketplaces_set)

self.excluded_dependencies: List[str] = metadata.get("excludedDependencies", [])
self.modules: List[str] = metadata.get("modules", [])
self.integrations: List[str] = []
Expand Down Expand Up @@ -212,6 +200,16 @@ def categories(self):
def use_cases(self):
return [capital_case(c) for c in self.pack_metadata_dict.get("useCases", [])]

@property
def marketplaces(self) -> List[MarketplaceVersions]:
marketplaces = self._metadata.get("marketplaces") or PACK_DEFAULT_MARKETPLACES
marketplace_set: Set[
MarketplaceVersions
] = BaseContentParser.update_marketplaces_set_with_xsoar_values(
{MarketplaceVersions(mp) for mp in marketplaces}
)
return sorted(list(marketplace_set))

def get_author_image_filepath(self, path: Path) -> str:
if (path / "Author_image.png").is_file():
return f"content/packs/{path.name}/Author_image.png"
Expand Down Expand Up @@ -322,7 +320,7 @@ def parse_content_item(self, content_item_path: Path) -> None:
"""
try:
content_item = ContentItemParser.from_path(
content_item_path, [MarketplaceVersions(mp) for mp in self.marketplaces]
content_item_path, self.marketplaces
)
content_item.add_to_pack(self.object_id)
self.content_items.append(content_item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from demisto_sdk.commands.content_graph.objects.content_item import ContentItem
from demisto_sdk.commands.content_graph.objects.pack import Pack as PackModel
from demisto_sdk.commands.content_graph.objects.pre_process_rule import PreProcessRule
from demisto_sdk.commands.content_graph.parsers.base_content import BaseContentParser
from demisto_sdk.commands.content_graph.parsers.content_item import (
ContentItemParser,
InvalidContentItemException,
Expand Down Expand Up @@ -2804,24 +2805,26 @@ def test_fix_layout_incident_to_alert(
{MarketplaceVersions.XSOAR},
{MarketplaceVersions.XSOAR, MarketplaceVersions.XSOAR_SAAS},
),
(
{MarketplaceVersions.XSOAR, MarketplaceVersions.XSOAR_ON_PREM},
{MarketplaceVersions.XSOAR, MarketplaceVersions.XSOAR_SAAS},
),
({MarketplaceVersions.MarketplaceV2}, {MarketplaceVersions.MarketplaceV2}),
({MarketplaceVersions.XPANSE}, {MarketplaceVersions.XPANSE}),
(
{MarketplaceVersions.XSOAR_ON_PREM},
{MarketplaceVersions.XSOAR_ON_PREM, MarketplaceVersions.XSOAR},
{MarketplaceVersions.XSOAR},
),
(
{MarketplaceVersions.XSOAR_ON_PREM, MarketplaceVersions.XSOAR_SAAS},
{
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR,
},
),
(
{MarketplaceVersions.XSOAR_ON_PREM, MarketplaceVersions.MarketplaceV2},
{
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XSOAR,
},
Expand Down Expand Up @@ -2851,13 +2854,9 @@ def test_updated_marketplaces_set(marketplace, expected_market_place_set):
- remains empty
"""
from demisto_sdk.commands.content_graph.parsers.content_item import (
ContentItemParser,
)

assert (
expected_market_place_set
== ContentItemParser.update_marketplaces_set_with_xsoar_values(marketplace)
== BaseContentParser.update_marketplaces_set_with_xsoar_values(marketplace)
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"marketplaces": [
"xsoar",
"marketplacev2"
"marketplacev2",
"xsoar_on_prem"
]
}

0 comments on commit 4623c20

Please sign in to comment.