forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_packs_util.py
More file actions
101 lines (80 loc) · 3.36 KB
/
content_packs_util.py
File metadata and controls
101 lines (80 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import json
import os
from typing import Tuple
from demisto_sdk.commands.common.constants import (PACK_METADATA_SUPPORT, PACKS_DIR, PACKS_PACK_META_FILE_NAME)
SKIPPED_PACKS = ['DeprecatedContent', 'NonSupported']
IGNORED_FILES = ['__init__.py', 'ApiModules', 'NonSupported'] # files to ignore inside Packs folder
def get_pack_metadata(file_path: str) -> dict:
"""
Args:
file_path: The Pack metadata file path
Returns:
dict: The pack metadata file content
"""
with open(file_path) as pack_metadata:
return json.load(pack_metadata)
def is_pack_xsoar_supported(pack_path: str) -> bool:
"""Checks whether the pack is XSOAR supported.
Tests are not being collected for non XSOAR packs.
Args:
pack_path (str): The pack path
Returns:
True if the pack is certified, False otherwise
"""
pack_metadata_path = os.path.join(pack_path, PACKS_PACK_META_FILE_NAME)
if not os.path.isfile(pack_metadata_path):
return False
pack_metadata = get_pack_metadata(pack_metadata_path)
return pack_metadata.get(PACK_METADATA_SUPPORT, '').lower() == "xsoar"
def is_pack_deprecated(pack_path: str) -> bool:
"""Checks whether the pack is deprecated.
Tests are not being collected for deprecated packs and the pack is not installed in the build process.
Args:
pack_path (str): The pack path
Returns:
True if the pack is deprecated, False otherwise
"""
pack_metadata_path = os.path.join(pack_path, PACKS_PACK_META_FILE_NAME)
if not os.path.isfile(pack_metadata_path):
return True
pack_metadata = get_pack_metadata(pack_metadata_path)
return pack_metadata.get('hidden', False)
def should_test_content_pack(pack_name: str) -> Tuple[bool, str]:
"""Checks if content pack should be tested in the build:
- Content pack is not in skipped packs
- Content pack is certified
- Content pack is not deprecated
Args:
pack_name (str): The pack name to check if it should be tested
Returns:
bool: True if should be tested, False otherwise
"""
if not pack_name:
return False, 'Invalid pack name'
pack_path = os.path.join(PACKS_DIR, pack_name)
if pack_name in SKIPPED_PACKS:
return False, 'Pack is either the "NonSupported" pack or the "DeprecatedContent" pack.'
if not is_pack_xsoar_supported(pack_path):
return False, 'Pack is not XSOAR supported'
if is_pack_deprecated(pack_path):
return False, 'Pack is Deprecated'
return True, ''
def should_install_content_pack(pack_name: str) -> Tuple[bool, str]:
"""Checks if content pack should be installed:
- Content pack is not in skipped packs
- Content pack is not deprecated
Args:
pack_name (str): The pack name to check if it should be tested
Returns:
bool: True if should be installed, False otherwise
"""
if not pack_name:
return False, 'Invalid pack name'
pack_path = os.path.join(PACKS_DIR, pack_name)
if pack_name in SKIPPED_PACKS:
return False, 'Pack is either the "NonSupported" pack or the "DeprecatedContent" pack.'
if pack_name in IGNORED_FILES:
return False, f'Pack should be ignored as it one of the files to ignore: {IGNORED_FILES}'
if is_pack_deprecated(pack_path):
return False, 'Pack is Deprecated'
return True, ''