diff options
Diffstat (limited to 'meta/classes/cve-check.bbclass')
| -rw-r--r-- | meta/classes/cve-check.bbclass | 51 |
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 |
| 80 | CVE_VERSION_SUFFIX ??= "" | 80 | CVE_VERSION_SUFFIX ??= "" |
| 81 | 81 | ||
| 82 | def 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 | |||
| 82 | python cve_save_summary_handler () { | 106 | python 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 | ||
| 106 | addhandler cve_save_summary_handler | 135 | addhandler 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 | ||
| 199 | ROOTFS_POSTPROCESS_COMMAND:prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}" | 214 | ROOTFS_POSTPROCESS_COMMAND:prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}" |
