Esempio n. 1
0
def update_statuses(cve, data, packages):
    statuses = cve.packages

    statuses_query = db_session.query(Status).filter(Status.cve_id == cve.id)
    statuses_to_delete = {
        f"{v.package_name}||{v.release_codename}": v
        for v in statuses_query.all()
    }

    for package_data in data.get("packages", []):
        name = package_data["name"]

        if packages.get(name) is None:
            package = Package(name=name)
            package.source = package_data["source"]
            package.ubuntu = package_data["ubuntu"]
            package.debian = package_data["debian"]
            packages[name] = package

            db_session.add(package)

        for status_data in package_data["statuses"]:
            update_status = False
            codename = status_data["release_codename"]

            status = statuses[name].get(codename)
            if status is None:
                update_status = True
                status = Status(
                    cve_id=cve.id, package_name=name, release_codename=codename
                )
            elif f"{name}||{codename}" in statuses_to_delete:
                del statuses_to_delete[f"{name}||{codename}"]

            if status.status != status_data["status"]:
                update_status = True
                status.status = status_data["status"]

            if status.description != status_data["description"]:
                update_status = True
                status.description = status_data["description"]

            if status.component != status_data.get("component"):
                update_status = True
                status.component = status_data.get("component")

            if status.pocket != status_data.get("pocket"):
                update_status = True
                status.pocket = status_data.get("pocket")

            if update_status:
                statuses[name][codename] = status
                db_session.add(status)

    for key in statuses_to_delete:
        db_session.delete(statuses_to_delete[key])
Esempio n. 2
0
def update_statuses(cve, data, packages, releases):
    updated_statuses = []

    for package_data in data.get("packages", []):
        name = package_data["name"]
        package = packages.get(name) or Package(name=name)
        package.source = package_data["source"]
        package.ubuntu = package_data["ubuntu"]
        package.debian = package_data["debian"]
        packages[name] = package

        statuses = defaultdict(dict)

        for status in cve.statuses:
            statuses[status.package_name][status.release_codename] = status

        for status_data in package_data["statuses"]:
            codename = status_data["release_codename"]
            release = releases.get(codename)

            status = statuses[name].get(codename) or Status(
                cve=cve, package=package, release=release)

            status.status = status_data["status"]
            status.description = status_data["description"]

            statuses[name][codename] = status

            updated_statuses.append(status)

    return updated_statuses