Skip to content

Commit 454f762

Browse files
committed
Change process to compute hash
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent a5acd9c commit 454f762

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

vulnerabilities/pipelines/v2_improvers/group_advisories_for_packages.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10+
import hashlib
11+
import json
1012
from collections import defaultdict
1113

1214
from django.db import transaction
@@ -16,7 +18,7 @@
1618
from vulnerabilities.models import AdvisoryV2
1719
from vulnerabilities.models import PackageV2
1820
from vulnerabilities.pipelines import VulnerableCodePipeline
19-
from vulnerabilities.utils import compute_advisory_content
21+
from vulnerabilities.utils import normalize_list
2022

2123

2224
class GroupAdvisoriesForPackages(VulnerableCodePipeline):
@@ -42,15 +44,26 @@ def merge_advisories(advisories):
4244
result_groups = []
4345

4446
for adv in advisories:
45-
print(adv.avid)
46-
if adv.advisory_content_hash:
47-
content_hash_map[adv.advisory_content_hash].append(adv)
47+
affected = []
48+
fixed = []
49+
50+
for impact in adv.impacted_packages.all():
51+
affected.extend([pkg.package_url for pkg in impact.affecting_packages.all()])
52+
53+
fixed.extend([pkg.package_url for pkg in impact.fixed_by_packages.all()])
54+
55+
normalized_data = {
56+
"affected_packages": normalize_list(affected),
57+
"fixed_packages": normalize_list(fixed),
58+
}
59+
60+
normalized_json = json.dumps(normalized_data, separators=(",", ":"), sort_keys=True)
61+
content_hash = hashlib.sha256(normalized_json.encode("utf-8")).hexdigest()
62+
63+
if content_hash:
64+
content_hash_map[content_hash].append(adv)
4865
else:
49-
content_hash = compute_advisory_content(advisory_data=adv)
50-
if content_hash:
51-
content_hash_map[content_hash].append(adv)
52-
else:
53-
result_groups.append([adv])
66+
result_groups.append([adv])
5467

5568
final_groups = []
5669

0 commit comments

Comments
 (0)