mirror of
https://git.yoctoproject.org/poky
synced 2026-02-13 12:13:02 +01:00
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: d8ef964ffeb92684d01d71c983af9dbb1e1b0c4f) Signed-off-by: Davide Gardenal <davide.gardenal@huawei.com> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> (cherry picked from commit f2987891d315466b7ef180ecce81d15320ce8487) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
2120a39b09
commit
46e00399e5
@@ -75,6 +75,30 @@ CVE_CHECK_LAYER_INCLUDELIST ??= ""
|
||||
# set to "alphabetical" for version using single alphabetical character as increment release
|
||||
CVE_VERSION_SUFFIX ??= ""
|
||||
|
||||
def generate_json_report(out_path, link_path):
|
||||
if os.path.exists(d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")):
|
||||
import json
|
||||
from oe.cve_check import cve_check_merge_jsons
|
||||
|
||||
bb.note("Generating JSON CVE summary")
|
||||
index_file = d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")
|
||||
summary = {"version":"1", "package": []}
|
||||
with open(index_file) as f:
|
||||
filename = f.readline()
|
||||
while filename:
|
||||
with open(filename.rstrip()) as j:
|
||||
data = json.load(j)
|
||||
cve_check_merge_jsons(summary, data)
|
||||
filename = f.readline()
|
||||
|
||||
with open(out_path, "w") as f:
|
||||
json.dump(summary, f, indent=2)
|
||||
|
||||
if link_path != out_path:
|
||||
if os.path.exists(os.path.realpath(link_path)):
|
||||
os.remove(link_path)
|
||||
os.symlink(os.path.basename(out_path), link_path)
|
||||
|
||||
python cve_save_summary_handler () {
|
||||
import shutil
|
||||
import datetime
|
||||
@@ -97,6 +121,11 @@ python cve_save_summary_handler () {
|
||||
if os.path.exists(os.path.realpath(cvefile_link)):
|
||||
os.remove(cvefile_link)
|
||||
os.symlink(os.path.basename(cve_summary_file), cvefile_link)
|
||||
|
||||
json_summary_link_name = os.path.join(cvelogpath, d.getVar("CVE_CHECK_SUMMARY_FILE_NAME_JSON"))
|
||||
json_summary_name = os.path.join(cvelogpath, "%s-%s.json" % (cve_summary_name, timestamp))
|
||||
generate_json_report(json_summary_name, json_summary_link_name)
|
||||
bb.plain("CVE report summary created at: %s" % json_summary_link_name)
|
||||
}
|
||||
|
||||
addhandler cve_save_summary_handler
|
||||
@@ -170,25 +199,11 @@ python cve_check_write_rootfs_manifest () {
|
||||
os.symlink(os.path.basename(manifest_name), manifest_link)
|
||||
bb.plain("Image CVE report stored in: %s" % manifest_name)
|
||||
|
||||
if os.path.exists(d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")):
|
||||
import json
|
||||
link_path = os.path.join(deploy_dir, "%s.json" % link_name)
|
||||
manifest_path = d.getVar("CVE_CHECK_MANIFEST_JSON")
|
||||
bb.note("Generating JSON CVE manifest")
|
||||
deploy_dir = d.getVar("DEPLOY_DIR_IMAGE")
|
||||
link_name = d.getVar("IMAGE_LINK_NAME")
|
||||
manifest_name = d.getVar("CVE_CHECK_MANIFEST_JSON")
|
||||
index_file = d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")
|
||||
manifest = {"version":"1", "package": []}
|
||||
with open(index_file) as f:
|
||||
filename = f.readline()
|
||||
while filename:
|
||||
with open(filename.rstrip()) as j:
|
||||
data = json.load(j)
|
||||
cve_check_merge_jsons(manifest, data)
|
||||
filename = f.readline()
|
||||
|
||||
with open(manifest_name, "w") as f:
|
||||
json.dump(manifest, f, indent=2)
|
||||
bb.plain("Image CVE report stored in: %s" % manifest_name)
|
||||
generate_json_report(json_summary_name, json_summary_link_name)
|
||||
bb.plain("Image CVE JSON report stored in: %s" % link_path)
|
||||
}
|
||||
|
||||
ROOTFS_POSTPROCESS_COMMAND_prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}"
|
||||
|
||||
Reference in New Issue
Block a user