Skip to content

Commit 3943767

Browse files
author
Valentijn Scholten
committed
add support for FINDING_DEDUPE_BATCH_METHOD
1 parent 04f24ad commit 3943767

1 file changed

Lines changed: 31 additions & 23 deletions

File tree

dojo/finding/deduplication.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def do_dedupe_finding(new_finding, *args, **kwargs):
3131
except System_Settings.DoesNotExist:
3232
logger.warning("system settings not found")
3333
enabled = False
34+
3435
if enabled:
3536
deduplicationLogger.debug("dedupe for: " + str(new_finding.id)
3637
+ ":" + str(new_finding.title))
@@ -511,31 +512,38 @@ def _dedupe_batch_legacy(findings):
511512
deduplicationLogger.debug(str(e))
512513

513514

514-
def dedupe_batch_of_findings(findings):
515+
def dedupe_batch_of_findings(findings, *args, **kwargs):
515516
if not findings:
516517
return
517518

518-
# sort findings by id to ensure deduplication is deterministic/reproducible
519-
findings = sorted(findings, key=attrgetter("id"))
520-
521-
from dojo.utils import get_custom_method # noqa: PLC0415 -- circular import
522-
if dedupe_method := get_custom_method("FINDING_DEDUPE_METHOD"):
523-
for finding in findings:
524-
dedupe_method(finding)
525-
return
519+
try:
520+
enabled = System_Settings.objects.get(no_cache=True).enable_deduplication
521+
except System_Settings.DoesNotExist:
522+
logger.warning("system settings not found")
523+
enabled = False
526524

527-
test = findings[0].test
528-
dedup_alg = test.deduplication_algorithm
529-
530-
if dedup_alg == settings.DEDUPE_ALGO_HASH_CODE:
531-
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_HASH_CODE - {len(findings)} findings")
532-
_dedupe_batch_hash_code(findings)
533-
elif dedup_alg == settings.DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL:
534-
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL - {len(findings)} findings")
535-
_dedupe_batch_unique_id(findings)
536-
elif dedup_alg == settings.DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE:
537-
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE - {len(findings)} findings")
538-
_dedupe_batch_uid_or_hash(findings)
525+
if enabled:
526+
# sort findings by id to ensure deduplication is deterministic/reproducible
527+
findings = sorted(findings, key=attrgetter("id"))
528+
529+
from dojo.utils import get_custom_method # noqa: PLC0415 -- circular import
530+
if batch_dedupe_method := get_custom_method("FINDING_DEDUPE_BATCH_METHOD"):
531+
batch_dedupe_method(findings, *args, **kwargs)
532+
533+
test = findings[0].test
534+
dedup_alg = test.deduplication_algorithm
535+
536+
if dedup_alg == settings.DEDUPE_ALGO_HASH_CODE:
537+
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_HASH_CODE - {len(findings)} findings")
538+
_dedupe_batch_hash_code(findings)
539+
elif dedup_alg == settings.DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL:
540+
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL - {len(findings)} findings")
541+
_dedupe_batch_unique_id(findings)
542+
elif dedup_alg == settings.DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE:
543+
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE - {len(findings)} findings")
544+
_dedupe_batch_uid_or_hash(findings)
545+
else:
546+
logger.debug(f"deduplicating finding batch with LEGACY - {len(findings)} findings")
547+
_dedupe_batch_legacy(findings)
539548
else:
540-
logger.debug(f"deduplicating finding batch with LEGACY - {len(findings)} findings")
541-
_dedupe_batch_legacy(findings)
549+
deduplicationLogger.debug("dedupe: skipping dedupe because it's disabled in system settings get()")

0 commit comments

Comments
 (0)