Skip to content

Commit

Permalink
support asset collection (#4005)
Browse files Browse the repository at this point in the history
* fixes for displaying items

* removed sorting keys

* added logs and reveerted changes

* fixed validating rules
  • Loading branch information
merit-maita committed Feb 28, 2024
1 parent edfeb01 commit b3b8fd6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .changelog/4005.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added description field to *Assets Modeling Rules* content item.
type: internal
pr_number: 4005
1 change: 1 addition & 0 deletions demisto_sdk/commands/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 6 additions & 10 deletions demisto_sdk/commands/common/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion demisto_sdk/commands/common/hook_validations/modeling_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
class AssetsModelingRuleParser(
ModelingRuleParser, content_type=ContentType.ASSETS_MODELING_RULE
):
pass
@property
def description(self) -> str:
return "Collect assets and vulnerabilities"

0 comments on commit b3b8fd6

Please sign in to comment.