From 40daf313de03857bd6f81ac74a2c957398fd92cc Mon Sep 17 00:00:00 2001 From: wangchong1995924 <15229716099@163.com> Date: Thu, 8 May 2025 14:23:15 +0800 Subject: [PATCH] support release osv json file --- script/tools/update_cve_and_repodata.py | 7 +++- script/tools/update_repodata.py | 53 ++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/script/tools/update_cve_and_repodata.py b/script/tools/update_cve_and_repodata.py index 459210c..3a74617 100644 --- a/script/tools/update_cve_and_repodata.py +++ b/script/tools/update_cve_and_repodata.py @@ -24,10 +24,11 @@ from update_repodata import update_cve from update_repodata import update_repo from update_repodata import update_csaf from update_repodata import update_bugfix +from update_repodata import update_osv par = argparse.ArgumentParser() par.add_argument("-f", "--flag", default=None, - help="cve or csaf or updateinfo or updateinfo-hotpatch or bugfix", required=True) + help="cve or csaf or updateinfo or updateinfo-hotpatch or bugfix or osv", required=True) par.add_argument("-ak", "--AK", default=None, help="Access Key", required=True) par.add_argument("-sk", "--SK", default=None, @@ -53,6 +54,8 @@ if __name__ == '__main__': update_repo(args) elif args.flag == "bugfix": update_bugfix(args) + elif args.flag == "osv": + update_osv(args) else: - print("The flag include cve, csaf, updateinfo, updateinfo-hotpatch and bugfix.") + print("The flag include cve, csaf, updateinfo, updateinfo-hotpatch, bugfix and osv.") sys.exit(1) diff --git a/script/tools/update_repodata.py b/script/tools/update_repodata.py index 705d8a5..1121ee8 100644 --- a/script/tools/update_repodata.py +++ b/script/tools/update_repodata.py @@ -121,6 +121,28 @@ def download_bugfix_xmlfile(args, cvrf_path, obsClient): else: return -1 +def download_osv_jsonfile(args, osv_path, obsClient): + """ + downloads osv json file + """ + update_path = os.path.join(osv_path, "update_osv.txt") + if os.path.exists(update_path): + if os.path.getsize(update_path): + with open(update_path, "r") as f: + filemsg = f.readlines() + for line in filemsg: + if line: + line = line.replace('\n', '') + localfile = os.path.join(osv_path, line) + + name = os.path.join("osv/advisories", line) + createFile(localfile) + download_withfile(args, obsClient, name, localfile) + else: + return -1 + else: + return -1 + def download_csaffile(args, csaf_path, obsClient, dir_name): """ downloads csaf file @@ -152,7 +174,7 @@ def upload_xml_file(args, uploadfile, cvrf_name): upload xml files to publish server """ print("Uploading xml file to publish server.") - if cvrf_name == "SA" or cvrf_name == "HotPatchSA": + if cvrf_name == "SA" or cvrf_name == "HotPatchSA" or cvrf_name == "osv": dest_dir = "/repo/openeuler/security/data/" elif cvrf_name == "bugfix": dest_dir = "/repo/openeuler/bugFix/data/" @@ -347,3 +369,32 @@ def update_bugfix(args): else: cvrf_index_txt = os.path.join(cvrf_path, "index_defect.txt") upload_xml_file(args, cvrf_path, "bugfix") + +def update_osv(args): + """ + update osv file + """ + osv_path = os.path.join(os.getcwd(), "osv") + if os.path.exists(osv_path): + shutil.rmtree(osv_path) + os.makedirs(osv_path) + + for name in args.filename.split(','): + localfile = os.path.join(osv_path, name) + createFile(localfile) + obsClient = construct_obsClient(args) + name = os.path.join("osv/advisories", name) + download_withfile(args, obsClient, name, localfile) + + ret = download_osv_jsonfile(args, osv_path, obsClient) + update_path = os.path.join(osv_path, "update_osv.txt") + if os.path.exists(update_path): + os.remove(update_path) + + if ret == -1: + print("Nothing to update !") + elif ret == -2: + print("There are some problems in the update_osv.txt file.") + sys.exit(1) + else: + upload_xml_file(args, osv_path, "osv") -- Gitee