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

Platform content support #4815

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions demisto_sdk/commands/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1956,13 +1956,15 @@ class MarketplaceVersions(StrEnum):
XPANSE = "xpanse"
XSOAR_SAAS = "xsoar_saas"
XSOAR_ON_PREM = "xsoar_on_prem"
PLATFORM = "platform"


MarketplaceVersionToMarketplaceName = {
MarketplaceVersions.XSOAR.value: DEMISTO_SDK_MARKETPLACE_XSOAR_DIST,
MarketplaceVersions.MarketplaceV2.value: DEMISTO_SDK_MARKETPLACE_XSIAM_DIST,
MarketplaceVersions.XPANSE.value: DEMISTO_SDK_MARKETPLACE_XPANSE_DIST,
MarketplaceVersions.XSOAR_SAAS.value: DEMISTO_SDK_MARKETPLACE_XSOAR_SAAS_DIST,
# TODO - MarketplaceVersions.PLATFORM.value:
}

MARKETPLACE_TO_CORE_PACKS_FILE: Dict[MarketplaceVersions, str] = {
Expand All @@ -1971,6 +1973,7 @@ class MarketplaceVersions(StrEnum):
MarketplaceVersions.XSOAR_ON_PREM: "Config/core_packs_list.json",
MarketplaceVersions.MarketplaceV2: "Config/core_packs_mpv2_list.json",
MarketplaceVersions.XPANSE: "Config/core_packs_xpanse_list.json",
MarketplaceVersions.PLATFORM: "Config/core_packs_platform_list.json",
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
XSOAR_EULA_URL = "https://github.com/demisto/content/blob/master/LICENSE"

CORE_PACKS_LIST = get_core_pack_list()

DEFAULT_PLATFORM_MODULES = ["x1", "x2"]

class PackMetaData(JSONObject):
def __init__(self, path: Union[Path, str]):
Expand Down Expand Up @@ -59,7 +59,9 @@ def __init__(self, path: Union[Path, str]):
self._useCases: List[str] = []
self._keywords: List[str] = []
self._dependencies: Dict[str, Dict] = {}

self._supported_modules: List[str] = DEFAULT_PLATFORM_MODULES
logger.info(f"supported_modules {self._supported_modules}")

@property
def name(self) -> str:
"""Object name attribute.
Expand Down Expand Up @@ -493,6 +495,13 @@ def dependencies(self, new_pack_dependencies: Dict[str, Dict]):
"""Setter for the dependencies attribute"""
self._dependencies = new_pack_dependencies

@property
def supported_modules(self):
"""
TODO - _summary_
"""
return self._supported_modules

def dump_metadata_file(self, dest_dir: Union[Path, str] = "") -> List[Path]:
file_content = {
"name": self.name,
Expand Down Expand Up @@ -577,7 +586,7 @@ def load_user_metadata(self, pack_id: str, pack_name: str, pack_path: Path) -> N
self.categories = user_metadata.get("categories", [])
self.use_cases = user_metadata.get("useCases", [])
self.dependencies = user_metadata.get("dependencies", {})

self.supportedModules = user_metadata.get("supportedModules", DEFAULT_PLATFORM_MODULES)
if self.price > 0:
self.premium = True
self.vendor_id = user_metadata.get("vendorId", "")
Expand Down
8 changes: 8 additions & 0 deletions demisto_sdk/commands/content_graph/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def should_update_graph(
)
)

import subprocess

def log_git_branch():
current_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8').strip()
logger.info(f"On branch {current_branch}")

@recover_if_fails
def update_content_graph(
Expand All @@ -73,6 +78,9 @@ def update_content_graph(
dependencies: bool = True,
output_path: Optional[Path] = None,
) -> None:

log_git_branch()

"""This function updates a new content graph database in neo4j from the content path
Args:
content_graph_interface (ContentGraphInterface): The content graph interface.
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/commands/content_graph/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ def replace_marketplace_references(
if marketplace in {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XPANSE,
MarketplaceVersions.PLATFORM,
}:
if isinstance(data, dict):
keys_to_update = {}
Expand Down
19 changes: 12 additions & 7 deletions demisto_sdk/commands/content_graph/objects/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ def dump_readme(self, path: Path, marketplace: MarketplaceVersions) -> None:
path, marketplace, self.object_id, file_type=ImagesFolderNames.README_IMAGES
)

def dump_release_notes(self, path: Path, marketplace: MarketplaceVersions) -> None:
# TODO - Update this to dump the release notes for the platform marketplace
# starting from platform supported version only.
try:
shutil.copytree(self.path / "ReleaseNotes", path / "ReleaseNotes")
except FileNotFoundError:
logger.debug(f'No such file {self.path / "ReleaseNotes"}')

def dump(self, path: Path, marketplace: MarketplaceVersions, tpb: bool = False):
if not self.path.exists():
logger.warning(f"Pack {self.name} does not exist in {self.path}")
Expand All @@ -330,9 +338,8 @@ def dump(self, path: Path, marketplace: MarketplaceVersions, tpb: bool = False):
try:
path.mkdir(exist_ok=True, parents=True)

content_types_excluded_from_upload = (
CONTENT_TYPES_EXCLUDED_FROM_UPLOAD.copy()
)
content_types_excluded_from_upload = CONTENT_TYPES_EXCLUDED_FROM_UPLOAD.copy()

if tpb:
content_types_excluded_from_upload.discard(ContentType.TEST_PLAYBOOK)

Expand Down Expand Up @@ -379,11 +386,9 @@ def dump(self, path: Path, marketplace: MarketplaceVersions, tpb: bool = False):
except FileNotFoundError:
logger.debug(f"No such file {self.path / VERSION_CONFIG_FILENAME}")

try:
shutil.copytree(self.path / "ReleaseNotes", path / "ReleaseNotes")
except FileNotFoundError:
logger.debug(f'No such file {self.path / "ReleaseNotes"}')

self.dump_release_notes(path / "ReleaseNotes", marketplace)

try:
shutil.copy(self.path / "Author_image.png", path / "Author_image.png")
except FileNotFoundError:
Expand Down
14 changes: 11 additions & 3 deletions demisto_sdk/commands/content_graph/objects/pack_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class PackMetadata(BaseModel):
preview_only: Optional[bool] = Field(None, alias="previewOnly")
disable_monthly: Optional[bool] = Field(None, alias="disableMonthly")
content_commit_hash: Optional[str] = Field(None, alias="contentCommitHash")

supportedModules: Optional[List[str]] = Field(None) # TODO - Rename when decision is made

def _enhance_pack_properties(
self,
marketplace: MarketplaceVersions,
Expand Down Expand Up @@ -188,7 +189,7 @@ def _get_content_items_and_displays_metadata(
collected_content_items: dict = {}
content_displays: dict = {}
for content_item in content_items:
if should_ignore_item_in_metadata(content_item):
if should_ignore_item_in_metadata(content_item, marketplace):
continue
self._add_item_to_metadata_list(
collected_content_items=collected_content_items,
Expand Down Expand Up @@ -491,10 +492,13 @@ def _get_author(author, marketplace):
MarketplaceVersions.XPANSE,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.PLATFORM,
]:
return author
elif marketplace == MarketplaceVersions.MarketplaceV2:
return author.replace("Cortex XSOAR", "Cortex XSIAM")
elif marketplace == MarketplaceVersions.PLATFORM:
return author.replace("Cortex XSOAR", "Cortex")
raise ValueError(f"Unknown marketplace version for author: {marketplace}")

def _add_item_to_metadata_list(
Expand Down Expand Up @@ -640,7 +644,7 @@ def _search_content_item_metadata_object(
return filtered_content_items[0] if filtered_content_items else None


def should_ignore_item_in_metadata(content_item):
def should_ignore_item_in_metadata(content_item, marketplace: MarketplaceVersions):
"""
Checks whether content item should be ignored from metadata
"""
Expand All @@ -652,6 +656,10 @@ def should_ignore_item_in_metadata(content_item):
logger.debug(
f"Skipping {content_item.name} in metadata creation: item is silent playbook/trigger."
)
elif marketplace not in content_item.marketplaces:
logger.debug(
f"Skipping {content_item.name} in metadata creation: item is not supported in {marketplace=}."
)
else:
return False
return True
1 change: 1 addition & 0 deletions demisto_sdk/commands/content_graph/parsers/case_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def object_id(self) -> Optional[str]:
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM
}

@property
Expand Down
5 changes: 4 additions & 1 deletion demisto_sdk/commands/content_graph/parsers/case_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
class CaseLayoutParser(LayoutParser, content_type=ContentType.CASE_LAYOUT):
@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {MarketplaceVersions.MarketplaceV2}
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM
}

@property
def strict_object(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def search_window(self):

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {MarketplaceVersions.MarketplaceV2}
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM,
}

@property
def strict_object(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}

def connect_to_dependencies(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}

def connect_to_dependencies(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ def code(self) -> Optional[str]:

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {
MarketplaceVersions.XSOAR,
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XPANSE,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
}
return set(MarketplaceVersions)

def connect_to_api_modules(self) -> None:
"""Creates IMPORTS relationships with the API modules used in the integration."""
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/commands/content_graph/parsers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.XSOAR,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}

def connect_to_dependencies(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/commands/content_graph/parsers/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}

def connect_to_dependencies(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def layout_id(self) -> Optional[str]:
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM
}

def connect_to_dependencies(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/commands/content_graph/parsers/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.XPANSE,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def rules_key(self) -> Optional[str]:

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {MarketplaceVersions.MarketplaceV2}
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM,
}

@property
def strict_object(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def field_mapping(self):

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {MarketplaceVersions.MarketplaceV2}
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM,
}

@property
def strict_object(self):
Expand Down
8 changes: 1 addition & 7 deletions demisto_sdk/commands/content_graph/parsers/playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,4 @@ def __init__(

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {
MarketplaceVersions.XSOAR,
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XPANSE,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
}
return set(MarketplaceVersions)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.XSOAR,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
barryyosi-panw marked this conversation as resolved.
Show resolved Hide resolved
}

@property
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/commands/content_graph/parsers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.XSOAR,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}

def connect_to_dependencies(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}
5 changes: 4 additions & 1 deletion demisto_sdk/commands/content_graph/parsers/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def field_mapping(self):

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {MarketplaceVersions.MarketplaceV2}
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM,
}

def connect_to_dependencies(self) -> None:
"""Collects the playbook used in the trigger as a mandatory dependency."""
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/commands/content_graph/parsers/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def supported_marketplaces(self) -> Set[MarketplaceVersions]:
MarketplaceVersions.XSOAR,
MarketplaceVersions.XSOAR_SAAS,
MarketplaceVersions.XSOAR_ON_PREM,
MarketplaceVersions.PLATFORM,
}

def get_packs(self) -> List[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def field_mapping(self):

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {MarketplaceVersions.MarketplaceV2}
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.XSOAR_ON_PREM,
}

@property
def strict_object(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def field_mapping(self):

@property
def supported_marketplaces(self) -> Set[MarketplaceVersions]:
return {MarketplaceVersions.MarketplaceV2}
return {
MarketplaceVersions.MarketplaceV2,
MarketplaceVersions.PLATFORM,
}


@property
def strict_object(self):
Expand Down
Loading
Loading