Skip to content

Commit

Permalink
Merge branch 'master' into support_assets_modeling_rules_folder
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
merit-maita committed Nov 28, 2023
2 parents b5e0875 + b5fec54 commit 4bab3b8
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Fixed an issue where **run-playbook** command did not work.
* Fixed an issue in **setup-env** command where the virtual environment failed to set up.
* Fixed an issue in **pre-commit** command where `False` properties were deleted.
* Fixed an issue in **coverage-analyze** command where the `report_dir` does not exist.
* Fixed an issue in **upload** command where the `marketplace` field was not taken into consideration when uploading single content-items.
* Added support for *Assets Modeling Rule* as a new content item in *content-graph*, *schemas* and all *demisto-sdk* commands.

## 1.23.0
Expand Down
1 change: 1 addition & 0 deletions demisto_sdk/commands/coverage_analyze/coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
str
] = f"https://storage.googleapis.com/{DEMISTO_SDK_MARKETPLACE_XSOAR_DIST_DEV}/code-coverage-reports/coverage-min.json",
):
Path(report_dir).mkdir(parents=True, exist_ok=True)
self.report_dir = report_dir
self._cov: Optional[coverage.Coverage] = None
self._report_str: Optional[str] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_run_repo_test_playbooks(self, mocker, tpb_result, res, message, capsys)
)
assert result == res

assert count_str_in_call_args_list(logger_info.call_args_list, message) == 7
assert count_str_in_call_args_list(logger_info.call_args_list, message) == 8

@pytest.mark.parametrize(
argnames="input_tpb, exit_code, err",
Expand Down
35 changes: 33 additions & 2 deletions demisto_sdk/commands/upload/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def __init__(
Tuple[Union[ContentItem, Pack], str]
] = []
self._failed_upload_version_mismatch: List[ContentItem] = []
self._skipped_upload_marketplace_mismatch: List[ContentItem] = []
self._failed_upload_zips: List[str] = []
self.failed_parsing: List[Tuple[Path, str]] = []

Expand Down Expand Up @@ -251,7 +252,8 @@ def _upload_single(self, path: Path) -> bool:
Upload a content item, a pack, or a zip containing packs.
Returns:
bool: whether the item is uploaded succesfully.
bool: whether the item is uploaded succesfully to the relevant
given marketplace.
Raises:
NotIndivitudallyUploadedException (see exception class)
Expand All @@ -268,7 +270,13 @@ def _upload_single(self, path: Path) -> bool:
)
self.failed_parsing.append((path, reason))
return False

