summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorDavide Gardenal <davidegarde2000@gmail.com>2022-05-03 09:51:43 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-05-04 21:13:29 +0100
commit630fb072192b345c42952dd0f274c66aedc67cff (patch)
treef597b8a86d4b82c39326f81e901990e1d521449a /meta
parent78b41029221ca27b4511459c09bc85504555272d (diff)
downloadpoky-630fb072192b345c42952dd0f274c66aedc67cff.tar.gz
cve-check: add JSON format to summary output
Create generate_json_report including all the code used to generate the JSON manifest file. Add to cve_save_summary_handler the ability to create the summary in JSON format. (From OE-Core rev: f2987891d315466b7ef180ecce81d15320ce8487) Signed-off-by: Davide Gardenal <davide.gardenal@huawei.com> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/cve-check.bbclass51
1 files changed, 33 insertions, 18 deletions
diff --git a/meta/classes/cve-check.bbclass b/meta/classes/cve-check.bbclass
index 7cf206299b..c74c717235 100644
--- a/meta/classes/cve-check.bbclass
+++ b/meta/classes/cve-check.bbclass
@@ -79,6 +79,30 @@ CVE_CHECK_LAYER_INCLUDELIST ??= ""
79# set to "alphabetical" for version using single alphabetical character as increment release 79# set to "alphabetical" for version using single alphabetical character as increment release
80CVE_VERSION_SUFFIX ??= "" 80CVE_VERSION_SUFFIX ??= ""
81 81
82def generate_json_report(out_path, link_path):
83 if os.path.exists(d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")):
84 import json
85 from oe.cve_check import cve_check_merge_jsons
86
87 bb.note("Generating JSON CVE summary")
88 index_file = d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")
89 summary = {"version":"1", "package": []}
90 with open(index_file) as f:
91 filename = f.readline()
92 while filename:
93 with open(filename.rstrip()) as j:
94 data = json.load(j)
95 cve_check_merge_jsons(summary, data)
96 filename = f.readline()
97
98 with open(out_path, "w") as f:
99 json.dump(summary, f, indent=2)
100
101 if link_path != out_path:
102 if os.path.exists(os.path.realpath(link_path)):
103 os.remove(link_path)
104 os.symlink(os.path.basename(out_path), link_path)
105
82python cve_save_summary_handler () { 106python cve_save_summary_handler () {
83 import shutil 107 import shutil
84 import datetime 108 import datetime
@@ -101,6 +125,11 @@ python cve_save_summary_handler () {
101 if os.path.exists(os.path.realpath(cvefile_link)): 125 if os.path.exists(os.path.realpath(cvefile_link)):
102 os.remove(cvefile_link) 126 os.remove(cvefile_link)
103 os.symlink(os.path.basename(cve_summary_file), cvefile_link) 127 os.symlink(os.path.basename(cve_summary_file), cvefile_link)
128
129 json_summary_link_name = os.path.join(cvelogpath, d.getVar("CVE_CHECK_SUMMARY_FILE_NAME_JSON"))
130 json_summary_name = os.path.join(cvelogpath, "%s-%s.json" % (cve_summary_name, timestamp))
131 generate_json_report(json_summary_name, json_summary_link_name)
132 bb.plain("CVE report summary created at: %s" % json_summary_link_name)
104} 133}
105 134
106addhandler cve_save_summary_handler 135addhandler cve_save_summary_handler
@@ -175,25 +204,11 @@ python cve_check_write_rootfs_manifest () {
175 os.symlink(os.path.basename(manifest_name), manifest_link) 204 os.symlink(os.path.basename(manifest_name), manifest_link)
176 bb.plain("Image CVE report stored in: %s" % manifest_name) 205 bb.plain("Image CVE report stored in: %s" % manifest_name)
177 206
178 if os.path.exists(d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")): 207 link_path = os.path.join(deploy_dir, "%s.json" % link_name)
179 import json 208 manifest_path = d.getVar("CVE_CHECK_MANIFEST_JSON")
180 bb.note("Generating JSON CVE manifest") 209 bb.note("Generating JSON CVE manifest")
181 deploy_dir = d.getVar("DEPLOY_DIR_IMAGE") 210 generate_json_report(json_summary_name, json_summary_link_name)
182 link_name = d.getVar("IMAGE_LINK_NAME") 211 bb.plain("Image CVE JSON report stored in: %s" % link_path)
183 manifest_name = d.getVar("CVE_CHECK_MANIFEST_JSON")
184 index_file = d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")
185 manifest = {"version":"1", "package": []}
186 with open(index_file) as f:
187 filename = f.readline()
188 while filename:
189 with open(filename.rstrip()) as j:
190 data = json.load(j)
191 cve_check_merge_jsons(manifest, data)
192 filename = f.readline()
193
194 with open(manifest_name, "w") as f:
195 json.dump(manifest, f, indent=2)
196 bb.plain("Image CVE report stored in: %s" % manifest_name)
197} 212}
198 213
199ROOTFS_POSTPROCESS_COMMAND:prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}" 214ROOTFS_POSTPROCESS_COMMAND:prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}"