diff --git a/script/tools/update_cve_and_repodata.py b/script/tools/update_cve_and_repodata.py index 459210cd506f2c1f38206db561de43376a81b509..3a74617304f15db810d4701630ab02e2535e0f3e 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 705d8a525df1fe2b53694c59a046ba623a251b61..1121ee8d5e9ca3985a0c7e8755b26a1925433c8c 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")