Skip to content

Commit

Permalink
fixed a bug where validate did not work with pre processing rules (#3977
Browse files Browse the repository at this point in the history
)

* fixed a bug where validate did not work with pre processing rules

* added doc

* added the schema of pre-processing rules

* Update .changelog/3977.yml

Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com>

* added test module

* fixed changelog test

---------

Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com>
  • Loading branch information
merit-maita and dorschw committed Jan 28, 2024
1 parent 3ffd770 commit 9679334
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .changelog/3977.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed an issue where the ***validate*** command failed on pre-processing rules.
type: fix
pr_number: 3977
14 changes: 7 additions & 7 deletions demisto_sdk/commands/common/schemas/pre-process-rule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ mapping:
type: str
required: true
period:
type: seq
sequence:
- include: period_schema
type: map
mapping:
by:
type: str
fromValue:
type: number
readyExistingEventsFilters:
type: seq
sequence:
Expand All @@ -54,7 +57,7 @@ mapping:
sequence:
- include: readyNewEventFilters_schema
scriptName:
type: number
type: str
required: true
searchClosed:
type: bool
Expand Down Expand Up @@ -95,9 +98,6 @@ schema;existingEventsFilters_schema:
schema;newEventFilters_schema:
type: any

schema;period_schema:
type: any

schema;readyExistingEventsFilters_schema:
type: any

Expand Down
2 changes: 2 additions & 0 deletions demisto_sdk/commands/common/tests/tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
VALID_LIST_PATH,
VALID_MD,
VALID_PLAYBOOK_ID_PATH,
VALID_PRE_PROCESSING_RULE_PATH,
VALID_REPUTATION_FILE,
VALID_SCRIPT_PATH,
VALID_WIDGET_PATH,
Expand Down Expand Up @@ -347,6 +348,7 @@ def test_get_dict_from_file(self, path, raises_error, _type):
(METADATA_FILE_NAME, FileType.METADATA),
("", None),
(VULTURE_WHITELIST_PATH, FileType.VULTURE_WHITELIST),
(VALID_PRE_PROCESSING_RULE_PATH, FileType.PRE_PROCESS_RULES),
]

@pytest.mark.parametrize("path, _type", data_test_find_type)
Expand Down
2 changes: 2 additions & 0 deletions demisto_sdk/commands/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,8 @@ def find_type_by_path(path: Union[str, Path] = "") -> Optional[FileType]:
return FileType.MODELING_RULE_SCHEMA
elif LAYOUT_RULES_DIR in path.parts:
return FileType.LAYOUT_RULE
elif PRE_PROCESS_RULES_DIR in path.parts:
return FileType.PRE_PROCESS_RULES

elif (path.stem.endswith("_image") and path.suffix == ".png") or (
(path.stem.endswith("_dark") or path.stem.endswith("_light"))
Expand Down
2 changes: 1 addition & 1 deletion demisto_sdk/scripts/changelog/tests/changelog_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_get_all_logs(changelog_folder_mock: Path):
yaml.dump(LOG_FILE_2, f)
log_files = read_log_files()
assert len(log_files) == 2
assert len(log_files[0].changes) == 2
assert len(log_files[0].changes) + len(log_files[1].changes) == 3


@pytest.mark.parametrize("pr_name", [DUMMY_PR_NAME, ""])
Expand Down
3 changes: 3 additions & 0 deletions demisto_sdk/tests/constants_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
INVALID_MULTI_LINE_2_CHANGELOG_PATH = (
f"{GIT_ROOT}/demisto_sdk/tests/test_files/invalid-multi-line_2_CHANGELOG.md"
)
VALID_PRE_PROCESSING_RULE_PATH = (
f"{GIT_ROOT}/demisto_sdk/tests/test_files/preprocessrule-test_rule.json"
)
PACK_TARGET = "Packs/TestPack"
LAYOUT_TARGET = f"{PACK_TARGET}/Layouts/layout-mock.json"
LAYOUTS_CONTAINER_TARGET = f"{PACK_TARGET}/Layouts/layoutscontainer-mock.json"
Expand Down
67 changes: 67 additions & 0 deletions demisto_sdk/tests/test_files/preprocessrule-test_rule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"action": "drop",
"cacheVersn": 0,
"definitionId": "",
"enabled": true,
"existingEventsFilters": [],
"fromServerVersion": "",
"id": "test rule",
"index": 0,
"itemVersion": "",
"linkTo": "oldest",
"locked": false,
"name": "test rule",
"newEventFilters": [
[
{
"left": {
"isContext": true,
"value": {
"simple": "accountid"
}
},
"operator": "isEqualString",
"right": {
"isContext": false,
"value": {
"simple": "t"
}
},
"type": "shortText"
}
]
],
"packID": "",
"packName": "",
"period": {
"by": "days",
"fromValue": 30
},
"readyExistingEventsFilters": [],
"readyNewEventFilters": [
[
{
"left": {
"isContext": true,
"value": {
"simple": "accountid"
}
},
"operator": "isEqualString",
"right": {
"isContext": false,
"value": {
"simple": "t"
}
},
"type": "shortText"
}
]
],
"scriptID": "",
"scriptName": "",
"searchClosed": false,
"system": false,
"toServerVersion": "",
"version": -1
}

0 comments on commit 9679334

Please sign in to comment.