From d29c9a71295a684c92d34e31f7bd6624ee0f40a3 Mon Sep 17 00:00:00 2001 From: Nemo Date: Fri, 28 Apr 2023 14:16:36 +0530 Subject: [PATCH] Delete old advisories --- README.md | 1 + generate.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22ca1ee..db3b642 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ republishes the advisories in the OSV format, and syncs them against the ## TODO: +- [x] Delete advisories that are deleted upstream (Experimental) - [x] Automatic Update - [ ] Automatic Sync (to GSD) - [ ] Schema: Provide `credits` diff --git a/generate.py b/generate.py index 9e831ef..00aada6 100644 --- a/generate.py +++ b/generate.py @@ -159,7 +159,6 @@ def merge_advisories(advisory_file, data): if canonicaljson.encode_canonical_json( original[key] ) != canonicaljson.encode_canonical_json(current[key]): - print(f"Found changes in {current['id']} / {key}") no_important_changes = False break @@ -195,8 +194,10 @@ def fetch_cve_metadata(PHOTON_VERSIONS): def __main__(advisory_id = None): cve_metadata = fetch_cve_metadata(PHOTON_VERSIONS) + advisories = set() for d in get_osv(cve_metadata): + advisories.add(d['id']) # If we are only running for a single advisory # Check and continue if it doesn't match if advisory_id and d['id'] != advisory_id: @@ -208,6 +209,13 @@ def __main__(advisory_id = None): with open(fn, "wb") as f: f.write(canonicaljson.encode_pretty_printed_json(d)) + # Remove any advisories that are no longer in the upstream data + for advisory in os.listdir("advisories"): + if advisory.endswith(".json"): + if advisory[:-5] not in advisories: + print(f"[-] Removing {advisory}") + # os.unlink(f"advisories/{advisory}") + if __name__ == "__main__": if len(sys.argv) >=2: