From patchwork Tue May 3 07:40:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davide Gardenal X-Patchwork-Id: 7520 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E95D0C433EF for ; Tue, 3 May 2022 07:40:52 +0000 (UTC) Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by mx.groups.io with SMTP id smtpd.web09.8296.1651563650888695455 for ; Tue, 03 May 2022 00:40:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=q7iSpY6N; spf=pass (domain: gmail.com, ip: 209.85.208.49, mailfrom: davidegarde2000@gmail.com) Received: by mail-ed1-f49.google.com with SMTP id g20so18917177edw.6 for ; Tue, 03 May 2022 00:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JD7f15Ts72+/BgpjdfYY2IEEtzutieRjwM8q4pGHXyY=; b=q7iSpY6NOWIpA66SL09tyDPveiFpBwqnLu4U3+3Gd7VpFoDipjiQVzMOH0z3cCLbTH OW9D0Rfkcn/RAenf8W5wJh2QDnoHHUH1g70j7QPDspvgKCPwFxh7MfG6cjtqdntgvZ8M /7Kwt96VCAd2nMq53F0qLaoHRqcvTIFw5jQM030pjR7WEcX1SatejUsxgMt1g7OLIsf/ w7hzJwVis5Cjhn4bjjXnR/wAQiHWZvhFJE/PijUehcWwYcd0jl468xDPEmSinZRwBIVQ RlkajhpsmTAT/FtJudvpfHNDHdjLNQS1vXDjOjJqBSojcku3XateHJgZY6ogGTSEN1z1 7mDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JD7f15Ts72+/BgpjdfYY2IEEtzutieRjwM8q4pGHXyY=; b=IBj3c5GImGKTW9u4Kf7uknAwQBFj15EAZryAYs6fWLQnyBZapB800NCH8UX0a9glAn MzSwqdg6qslh98NP+Iai0fVD6dFPMaWsM189k5FgAaRaa9Ee8FoR5Zr/KS+/TdNZpRC/ tU2n/+D66KO2VQ+tKDEO4CWvR51vtOeJjQ6kZ9Kz0X9H761QyV2iV7QOOOu4HVj5CtsN 9RZeW41xDdwRiSGwM5DUQgKh1hrz2LpOGMlLnyjRCyxUtNna9EGZXPZYJqpUY3GC9uWO /G3+hyyXQY9Fch3wU7txRnrsykbQFkAFRcLOKRDxTkOt6gYUzZncTW0ImigHzE6gL0G0 UpEQ== X-Gm-Message-State: AOAM531CEr6f1voNLvAcShgcqRaQgdNwQp+/8eZQrWwlzAvYgC5gaKUl 5Rcxvo+SZv42PyNTKt/9ZVikBCh7oyg= X-Google-Smtp-Source: ABdhPJwrl/g2j/fzJZERPMHQx4AnD2VGMTeSzqoFOtaqDlISU+SQ1zsj6EmSPAAJwEB4MCJZBpwLvw== X-Received: by 2002:a05:6402:2142:b0:413:6531:bd9e with SMTP id bq2-20020a056402214200b004136531bd9emr16429867edb.5.1651563648801; Tue, 03 May 2022 00:40:48 -0700 (PDT) Received: from tony3oo3-XPS-13-9370.home (host-87-5-19-163.retail.telecomitalia.it. [87.5.19.163]) by smtp.gmail.com with ESMTPSA id eo9-20020a1709069b0900b006f3ef214e02sm4312014ejc.104.2022.05.03.00.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 00:40:47 -0700 (PDT) From: Davide Gardenal X-Google-Original-From: Davide Gardenal To: openembedded-core@lists.openembedded.org Cc: Davide Gardenal Subject: [master][kirkstone][PATCH v2] cve-check: add JSON format to summary output Date: Tue, 3 May 2022 09:40:44 +0200 Message-Id: <20220503074044.6864-1-davide.gardenal@huawei.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 03 May 2022 07:40:52 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/165190 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. Signed-off-by: Davide Gardenal --- Updates: - v2: add a check to prevent linking the symlink to self and deleting the output file if the link name and the output name are the same --- meta-oniro-staging/classes/cve-check.bbclass | 51 +++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/meta-oniro-staging/classes/cve-check.bbclass b/meta-oniro-staging/classes/cve-check.bbclass index 78516d0..e4e7240 100644 --- a/meta-oniro-staging/classes/cve-check.bbclass +++ b/meta-oniro-staging/classes/cve-check.bbclass @@ -79,6 +79,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 @@ -101,6 +125,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 @@ -175,25 +204,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 ''}"