From b3b8fd6ac39a83165d592a950b5e74a793cf8d45 Mon Sep 17 00:00:00 2001 From: merit-maita <49760643+merit-maita@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:36:51 +0200 Subject: [PATCH] support asset collection (#4005) * fixes for displaying items * removed sorting keys * added logs and reveerted changes * fixed validating rules --- .changelog/4005.yml | 4 ++++ demisto_sdk/commands/common/constants.py | 1 + demisto_sdk/commands/common/errors.py | 16 ++++++---------- .../hook_validations/content_entity_validator.py | 8 +++++++- .../common/hook_validations/modeling_rule.py | 15 ++++++++++++++- .../parsers/assets_modeling_rule.py | 4 +++- 6 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 .changelog/4005.yml diff --git a/.changelog/4005.yml b/.changelog/4005.yml new file mode 100644 index 0000000000..f7d669a0cb --- /dev/null +++ b/.changelog/4005.yml @@ -0,0 +1,4 @@ +changes: +- description: Added description field to *Assets Modeling Rules* content item. + type: internal +pr_number: 4005 diff --git a/demisto_sdk/commands/common/constants.py b/demisto_sdk/commands/common/constants.py index c3ca70bde1..82e7413638 100644 --- a/demisto_sdk/commands/common/constants.py +++ b/demisto_sdk/commands/common/constants.py @@ -890,6 +890,7 @@ class FileType(str, Enum): MODELING_RULE_PREFIX = "modelingrule" MODELING_RULE_ID_SUFFIX = "ModelingRule" MODELING_RULE_NAME_SUFFIX = "Modeling Rule" +ASSETS_MODELING_RULE_NAME_SUFFIX = "Asset Collection" XDRC_TEMPLATE_PREFIX = "xdrctemplate" LAYOUT_RULE_PREFIX = "layoutrule" ASSETS_MODELING_RULE_ID_SUFFIX = "AssetsModelingRule" diff --git a/demisto_sdk/commands/common/errors.py b/demisto_sdk/commands/common/errors.py index ef5def330e..a721fc69b7 100644 --- a/demisto_sdk/commands/common/errors.py +++ b/demisto_sdk/commands/common/errors.py @@ -11,13 +11,9 @@ BETA_INTEGRATION_DISCLAIMER, FILETYPE_TO_DEFAULT_FROMVERSION, INTEGRATION_CATEGORIES, - MODELING_RULE_ID_SUFFIX, - MODELING_RULE_NAME_SUFFIX, MODULES, PACK_METADATA_DESC, PACK_METADATA_NAME, - PARSING_RULE_ID_SUFFIX, - PARSING_RULE_NAME_SUFFIX, RELIABILITY_PARAMETER_NAMES, RN_CONTENT_ENTITY_WITH_STARS, RN_HEADER_BY_FILE_TYPE, @@ -4294,22 +4290,22 @@ def invalid_rule_name(invalid_files): @staticmethod @error_code_decorator - def invalid_modeling_rule_suffix_name(file_path, **kwargs): + def invalid_modeling_rule_suffix_name(file_path, id_suffix, name_suffix, **kwargs): message = f"The file {file_path} is invalid:" if kwargs.get("invalid_id"): - message += f"\nThe rule id should end with '{MODELING_RULE_ID_SUFFIX}'" + message += f"\nThe rule id should end with '{id_suffix}'" if kwargs.get("invalid_name"): - message += f"\nThe rule name should end with '{MODELING_RULE_NAME_SUFFIX}'" + message += f"\nThe rule name should end with '{name_suffix}'" return message @staticmethod @error_code_decorator - def invalid_parsing_rule_suffix_name(file_path, **kwargs): + def invalid_parsing_rule_suffix_name(file_path, id_suffix, name_suffix, **kwargs): message = f"The file {file_path} is invalid:" if kwargs.get("invalid_id"): - message += f"\nThe rule id should end with '{PARSING_RULE_ID_SUFFIX}'" + message += f"\nThe rule id should end with '{id_suffix}'" if kwargs.get("invalid_name"): - message += f"\nThe rule name should end with '{PARSING_RULE_NAME_SUFFIX}'" + message += f"\nThe rule name should end with '{name_suffix}'" return message @staticmethod diff --git a/demisto_sdk/commands/common/hook_validations/content_entity_validator.py b/demisto_sdk/commands/common/hook_validations/content_entity_validator.py index 8547ac39e9..a4c02fb3e7 100644 --- a/demisto_sdk/commands/common/hook_validations/content_entity_validator.py +++ b/demisto_sdk/commands/common/hook_validations/content_entity_validator.py @@ -9,6 +9,8 @@ from demisto_sdk.commands.common.constants import ( API_MODULES_PACK, + ASSETS_MODELING_RULE, + ASSETS_MODELING_RULE_NAME_SUFFIX, DEFAULT_CONTENT_ITEM_FROM_VERSION, DEMISTO_GIT_UPSTREAM, ENTITY_NAME_SEPARATORS, @@ -775,6 +777,10 @@ def is_valid_rule_suffix(self, rule_type: str) -> bool: id_suffix = PARSING_RULE_ID_SUFFIX name_suffix = PARSING_RULE_NAME_SUFFIX invalid_suffix_function = Errors.invalid_parsing_rule_suffix_name + if rule_type == ASSETS_MODELING_RULE: + id_suffix = MODELING_RULE_ID_SUFFIX + name_suffix = ASSETS_MODELING_RULE_NAME_SUFFIX + invalid_suffix_function = Errors.invalid_modeling_rule_suffix_name invalid_suffix = { "invalid_id": not rule_id.endswith(id_suffix), @@ -783,7 +789,7 @@ def is_valid_rule_suffix(self, rule_type: str) -> bool: if any(invalid_suffix.values()): error_message, error_code = invalid_suffix_function( - self.file_path, **invalid_suffix + self.file_path, id_suffix, name_suffix, **invalid_suffix ) if self.handle_error(error_message, error_code, file_path=self.file_path): return False diff --git a/demisto_sdk/commands/common/hook_validations/modeling_rule.py b/demisto_sdk/commands/common/hook_validations/modeling_rule.py index 7589922be9..15633c1c38 100644 --- a/demisto_sdk/commands/common/hook_validations/modeling_rule.py +++ b/demisto_sdk/commands/common/hook_validations/modeling_rule.py @@ -7,7 +7,9 @@ from typing import List from demisto_sdk.commands.common.constants import ( + ASSETS_MODELING_RULE, MODELING_RULE, + FileType, ) from demisto_sdk.commands.common.errors import Errors from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json @@ -37,7 +39,18 @@ def __init__( ignored_errors=ignored_errors, json_file_path=json_file_path, ) - self._is_valid = self.is_valid_rule_suffix(MODELING_RULE) + rule_type = ( + MODELING_RULE + if structure_validator.file_type + in [ + FileType.MODELING_RULE, + FileType.MODELING_RULE_SCHEMA, + FileType.MODELING_RULE_XIF, + FileType.MODELING_RULE_TEST_DATA, + ] + else ASSETS_MODELING_RULE + ) + self._is_valid = self.is_valid_rule_suffix(rule_type) self.schema_path = None self.schema_content = None self.xif_path = None diff --git a/demisto_sdk/commands/content_graph/parsers/assets_modeling_rule.py b/demisto_sdk/commands/content_graph/parsers/assets_modeling_rule.py index 8a5f0571d0..706315baf8 100644 --- a/demisto_sdk/commands/content_graph/parsers/assets_modeling_rule.py +++ b/demisto_sdk/commands/content_graph/parsers/assets_modeling_rule.py @@ -5,4 +5,6 @@ class AssetsModelingRuleParser( ModelingRuleParser, content_type=ContentType.ASSETS_MODELING_RULE ): - pass + @property + def description(self) -> str: + return "Collect assets and vulnerabilities"