if (
self.marketplace
and isinstance(content_item, ContentItem)
and self.marketplace not in content_item.marketplaces
):
self._skipped_upload_marketplace_mismatch.append(content_item)
return True
try:
content_item.upload(
client=self.client,
Expand Down Expand Up @@ -421,6 +429,29 @@ def print_summary(self) -> None:

logger.info(f"[green]SUCCESSFUL UPLOADS:\n{uploaded_str}\n[/green]")

if self._skipped_upload_marketplace_mismatch:
marketplace_mismatch_str = tabulate(
(
(
item.path.name,
item.content_type,
self.marketplace,
[marketplace.value for marketplace in item.marketplaces],
)
for item in self._skipped_upload_marketplace_mismatch
),
headers=[
"NAME",
"TYPE",
"MARKETPLACE",
"FILE_MARKETPLACES",
],
tablefmt="fancy_grid",
)
logger.info(
f"[yellow]SKIPPED UPLOADED DUE TO MARKETPLACE MISMATCH:\n{marketplace_mismatch_str}\n[/yellow]"
)

if self._failed_upload_version_mismatch:
version_mismatch_str = tabulate(
(
Expand Down
65 changes: 65 additions & 0 deletions demisto_sdk/tests/integration_tests/upload_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,71 @@ def test_integration_upload_pack_positive(demisto_client_mock, mocker):
)


def test_integration_upload_pack_with_specific_marketplace(demisto_client_mock, mocker):
"""
Given
- Content pack named ExmaplePack to upload.
When
- Uploading the pack.
Then
- Ensure upload runs successfully.
- Ensure success upload message is printed.
- Ensure Skipped message is printed.
"""
import demisto_sdk.commands.content_graph.objects.content_item as content_item

logger_info = mocker.patch.object(logging.getLogger("demisto-sdk"), "info")
pack_path = Path(
DEMISTO_SDK_PATH,
"tests/test_files/content_repo_example/Packs/ExamplePack/Integrations",
)
mocker.patch.object(
content_item,
"CONTENT_PATH",
Path(DEMISTO_SDK_PATH, "tests/test_files/content_repo_example"),
)

for content_class in (
IncidentField,
Integration,
Playbook,
Script,
):
mock_upload_method(mocker, content_class)

runner = CliRunner(mix_stderr=False)
mocker.patch.object(PackParser, "parse_ignored_errors", return_value={})
result = runner.invoke(
main, [UPLOAD_CMD, "-i", str(pack_path), "--insecure", "--marketplace", "xsoar"]
)
assert result.exit_code == 0
logged = flatten_call_args(logger_info.call_args_list)
assert logged[-1] == "\n".join(
(
"[yellow]SKIPPED UPLOADED DUE TO MARKETPLACE MISMATCH:",
"╒════════════════════════════════════════╤═════════════╤═══════════════╤═════════════════════╕",
"│ NAME │ TYPE │ MARKETPLACE │ FILE_MARKETPLACES │",
"╞════════════════════════════════════════╪═════════════╪═══════════════╪═════════════════════╡",
"│ integration-sample_event_collector.yml │ Integration │ xsoar │ ['marketplacev2'] │",
"╘════════════════════════════════════════╧═════════════╧═══════════════╧═════════════════════╛",
"[/yellow]",
)
)
assert logged[-2] == "\n".join(
(
"[green]SUCCESSFUL UPLOADS:",
"╒══════════════════════════════╤═════════════╤═════════════╤════════════════╕",
"│ NAME │ TYPE │ PACK NAME │ PACK VERSION │",
"╞══════════════════════════════╪═════════════╪═════════════╪════════════════╡",
"│ integration-sample_packs.yml │ Integration │ ExamplePack │ 3.0.0 │",
"╘══════════════════════════════╧═════════════╧═════════════╧════════════════╛",
"[/green]",
)
)


METADATA_DISPLAYS = {
"automation": "Automation",
"classifier": "Classifiers",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
category: "test"
name: name
name_x2: name_x2
commonfields:
id: SampleEventCollector
version: -1
id: id
display: My display name
script:
script: >2
pass
subtype: python3
type: python
type: python
subtype: python3
defaultEnabled: false
defaultEnabled_x2: true
marketplaces:
- marketplacev2
fromversion: 8.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fromversion: "6.0.0"
category: "test"
name: name
name_x2: name_x2
commonfields:
id: Sample Integration
version: -1
id: id
display: My display name
script:
script: >2
pass
subtype: python3
type: python
type: python
subtype: python3
defaultEnabled: false
defaultEnabled_x2: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This content pack example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
commonfields:
id: just_a_test
version: -1
name: just_a_test
script: wait(parseInt(args.seconds));
type: javascript
tags:
- Utility
comment: Sleep for X seconds
enabled: true
args:
- name: seconds
required: true
default: true
description: Amount of seconds to sleep
scripttarget: 0
timeout: 1h40m0s
fromversion: 5.5.0
tests:
- No tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ExamplePack",
"description": "This is example.",
"support": "community",
"currentVersion": "3.0.0",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
"created": "2020-03-10T08:37:18Z",
"certification": "verified",
"categories": [
"Utilities"
],
"tags": [
"Getting Started"
],
"useCases": [],
"keywords": [],
"dependencies": {
},
"marketplaces": [
"xsoar",
"marketplacev2"
]
}

0 comments on commit 4bab3b8

Please sign in to comment.