Skip to content

Commit

Permalink
Merge 89a1961 into 44b4997
Browse files Browse the repository at this point in the history
  • Loading branch information
amshamah419 committed Apr 3, 2024
2 parents 44b4997 + 89a1961 commit e0227c6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changelog/4139.yml
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
19 changes: 19 additions & 0 deletions demisto_sdk/commands/content_graph/objects/pack_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PackMetadata(BaseModel):
modules: List[str] = Field([])
integrations: List[str] = Field([])
hybrid: bool = Field(False, alias="hybrid")
default_data_source: Optional[str] = Field(None, alias="defaultDataSource")

# For private packs
premium: Optional[bool]
Expand Down Expand Up @@ -103,6 +104,7 @@ def _format_metadata(
- Adding the content items display names.
- Gathering the pack dependencies and adding the metadata.
- Unifying the `url` and `email` into the `support_details` property.
- Adding the default data source if exists.
Args:
marketplace (MarketplaceVersions): The marketplace to which the pack should belong to.
Expand All @@ -125,6 +127,7 @@ def _format_metadata(
"contentDisplays": content_displays,
"dependencies": self._enhance_dependencies(marketplace, dependencies),
"supportDetails": self._get_support_details(),
"defaultDataSource": self._get_default_data_source(content_items),
}
)

Expand Down Expand Up @@ -329,6 +332,22 @@ def _is_data_source(self, content_items: PackContentItems) -> bool:
== 1
)

def _get_default_data_source(
self, content_items: PackContentItems
) -> Optional[str]:
"""If there is more than one data source in the pack, return the default data source."""
data_sources = [
integration.name
for integration in content_items.integration
if MarketplaceVersions.MarketplaceV2 in integration.marketplaces
and (integration.is_fetch or integration.is_fetch_events)
]
if len(data_sources) > 1:
logger.debug(
f"{self.name} has multiple datasources. Setting a default value."
)
return data_sources[0] if len(data_sources) > 1 else None

def _get_tags_from_landing_page(self, pack_id: str) -> set:
"""
Build the pack's tag list according to the landingPage sections file.
Expand Down
2 changes: 2 additions & 0 deletions demisto_sdk/commands/content_graph/parsers/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def __init__(self, path: Path, metadata: Dict[str, Any]) -> None:
self.commit = ""
self.downloads: int = 0
self.tags: List[str] = metadata.get("tags") or []
self.default_data_source: str = metadata.get("defaultDataSource") or ""
self.keywords: List[str] = metadata.get("keywords", [])
self.search_rank: int = 0
self.videos: List[str] = metadata.get("videos", [])
Expand Down Expand Up @@ -373,4 +374,5 @@ def field_mapping(self):
"modules": "modules",
"disable_monthly": "disableMonthly",
"content_commit_hash": "contentCommitHash",
"default_data_source": "defaultDataSource",
}
2 changes: 1 addition & 1 deletion demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ignorable_errors = [
select = [
"BA100", "BA101", "BA105", "BA106", "BA110", "BA111", "BA114", "BA116", "BA118", "BA119", "BA124", "BA126",
"PA100", "PA101", "PA102", "PA103", "PA104", "PA105", "PA107", "PA108", "PA109", "PA111", "PA113", "PA115", "PA117", "PA118", "PA119", "PA120",
"PA121", "PA123", "PA125", "PA127", "PA128", "PA130",
"PA121", "PA123", "PA125", "PA127", "PA128", "PA130", "PA131",
"BC100", "BC101", "BC102", "BC105", "BC108",
"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",
Expand Down
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
]

0 comments on commit e0227c6

Please sign in to comment.