Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into YR/BC103/CIAC-10000
Browse files Browse the repository at this point in the history
  • Loading branch information
RosenbergYehuda committed Apr 2, 2024
2 parents 47112b7 + 44b4997 commit 2a8dd23
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 49 deletions.
6 changes: 0 additions & 6 deletions .changelog/4114.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .changelog/4130.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .changelog/4142.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .changelog/4160.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .changelog/4175.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .changelog/4184.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .changelog/4186.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .changelog/4190.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .changelog/4196.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .changelog/4203.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed an issue where validate spammed logs when running.
type: fix
pr_number: 4203
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# Changelog
## 1.29.0
* The new validate flow is enabled by default while the old one is disabled. If you want to change this behavior, use the **--run-old-validate** and **--skip-new-validate** flags or the **RUN_OLD_VALIDATE** and **SKIP_NEW_VALIDATE** environment variables. [#4114](https://github.com/demisto/demisto-sdk/pull/4114)
* A new version of validate is available. For more information, refer to the readme. (a docs web page with further information about each validation will be added soon). Note that the old validate flow is beginning to go under a deprecation process and will eventually be removed. [#4114](https://github.com/demisto/demisto-sdk/pull/4114)
* Added the `--template-path` argument to the **pre-commit** command. [#4184](https://github.com/demisto/demisto-sdk/pull/4184)
* Added support for a new argument **parallel* for each hook to determine whether a hook run in parallel or not. [#4130](https://github.com/demisto/demisto-sdk/pull/4130)
* Added handling for API Modules in **pre-commit**. [#4175](https://github.com/demisto/demisto-sdk/pull/4175)
* Fixed an issue in **pre-commit** when using `--all-files` it crashed with memory error. [#4196](https://github.com/demisto/demisto-sdk/pull/4196)
* Fixed an issue in **graph update** where all content packs were being parsed. [#4186](https://github.com/demisto/demisto-sdk/pull/4186)
* Fixed an issue in **graph update** to create the graph from scratch if changed packs can not be determined. [#4186](https://github.com/demisto/demisto-sdk/pull/4186)
* Fixed an issue in **graph update** where the graph failed to update in external repositories. [#4190](https://github.com/demisto/demisto-sdk/pull/4190)
* Fixed an issue where **pre-commit** command showed wrong hooks failing. [#4130](https://github.com/demisto/demisto-sdk/pull/4130)
* Fixes an issue where *Fetch Events* and *Fetch Assets* checkboxes appeared in Xsoar Machines. [#4160](https://github.com/demisto/demisto-sdk/pull/4160)
* Added an implicit validation for the graph's *relationship* object by converting it to utilize Pydantic. [#4142](https://github.com/demisto/demisto-sdk/pull/4142)

## 1.28.0
* Added the `validate-xsoar-config` pre-commit hook, replacing `XC` validations. [#4150](https://github.com/demisto/demisto-sdk/pull/4150)
* Add `--prev-version` argument to **pre-commit** command. [#4177](https://github.com/demisto/demisto-sdk/pull/4177)
Expand Down
6 changes: 3 additions & 3 deletions demisto_sdk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,11 @@ def validate(ctx, config, file_paths: str, **kwargs):
"config_path",
"category_to_run",
]:
if new_validate_flag in kwargs:
if kwargs.get(new_validate_flag):
logger.warning(
f"The following flag {new_validate_flag.replace('_', '-')} is related only to the new validate and is being called while not running the new validate flow, therefore the flag will be ignored."
)
if run_old_validate:
if not run_old_validate:
for old_validate_flag in [
"no_backward_comp",
"no_conf_json",
Expand All @@ -865,7 +865,7 @@ def validate(ctx, config, file_paths: str, **kwargs):
"run_specific_validations",
"no_multiprocessing",
]:
if old_validate_flag in kwargs:
if kwargs.get(old_validate_flag):
logger.warning(
f"The following flag {old_validate_flag.replace('_', '-')} is related only to the old validate and is being called while not running the old validate flow, therefore the flag will be ignored."
)
Expand Down
2 changes: 2 additions & 0 deletions demisto_sdk/commands/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ class FileType(str, Enum):
FileType.GENERIC_FIELD,
]

DEFAULT_IMAGE = "demisto_sdk/tests/test_files/default_image.png"

DEFAULT_IMAGE_PREFIX = "data:image/png;base64,"
DEFAULT_IMAGE_BASE64 = (
"iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAACYVBMVEVHcEwAT4UAT4UAT4YAf/8A//8AT4UAf78AT4U"
Expand Down
19 changes: 18 additions & 1 deletion demisto_sdk/commands/content_graph/parsers/related_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from abc import ABC
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -198,14 +199,30 @@ def get_file_size(self):
def get_file_dimensions(self):
raise NotImplementedError

def load_image(self):
raise NotImplementedError


class PNGFiles(ImageFiles):
def get_file_size(self):
return self.file_path.stat()

def load_image(self) -> Union[str, bytearray, memoryview]:
encoded_image = ""
with open(self.file_path, "rb") as image:
image_data = image.read()
encoded_image = base64.b64encode(image_data) # type: ignore
if isinstance(encoded_image, bytes):
encoded_image = encoded_image.decode("utf-8")
return encoded_image


class SVGFiles(ImageFiles):
pass
def load_image(self) -> bytes:
encoded_image = b""
with open(self.file_path, "rb") as image_file:
encoded_image = image_file.read() # type: ignore
return encoded_image


class DarkSVGRelatedFile(RelatedFile):
Expand Down
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 @@ -36,7 +36,7 @@ select = [
"CL100",
"GF100", "GF101", "GF102",
"IF100", "IF101", "IF102", "IF103", "IF104", "IF105", "IF106",
"IM100", "IM108", "IM109",
"IM100", "IM108", "IM109", "IM106",
"RP101", "BC106", "BC107"
]
warning = []
Expand Down
45 changes: 45 additions & 0 deletions demisto_sdk/commands/validate/tests/IM_validators_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import pytest
from pytest_mock import MockerFixture

from demisto_sdk.commands.common.constants import DEFAULT_IMAGE
from demisto_sdk.commands.content_graph.parsers.related_files import (
ImageRelatedFile,
)
from demisto_sdk.commands.validate.tests.test_tools import (
create_integration_object,
create_pack_object,
)
from demisto_sdk.commands.validate.validators.IM_validators.IM100_image_exists_validation import (
ImageExistsValidator,
)
from demisto_sdk.commands.validate.validators.IM_validators.IM106_default_image_validator import (
DefaultImageValidator,
)
from demisto_sdk.commands.validate.validators.IM_validators.IM108_author_image_is_empty import (
AuthorImageIsEmptyValidator,
)
Expand Down Expand Up @@ -112,3 +120,40 @@ def test_AuthorImageIsEmptyValidator_is_valid(
for result, expected_msg in zip(results, expected_msgs)
]
)


def test_DefaultImageValidator_is_valid(mocker: MockerFixture):
"""
Given:
- First integration with a default image.
- Second integration with a sample image
When:
- Calling the DefaultImageValidator is_valid function.
Then:
- Make sure the right amount of integration image validation failed, and that the right error message is returned.
- Case 1: Should fail.
- Case 2: Shouldn't fail.
"""
from pathlib import Path

default_image = ImageRelatedFile(main_file_path=Path(DEFAULT_IMAGE))
sample_image = ImageRelatedFile(
main_file_path=Path("TestSuite/assets/default_integration/sample_image.png")
)

content_items = [create_integration_object(), create_integration_object()]
mocker.patch.object(
content_items[0].image, "load_image", return_value=default_image.load_image()
)
mocker.patch.object(
content_items[1].image, "load_image", return_value=sample_image.load_image()
)
results = DefaultImageValidator().is_valid(content_items)
assert len(results) == 1
assert results[
0
].message == "The integration is using the default image at {0}, please change to the integration image.".format(
DEFAULT_IMAGE
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import annotations

from typing import Iterable, List

from demisto_sdk.commands.common.constants import (
DEFAULT_DBOT_IMAGE_BASE64,
DEFAULT_IMAGE,
DEFAULT_IMAGE_BASE64,
)
from demisto_sdk.commands.content_graph.objects.integration import Integration
from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)

ContentTypes = Integration


class DefaultImageValidator(BaseValidator[ContentTypes]):
error_code = "IM106"
description = "Checks if the integration has an image other than the default ones."
rationale = "If an image is provided, it must not be the default ones."
error_message = "The integration is using the default image at {0}, please change to the integration image."
related_field = "image"
is_auto_fixable = False
related_file_type = [RelatedFileType.IMAGE]

def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
return [
ValidationResult(
validator=self,
message=self.error_message.format(
DEFAULT_IMAGE,
),
content_object=content_item,
)
for content_item in content_items
if (
content_item.image.load_image()
in [
DEFAULT_IMAGE_BASE64,
DEFAULT_DBOT_IMAGE_BASE64,
]
)
]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "demisto-sdk"
version = "1.28.0"
version = "1.29.0"
description = "\"A Python library for the Demisto SDK\""
authors = ["Demisto"]
license = "MIT"
Expand Down

0 comments on commit 2a8dd23

Please sign in to comment.