fosslight-util 1.4.48__py3-none-any.whl → 2.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fosslight_util/compare_yaml.py +18 -11
- fosslight_util/constant.py +11 -0
- fosslight_util/convert_excel_to_yaml.py +1 -1
- fosslight_util/correct.py +47 -91
- fosslight_util/help.py +3 -4
- fosslight_util/oss_item.py +150 -155
- fosslight_util/output_format.py +88 -12
- fosslight_util/parsing_yaml.py +45 -30
- fosslight_util/read_excel.py +29 -35
- fosslight_util/set_log.py +20 -3
- fosslight_util/spdx_licenses.py +2 -1
- fosslight_util/write_excel.py +88 -156
- fosslight_util/write_opossum.py +14 -20
- fosslight_util/write_scancodejson.py +31 -31
- fosslight_util/write_spdx.py +147 -115
- fosslight_util/write_txt.py +2 -1
- fosslight_util/write_yaml.py +43 -54
- {fosslight_util-1.4.48.dist-info → fosslight_util-2.0.1.dist-info}/METADATA +7 -8
- fosslight_util-2.0.1.dist-info/RECORD +31 -0
- {fosslight_util-1.4.48.dist-info → fosslight_util-2.0.1.dist-info}/WHEEL +1 -1
- fosslight_util-1.4.48.dist-info/RECORD +0 -31
- {fosslight_util-1.4.48.dist-info → fosslight_util-2.0.1.dist-info}/LICENSE +0 -0
- {fosslight_util-1.4.48.dist-info → fosslight_util-2.0.1.dist-info}/entry_points.txt +0 -0
- {fosslight_util-1.4.48.dist-info → fosslight_util-2.0.1.dist-info}/top_level.txt +0 -0
fosslight_util/compare_yaml.py
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
|
-
import os
|
|
8
7
|
from fosslight_util.constant import LOGGER_NAME
|
|
9
|
-
from fosslight_util.parsing_yaml import parsing_yml
|
|
10
8
|
|
|
11
9
|
logger = logging.getLogger(LOGGER_NAME)
|
|
12
10
|
VERSION = 'version'
|
|
@@ -14,12 +12,16 @@ LICENSE = 'license'
|
|
|
14
12
|
NAME = 'name'
|
|
15
13
|
|
|
16
14
|
|
|
17
|
-
def compare_yaml(
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
def compare_yaml(before_fileitems, after_fileitems):
|
|
16
|
+
bf_raw = []
|
|
17
|
+
af_raw = []
|
|
18
|
+
for bf in before_fileitems:
|
|
19
|
+
bf_raw.extend(bf.get_print_json())
|
|
20
|
+
for af in after_fileitems:
|
|
21
|
+
af_raw.extend(af.get_print_json())
|
|
20
22
|
|
|
21
|
-
before_items = get_merged_item(
|
|
22
|
-
after_items = get_merged_item(
|
|
23
|
+
before_items = get_merged_item(bf_raw)
|
|
24
|
+
after_items = get_merged_item(af_raw)
|
|
23
25
|
|
|
24
26
|
new_before = []
|
|
25
27
|
for bi in before_items:
|
|
@@ -72,13 +74,18 @@ def compare_yaml(before_file, after_file):
|
|
|
72
74
|
def get_merged_item(oss_items):
|
|
73
75
|
item_list = []
|
|
74
76
|
for oi in oss_items:
|
|
75
|
-
if oi.exclude:
|
|
77
|
+
if oi.get("exclude", None):
|
|
76
78
|
continue
|
|
77
|
-
|
|
79
|
+
oi_name = oi.get("name", '')
|
|
80
|
+
oi_version = oi.get("version", '')
|
|
81
|
+
oi_license = oi.get("license", '')
|
|
82
|
+
if not (oi_name and oi_version and oi_license):
|
|
83
|
+
continue
|
|
84
|
+
item_info = {NAME: oi_name, VERSION: oi_version, LICENSE: oi_license}
|
|
78
85
|
|
|
79
|
-
filtered = next(filter(lambda oss_dict: oss_dict[NAME] ==
|
|
86
|
+
filtered = next(filter(lambda oss_dict: oss_dict[NAME] == oi_name and oss_dict[VERSION] == oi_version, item_list), None)
|
|
80
87
|
if filtered:
|
|
81
|
-
filtered[LICENSE].extend(
|
|
88
|
+
filtered[LICENSE].extend(oi_license)
|
|
82
89
|
filtered[LICENSE] = list(set(filtered[LICENSE]))
|
|
83
90
|
else:
|
|
84
91
|
item_list.append(item_info)
|
fosslight_util/constant.py
CHANGED
|
@@ -15,6 +15,17 @@ supported_sheet_and_scanner = {'SRC': FL_SOURCE,
|
|
|
15
15
|
f'BIN_{FL_BINARY}': FL_BINARY,
|
|
16
16
|
f'DEP_{FL_DEPENDENCY}': FL_DEPENDENCY}
|
|
17
17
|
|
|
18
|
+
FOSSLIGHT_SCANNER = 'fosslight_scanner'
|
|
19
|
+
FOSSLIGHT_SOURCE = 'fosslight_source'
|
|
20
|
+
FOSSLIGHT_DEPENDENCY = 'fosslight_dependency'
|
|
21
|
+
FOSSLIGHT_BINARY = 'fosslight_binary'
|
|
22
|
+
|
|
23
|
+
SHEET_NAME_FOR_SCANNER = {
|
|
24
|
+
FOSSLIGHT_SOURCE: 'SRC_FL_Source',
|
|
25
|
+
FOSSLIGHT_BINARY: 'BIN_FL_Binary',
|
|
26
|
+
FOSSLIGHT_DEPENDENCY: 'DEP_FL_Dependency'
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
# Github : https://github.com/(owner)/(repo)
|
|
19
30
|
# npm : https://www.npmjs.com/package/(package)/v/(version)
|
|
20
31
|
# npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
|
|
@@ -33,7 +33,7 @@ def find_report_file(path_to_find):
|
|
|
33
33
|
return ""
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def convert_excel_to_yaml(oss_report_to_read, output_file, sheet_names=""):
|
|
36
|
+
def convert_excel_to_yaml(oss_report_to_read: str, output_file: str, sheet_names: str = "") -> None:
|
|
37
37
|
_file_extension = ".yaml"
|
|
38
38
|
yaml_dict = {}
|
|
39
39
|
|
fosslight_util/correct.py
CHANGED
|
@@ -7,19 +7,16 @@ import logging
|
|
|
7
7
|
import os
|
|
8
8
|
import copy
|
|
9
9
|
import re
|
|
10
|
-
from fosslight_util.constant import LOGGER_NAME
|
|
10
|
+
from fosslight_util.constant import LOGGER_NAME, FOSSLIGHT_SOURCE
|
|
11
11
|
from fosslight_util.parsing_yaml import parsing_yml
|
|
12
|
-
import fosslight_util.constant as constant
|
|
13
|
-
from fosslight_util.oss_item import OssItem
|
|
14
12
|
|
|
15
13
|
logger = logging.getLogger(LOGGER_NAME)
|
|
16
14
|
SBOM_INFO_YAML = r"sbom(-|_)info[\s\S]*.ya?ml"
|
|
17
15
|
|
|
18
16
|
|
|
19
|
-
def correct_with_yaml(correct_filepath, path_to_scan,
|
|
17
|
+
def correct_with_yaml(correct_filepath, path_to_scan, scan_item):
|
|
20
18
|
success = True
|
|
21
19
|
msg = ""
|
|
22
|
-
correct_list = {}
|
|
23
20
|
correct_yaml = ""
|
|
24
21
|
if correct_filepath == "":
|
|
25
22
|
correct_filepath = path_to_scan
|
|
@@ -33,101 +30,60 @@ def correct_with_yaml(correct_filepath, path_to_scan, scanner_oss_list):
|
|
|
33
30
|
if not correct_yaml:
|
|
34
31
|
msg = f"Cannot find sbom-info.yaml in {correct_filepath}."
|
|
35
32
|
success = False
|
|
36
|
-
return success, msg,
|
|
33
|
+
return success, msg, scan_item
|
|
37
34
|
|
|
38
35
|
rel_path = os.path.relpath(path_to_scan, correct_filepath)
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
yaml_file_list, _, err_msg = parsing_yml(correct_yaml, os.path.dirname(correct_yaml), print_log=True)
|
|
42
38
|
find_match = False
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
for idx, oss_raw_item in enumerate(sheet_contents):
|
|
54
|
-
if len(oss_raw_item) < 9:
|
|
55
|
-
logger.warning(f"sheet list is too short ({len(oss_raw_item)}): {oss_raw_item}")
|
|
39
|
+
for scanner_name, _ in scan_item.file_items.items():
|
|
40
|
+
correct_fileitems = []
|
|
41
|
+
exclude_fileitems = []
|
|
42
|
+
for yaml_file_item in yaml_file_list:
|
|
43
|
+
yaml_path_exists = False
|
|
44
|
+
if yaml_file_item.source_name_or_path == '':
|
|
45
|
+
if scanner_name == FOSSLIGHT_SOURCE:
|
|
46
|
+
correct_item = copy.deepcopy(yaml_file_item)
|
|
47
|
+
correct_item.comment = 'Added by sbom-info.yaml'
|
|
48
|
+
correct_fileitems.append(correct_item)
|
|
56
49
|
continue
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
for idx, scan_file_item in enumerate(scan_item.file_items[scanner_name]):
|
|
51
|
+
oss_rel_path = os.path.normpath(os.path.join(rel_path, scan_file_item.source_name_or_path))
|
|
52
|
+
yi_path = yaml_file_item.source_name_or_path
|
|
53
|
+
if ((os.path.normpath(yi_path) == os.path.normpath(oss_rel_path)) or
|
|
54
|
+
((os.path.normpath(oss_rel_path).startswith(os.path.normpath(yi_path.rstrip('*')))))):
|
|
55
|
+
correct_item = copy.deepcopy(scan_file_item)
|
|
56
|
+
correct_item.exclude = yaml_file_item.exclude
|
|
57
|
+
correct_item.oss_items = copy.deepcopy(yaml_file_item.oss_items)
|
|
58
|
+
correct_item.comment = ''
|
|
59
|
+
correct_item.comment = 'Loaded from sbom-info.yaml'
|
|
60
|
+
correct_fileitems.append(correct_item)
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
oss_rel_path = os.path.normpath(os.path.join(rel_path, oss_item.source_name_or_path[0]))
|
|
63
|
-
for y_idx, yi in enumerate(yaml_oss_list):
|
|
64
|
-
if not yi.source_name_or_path:
|
|
65
|
-
continue
|
|
66
|
-
for ys_idx, yi_path in enumerate(yi.source_name_or_path):
|
|
67
|
-
yi_item = copy.deepcopy(yi)
|
|
68
|
-
if ((os.path.normpath(yi_path) == os.path.normpath(oss_rel_path)) or
|
|
69
|
-
((os.path.normpath(oss_rel_path).startswith(os.path.normpath(yi_path.rstrip('*')))))):
|
|
70
|
-
find_match = True
|
|
71
|
-
yi_item.source_name_or_path = []
|
|
72
|
-
yi_item.source_name_or_path = oss_item.source_name_or_path[0]
|
|
73
|
-
matched_source_path_with_sbom.append(oss_item.source_name_or_path[0])
|
|
74
|
-
matched_yi.append(yi_item)
|
|
75
|
-
matched_yaml[y_idx][ys_idx] = 1
|
|
76
|
-
if len(matched_yi) > 0:
|
|
77
|
-
for matched_yi_item in matched_yi:
|
|
78
|
-
matched_oss_item = copy.deepcopy(matched_yi_item)
|
|
79
|
-
if matched_oss_item.comment:
|
|
80
|
-
matched_oss_item.comment += '/'
|
|
81
|
-
matched_oss_item.comment += 'Loaded from sbom-info.yaml'
|
|
82
|
-
if sheet_name == 'BIN_FL_Binary':
|
|
83
|
-
matched_oss_item.bin_vulnerability = oss_item.bin_vulnerability
|
|
84
|
-
matched_oss_item.bin_tlsh = oss_item.bin_tlsh
|
|
85
|
-
matched_oss_item.bin_sha1 = oss_item.bin_sha1
|
|
86
|
-
matched_oss_array = matched_oss_item.get_print_array(scanner_name)[0]
|
|
87
|
-
correct_contents.append(matched_oss_array)
|
|
88
|
-
oss_item.exclude = True
|
|
89
|
-
if oss_item.comment:
|
|
90
|
-
oss_item.comment += '/'
|
|
91
|
-
oss_item.comment += 'Excluded by sbom-info.yaml'
|
|
92
|
-
correct_contents[idx] = oss_item.get_print_array(scanner_name)[0]
|
|
93
|
-
else:
|
|
94
|
-
oss_item.exclude = True
|
|
95
|
-
if oss_item.comment:
|
|
96
|
-
oss_item.comment += '/'
|
|
97
|
-
oss_item.comment += 'Excluded by sbom-info.yaml'
|
|
98
|
-
correct_contents[idx] = oss_item.get_print_array(scanner_name)[0]
|
|
62
|
+
yaml_path_exists = True
|
|
63
|
+
exclude_fileitems.append(idx)
|
|
99
64
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
continue
|
|
119
|
-
for y_path in y_item.source_name_or_path:
|
|
120
|
-
y_item_i = copy.deepcopy(y_item)
|
|
121
|
-
if not os.path.exists(os.path.normpath(os.path.join(correct_filepath, y_path))):
|
|
122
|
-
y_item_i.exclude = True
|
|
123
|
-
y_item_i.source_name_or_path = []
|
|
124
|
-
y_item_i.source_name_or_path = y_path
|
|
125
|
-
correct_contents.append(y_item_i.get_print_array()[0])
|
|
126
|
-
correct_list[sheet_name] = correct_contents
|
|
65
|
+
if not yaml_path_exists:
|
|
66
|
+
correct_item = copy.deepcopy(yaml_file_item)
|
|
67
|
+
if os.path.exists(os.path.normpath(yaml_file_item.source_name_or_path)):
|
|
68
|
+
correct_item.comment = 'Loaded from sbom-info.yaml'
|
|
69
|
+
correct_fileitems.append(correct_item)
|
|
70
|
+
else:
|
|
71
|
+
if scanner_name == FOSSLIGHT_SOURCE:
|
|
72
|
+
correct_item.exclude = True
|
|
73
|
+
correct_item.comment = 'Added by sbom-info.yaml'
|
|
74
|
+
correct_fileitems.append(correct_item)
|
|
75
|
+
if correct_fileitems:
|
|
76
|
+
scan_item.append_file_items(correct_fileitems, scanner_name)
|
|
77
|
+
find_match = True
|
|
78
|
+
if exclude_fileitems:
|
|
79
|
+
exclude_fileitems = list(set(exclude_fileitems))
|
|
80
|
+
for e_idx in exclude_fileitems:
|
|
81
|
+
scan_item.file_items[scanner_name][e_idx].exclude = True
|
|
82
|
+
scan_item.file_items[scanner_name][e_idx].comment = 'Excluded by sbom-info.yaml'
|
|
127
83
|
|
|
128
84
|
if not find_match:
|
|
129
85
|
success = False
|
|
130
86
|
err_msg = 'No match items in sbom-info.yaml'
|
|
131
|
-
return success, err_msg,
|
|
87
|
+
return success, err_msg, scan_item
|
|
132
88
|
|
|
133
|
-
return success, msg,
|
|
89
|
+
return success, msg, scan_item
|
fosslight_util/help.py
CHANGED
|
@@ -35,12 +35,11 @@ _HELP_MESSAGE_DOWNLOAD = """
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
class PrintHelpMsg():
|
|
38
|
-
message_suffix = ""
|
|
39
38
|
|
|
40
|
-
def __init__(self, value):
|
|
39
|
+
def __init__(self, value: str = ""):
|
|
41
40
|
self.message_suffix = value
|
|
42
41
|
|
|
43
|
-
def print_help_msg(self, exitopt):
|
|
42
|
+
def print_help_msg(self, exitopt: bool) -> None:
|
|
44
43
|
print(_HELP_MESSAGE_COMMON)
|
|
45
44
|
print(self.message_suffix)
|
|
46
45
|
|
|
@@ -48,7 +47,7 @@ class PrintHelpMsg():
|
|
|
48
47
|
sys.exit()
|
|
49
48
|
|
|
50
49
|
|
|
51
|
-
def print_package_version(pkg_name, msg="", exitopt=True):
|
|
50
|
+
def print_package_version(pkg_name: str, msg: str = "", exitopt: bool = True) -> str:
|
|
52
51
|
if msg == "":
|
|
53
52
|
msg = f"{pkg_name} Version:"
|
|
54
53
|
cur_version = pkg_resources.get_distribution(pkg_name).version
|
fosslight_util/oss_item.py
CHANGED
|
@@ -5,46 +5,42 @@
|
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
|
-
from fosslight_util.constant import LOGGER_NAME,
|
|
8
|
+
from fosslight_util.constant import LOGGER_NAME, FOSSLIGHT_SCANNER
|
|
9
|
+
from fosslight_util.cover import CoverItem
|
|
10
|
+
from typing import List, Dict
|
|
9
11
|
|
|
10
12
|
_logger = logging.getLogger(LOGGER_NAME)
|
|
13
|
+
CHECKSUM_NULL = "0"
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
class OssItem:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
self.
|
|
17
|
+
|
|
18
|
+
def __init__(self, name="", version="", license="", dl_url=""):
|
|
19
|
+
self.name = name
|
|
20
|
+
self.version = version
|
|
17
21
|
self._license = []
|
|
18
|
-
self.
|
|
22
|
+
self.license = license
|
|
23
|
+
self.download_location = dl_url
|
|
24
|
+
self.exclude = False
|
|
19
25
|
self.comment = ""
|
|
20
|
-
self._exclude = False
|
|
21
26
|
self.homepage = ""
|
|
22
|
-
self.
|
|
23
|
-
self._source_name_or_path = []
|
|
24
|
-
self.download_location = ""
|
|
25
|
-
self._yocto_recipe = []
|
|
26
|
-
self._yocto_package = []
|
|
27
|
-
self.is_binary = False
|
|
28
|
-
self._depends_on = []
|
|
29
|
-
self.purl = ""
|
|
30
|
-
self.bin_vulnerability = ""
|
|
31
|
-
self.bin_tlsh = ""
|
|
32
|
-
self.bin_sha1 = ""
|
|
27
|
+
self._copyright = ""
|
|
33
28
|
|
|
34
29
|
def __del__(self):
|
|
35
30
|
pass
|
|
36
31
|
|
|
37
32
|
@property
|
|
38
|
-
def
|
|
39
|
-
return self.
|
|
33
|
+
def license(self):
|
|
34
|
+
return self._license
|
|
40
35
|
|
|
41
|
-
@
|
|
42
|
-
def
|
|
36
|
+
@license.setter
|
|
37
|
+
def license(self, value):
|
|
43
38
|
if value != "":
|
|
44
|
-
if isinstance(value, list):
|
|
45
|
-
value = "
|
|
46
|
-
|
|
47
|
-
self.
|
|
39
|
+
if not isinstance(value, list):
|
|
40
|
+
value = value.split(",")
|
|
41
|
+
self._license.extend(value)
|
|
42
|
+
self._license = [item.strip() for item in self._license]
|
|
43
|
+
self._license = list(set(self._license))
|
|
48
44
|
|
|
49
45
|
@property
|
|
50
46
|
def exclude(self):
|
|
@@ -58,13 +54,16 @@ class OssItem:
|
|
|
58
54
|
self._exclude = False
|
|
59
55
|
|
|
60
56
|
@property
|
|
61
|
-
def
|
|
62
|
-
return self.
|
|
57
|
+
def copyright(self):
|
|
58
|
+
return self._copyright
|
|
63
59
|
|
|
64
|
-
@
|
|
65
|
-
def
|
|
60
|
+
@copyright.setter
|
|
61
|
+
def copyright(self, value):
|
|
66
62
|
if value != "":
|
|
67
|
-
|
|
63
|
+
if isinstance(value, list):
|
|
64
|
+
value = "\n".join(value)
|
|
65
|
+
value = value.strip()
|
|
66
|
+
self._copyright = value
|
|
68
67
|
|
|
69
68
|
@property
|
|
70
69
|
def version(self):
|
|
@@ -78,149 +77,145 @@ class OssItem:
|
|
|
78
77
|
self._version = ""
|
|
79
78
|
|
|
80
79
|
@property
|
|
81
|
-
def
|
|
82
|
-
return self.
|
|
83
|
-
|
|
84
|
-
@license.setter
|
|
85
|
-
def license(self, value):
|
|
86
|
-
if not isinstance(value, list):
|
|
87
|
-
value = value.split(",")
|
|
88
|
-
self._license.extend(value)
|
|
89
|
-
self._license = [item.strip() for item in self._license]
|
|
90
|
-
self._license = list(set(self._license))
|
|
91
|
-
|
|
92
|
-
@property
|
|
93
|
-
def source_name_or_path(self):
|
|
94
|
-
return self._source_name_or_path
|
|
80
|
+
def comment(self):
|
|
81
|
+
return self._comment
|
|
95
82
|
|
|
96
|
-
@
|
|
97
|
-
def
|
|
83
|
+
@comment.setter
|
|
84
|
+
def comment(self, value):
|
|
98
85
|
if not value:
|
|
99
|
-
self.
|
|
86
|
+
self._comment = ""
|
|
100
87
|
else:
|
|
101
|
-
if
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
self._source_name_or_path = list(set(self._source_name_or_path))
|
|
88
|
+
if self._comment:
|
|
89
|
+
self._comment = f"{self._comment} / {value}"
|
|
90
|
+
else:
|
|
91
|
+
self._comment = value
|
|
106
92
|
|
|
107
|
-
@property
|
|
108
|
-
def yocto_recipe(self):
|
|
109
|
-
return self._yocto_recipe
|
|
110
93
|
|
|
111
|
-
|
|
112
|
-
def
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
self.
|
|
116
|
-
self.
|
|
117
|
-
self.
|
|
94
|
+
class FileItem:
|
|
95
|
+
def __init__(self, value):
|
|
96
|
+
self.relative_path = value
|
|
97
|
+
self.source_name_or_path = ""
|
|
98
|
+
self._exclude = False
|
|
99
|
+
self._comment = ""
|
|
100
|
+
self.is_binary = False
|
|
101
|
+
self.oss_items: List[OssItem] = []
|
|
102
|
+
self.checksum = CHECKSUM_NULL
|
|
103
|
+
|
|
104
|
+
def __del__(self):
|
|
105
|
+
pass
|
|
118
106
|
|
|
119
107
|
@property
|
|
120
|
-
def
|
|
121
|
-
return self.
|
|
108
|
+
def exclude(self):
|
|
109
|
+
return self._exclude
|
|
122
110
|
|
|
123
|
-
@
|
|
124
|
-
def
|
|
125
|
-
if
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
111
|
+
@exclude.setter
|
|
112
|
+
def exclude(self, value):
|
|
113
|
+
if value:
|
|
114
|
+
self._exclude = True
|
|
115
|
+
else:
|
|
116
|
+
self._exclude = False
|
|
117
|
+
for oss in self.oss_items:
|
|
118
|
+
oss.exclude = value
|
|
130
119
|
|
|
131
120
|
@property
|
|
132
|
-
def
|
|
133
|
-
return self.
|
|
121
|
+
def comment(self):
|
|
122
|
+
return self._comment
|
|
134
123
|
|
|
135
|
-
@
|
|
136
|
-
def
|
|
124
|
+
@comment.setter
|
|
125
|
+
def comment(self, value):
|
|
137
126
|
if not value:
|
|
138
|
-
self.
|
|
139
|
-
else:
|
|
140
|
-
if not isinstance(value, list):
|
|
141
|
-
value = value.split(",")
|
|
142
|
-
self._depends_on.extend(value)
|
|
143
|
-
self._depends_on = [item.strip() for item in self._depends_on]
|
|
144
|
-
self._depends_on = list(set(self._depends_on))
|
|
145
|
-
|
|
146
|
-
def set_sheet_item(self, item, scanner_name=''):
|
|
147
|
-
if len(item) < 9:
|
|
148
|
-
_logger.warning(f"sheet list is too short ({len(item)}): {item}")
|
|
149
|
-
return
|
|
150
|
-
if scanner_name == FL_DEPENDENCY:
|
|
151
|
-
self.purl = item[0]
|
|
127
|
+
self._comment = ""
|
|
152
128
|
else:
|
|
153
|
-
self.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
self.comment = item[8]
|
|
162
|
-
|
|
163
|
-
if len(item) >= 10 and scanner_name == FL_DEPENDENCY:
|
|
164
|
-
self.depends_on = item[9]
|
|
165
|
-
if len(item) >= 10 and scanner_name == FL_BINARY:
|
|
166
|
-
self.bin_vulnerability = item[9]
|
|
167
|
-
if len(item) >= 12:
|
|
168
|
-
self.bin_tlsh = item[10]
|
|
169
|
-
self.bin_sha1 = item[11]
|
|
170
|
-
|
|
171
|
-
def get_print_array(self, scanner_name=''):
|
|
129
|
+
if self._comment:
|
|
130
|
+
self._comment = f"{self._comment} / {value}"
|
|
131
|
+
else:
|
|
132
|
+
self._comment = value
|
|
133
|
+
for oss in self.oss_items:
|
|
134
|
+
oss.comment = value
|
|
135
|
+
|
|
136
|
+
def get_print_array(self):
|
|
172
137
|
items = []
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if scanner_name == FL_DEPENDENCY:
|
|
182
|
-
items = [self.purl, self.name, self.version, lic,
|
|
183
|
-
self.download_location, self.homepage, self.copyright, exclude, self.comment]
|
|
184
|
-
if len(self.depends_on) > 0:
|
|
185
|
-
items.append(",".join(self.depends_on))
|
|
186
|
-
else:
|
|
187
|
-
for source_name_or_path in self.source_name_or_path:
|
|
188
|
-
if scanner_name == FL_BINARY:
|
|
189
|
-
oss_item = [os.path.join(self.relative_path, source_name_or_path), self.name, self.version, lic,
|
|
190
|
-
self.download_location, self.homepage, self.copyright, exclude, self.comment,
|
|
191
|
-
self.bin_vulnerability, self.bin_tlsh, self.bin_sha1]
|
|
192
|
-
else:
|
|
193
|
-
oss_item = [os.path.join(self.relative_path, source_name_or_path), self.name, self.version, lic,
|
|
194
|
-
self.download_location, self.homepage, self.copyright, exclude, self.comment]
|
|
195
|
-
items.append(oss_item)
|
|
138
|
+
|
|
139
|
+
for oss in self.oss_items:
|
|
140
|
+
exclude = "Exclude" if self.exclude or oss.exclude else ""
|
|
141
|
+
lic = ",".join(oss.license)
|
|
142
|
+
|
|
143
|
+
oss_item = [os.path.join(self.relative_path, self.source_name_or_path), oss.name, oss.version, lic,
|
|
144
|
+
oss.download_location, oss.homepage, oss.copyright, exclude, oss.comment]
|
|
145
|
+
items.append(oss_item)
|
|
196
146
|
return items
|
|
197
147
|
|
|
198
148
|
def get_print_json(self):
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
json_item["
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
json_item
|
|
221
|
-
|
|
222
|
-
return json_item
|
|
149
|
+
items = []
|
|
150
|
+
|
|
151
|
+
for oss in self.oss_items:
|
|
152
|
+
json_item = {}
|
|
153
|
+
json_item["name"] = oss.name
|
|
154
|
+
json_item["version"] = oss.version
|
|
155
|
+
|
|
156
|
+
if self.source_name_or_path != "":
|
|
157
|
+
json_item["source path"] = self.source_name_or_path
|
|
158
|
+
if len(oss.license) > 0:
|
|
159
|
+
json_item["license"] = oss.license
|
|
160
|
+
if oss.download_location != "":
|
|
161
|
+
json_item["download location"] = oss.download_location
|
|
162
|
+
if oss.homepage != "":
|
|
163
|
+
json_item["homepage"] = oss.homepage
|
|
164
|
+
if oss.copyright != "":
|
|
165
|
+
json_item["copyright text"] = oss.copyright
|
|
166
|
+
if self.exclude or oss.exclude:
|
|
167
|
+
json_item["exclude"] = True
|
|
168
|
+
if oss.comment != "":
|
|
169
|
+
json_item["comment"] = oss.comment
|
|
170
|
+
items.append(json_item)
|
|
171
|
+
return items
|
|
223
172
|
|
|
224
173
|
|
|
225
174
|
def invalid(cmd):
|
|
226
175
|
_logger.info('[{}] is invalid'.format(cmd))
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class ScannerItem:
|
|
179
|
+
def __init__(self, pkg_name, start_time=""):
|
|
180
|
+
self.cover = CoverItem(tool_name=pkg_name, start_time=start_time)
|
|
181
|
+
self.file_items: Dict[str, List[FileItem]] = {pkg_name: []} if pkg_name != FOSSLIGHT_SCANNER else {}
|
|
182
|
+
self.external_sheets: Dict[str, List[List[str]]] = {}
|
|
183
|
+
|
|
184
|
+
def set_cover_pathinfo(self, input_dir, path_to_exclude):
|
|
185
|
+
self.cover.input_path = input_dir
|
|
186
|
+
self.cover.exclude_path = ", ".join(path_to_exclude)
|
|
187
|
+
|
|
188
|
+
def set_cover_comment(self, value):
|
|
189
|
+
if value:
|
|
190
|
+
if self.cover.comment:
|
|
191
|
+
self.cover.comment = f"{self.cover.comment} / {value}"
|
|
192
|
+
else:
|
|
193
|
+
self.cover.comment = value
|
|
194
|
+
|
|
195
|
+
def get_cover_comment(self):
|
|
196
|
+
return [item.strip() for item in self.cover.comment.split(" / ")]
|
|
197
|
+
|
|
198
|
+
def append_file_items(self, file_item: List[FileItem], pkg_name=""):
|
|
199
|
+
if pkg_name == "":
|
|
200
|
+
if len(self.file_items.keys()) != 1:
|
|
201
|
+
_logger.error("Package name is not set. Cannot append file_item into ScannerItem.")
|
|
202
|
+
else:
|
|
203
|
+
pkg_name = list(self.file_items.keys())[0]
|
|
204
|
+
if pkg_name not in self.file_items:
|
|
205
|
+
self.file_items[pkg_name] = []
|
|
206
|
+
self.file_items[pkg_name].extend(file_item)
|
|
207
|
+
|
|
208
|
+
def get_print_array(self, scanner_name):
|
|
209
|
+
items = []
|
|
210
|
+
for file_item in self.file_items[scanner_name]:
|
|
211
|
+
items.extend(file_item.get_print_array())
|
|
212
|
+
return items
|
|
213
|
+
|
|
214
|
+
def get_print_json(self, scanner_name):
|
|
215
|
+
items = []
|
|
216
|
+
for file_item in self.file_items[scanner_name]:
|
|
217
|
+
items.extend(file_item.get_print_json())
|
|
218
|
+
return items
|
|
219
|
+
|
|
220
|
+
def __del__(self):
|
|
221
|
+
pass
|