|
13 | 13 |
|
14 | 14 | import dojo.finding.helper as finding_helper |
15 | 15 | import dojo.risk_acceptance.helper as ra_helper |
16 | | -from dojo.celery_dispatch import dojo_dispatch_task |
17 | | -from dojo.importers.location_manager import LocationManager, UnsavedLocation |
18 | 16 | from dojo.importers.options import ImporterOptions |
19 | 17 | from dojo.jira_link.helper import is_keep_in_sync_with_jira |
20 | 18 | from dojo.location.models import Location |
@@ -80,8 +78,6 @@ def __init__( |
80 | 78 | and will raise a `NotImplemented` exception |
81 | 79 | """ |
82 | 80 | ImporterOptions.__init__(self, *args, **kwargs) |
83 | | - if settings.V3_FEATURE_LOCATIONS: |
84 | | - self.location_manager = LocationManager() |
85 | 81 |
|
86 | 82 | def check_child_implementation_exception(self): |
87 | 83 | """ |
@@ -391,36 +387,20 @@ def apply_import_tags( |
391 | 387 | for tag in self.tags: |
392 | 388 | self.add_tags_safe(finding, tag) |
393 | 389 |
|
394 | | - if settings.V3_FEATURE_LOCATIONS: |
395 | | - # Add any tags to any locations of the findings imported if necessary |
396 | | - if self.apply_tags_to_endpoints and self.tags: |
397 | | - # Collect all endpoints linked to the affected findings |
398 | | - locations_qs = Location.objects.filter(findings__finding__in=findings_to_tag).distinct() |
399 | | - try: |
400 | | - bulk_add_tags_to_instances( |
401 | | - tag_or_tags=self.tags, |
402 | | - instances=locations_qs, |
403 | | - tag_field_name="tags", |
404 | | - ) |
405 | | - except IntegrityError: |
406 | | - for finding in findings_to_tag: |
407 | | - for location in finding.locations.all(): |
408 | | - for tag in self.tags: |
409 | | - self.add_tags_safe(location.location, tag) |
410 | | - # Add any tags to any endpoints of the findings imported if necessary |
411 | | - elif self.apply_tags_to_endpoints and self.tags: |
412 | | - endpoints_qs = Endpoint.objects.filter(finding__in=findings_to_tag).distinct() |
| 390 | + # Add any tags to any locations/endpoints of the findings imported if necessary |
| 391 | + if self.apply_tags_to_endpoints and self.tags: |
| 392 | + locations_qs = self.location_handler.get_locations_for_tagging(findings_to_tag) |
413 | 393 | try: |
414 | 394 | bulk_add_tags_to_instances( |
415 | 395 | tag_or_tags=self.tags, |
416 | | - instances=endpoints_qs, |
| 396 | + instances=locations_qs, |
417 | 397 | tag_field_name="tags", |
418 | 398 | ) |
419 | 399 | except IntegrityError: |
420 | 400 | for finding in findings_to_tag: |
421 | | - for endpoint in finding.endpoints.all(): |
| 401 | + for location in self.location_handler.get_location_tag_fallback(finding): |
422 | 402 | for tag in self.tags: |
423 | | - self.add_tags_safe(endpoint, tag) |
| 403 | + self.add_tags_safe(location, tag) |
424 | 404 |
|
425 | 405 | def update_import_history( |
426 | 406 | self, |
@@ -467,14 +447,8 @@ def update_import_history( |
467 | 447 | import_settings["apply_tags_to_endpoints"] = self.apply_tags_to_endpoints |
468 | 448 | import_settings["group_by"] = self.group_by |
469 | 449 | import_settings["create_finding_groups_for_all_findings"] = self.create_finding_groups_for_all_findings |
470 | | - if settings.V3_FEATURE_LOCATIONS: |
471 | | - # Add the list of locations that were added exclusively at import time |
472 | | - if len(self.endpoints_to_add) > 0: |
473 | | - import_settings["locations"] = [str(location) for location in self.endpoints_to_add] |
474 | | - # TODO: Delete this after the move to Locations |
475 | | - # Add the list of endpoints that were added exclusively at import time |
476 | | - elif len(self.endpoints_to_add) > 0: |
477 | | - import_settings["endpoints"] = [str(endpoint) for endpoint in self.endpoints_to_add] |
| 450 | + if len(self.endpoints_to_add) > 0: |
| 451 | + import_settings.update(self.location_handler.serialize_extra_locations(self.endpoints_to_add)) |
478 | 452 | # Create the test import object |
479 | 453 | test_import = Test_Import.objects.create( |
480 | 454 | test=self.test, |
@@ -796,50 +770,13 @@ def process_request_response_pairs( |
796 | 770 | def process_locations( |
797 | 771 | self, |
798 | 772 | finding: Finding, |
799 | | - locations_to_add: list[UnsavedLocation], |
| 773 | + extra_locations_to_add: list | None = None, |
800 | 774 | ) -> None: |
801 | 775 | """ |
802 | | - Process any locations to add to the finding. Locations could come from two places |
803 | | - - Directly from the report |
804 | | - - Supplied by the user from the import form |
805 | | - These locations will be processed in to Location objects and associated with the |
806 | | - finding and product |
807 | | - """ |
808 | | - # Save the unsaved locations |
809 | | - self.location_manager.chunk_locations_and_disperse(finding, finding.unsaved_locations) |
810 | | - # Check for any that were added in the form |
811 | | - if len(locations_to_add) > 0: |
812 | | - logger.debug("locations_to_add: %s", locations_to_add) |
813 | | - self.location_manager.chunk_locations_and_disperse(finding, locations_to_add) |
814 | | - |
815 | | - # TODO: Delete this after the move to Locations |
816 | | - def process_endpoints( |
817 | | - self, |
818 | | - finding: Finding, |
819 | | - endpoints_to_add: list[Endpoint], |
820 | | - ) -> None: |
| 776 | + Record locations/endpoints from the finding + any form-added extras. |
| 777 | + Flushed to DB by location_handler.persist(). |
821 | 778 | """ |
822 | | - Process any endpoints to add to the finding. Endpoints could come from two places |
823 | | - - Directly from the report |
824 | | - - Supplied by the user from the import form |
825 | | - These endpoints will be processed in to endpoints objects and associated with the |
826 | | - finding and and product |
827 | | - """ |
828 | | - if settings.V3_FEATURE_LOCATIONS: |
829 | | - msg = "BaseImporter#process_endpoints() method is deprecated when V3_FEATURE_LOCATIONS is enabled" |
830 | | - raise NotImplementedError(msg) |
831 | | - |
832 | | - # Clean and record unsaved endpoints from the report |
833 | | - self.endpoint_manager.clean_unsaved_endpoints(finding.unsaved_endpoints) |
834 | | - for endpoint in finding.unsaved_endpoints: |
835 | | - key = self.endpoint_manager.record_endpoint(endpoint) |
836 | | - self.endpoint_manager.record_status_for_create(finding, key) |
837 | | - # Record any endpoints added from the form |
838 | | - if len(endpoints_to_add) > 0: |
839 | | - logger.debug("endpoints_to_add: %s", endpoints_to_add) |
840 | | - for endpoint in endpoints_to_add: |
841 | | - key = self.endpoint_manager.record_endpoint(endpoint) |
842 | | - self.endpoint_manager.record_status_for_create(finding, key) |
| 779 | + self.location_handler.record_for_finding(finding, extra_locations_to_add) |
843 | 780 |
|
844 | 781 | def sanitize_vulnerability_ids(self, finding) -> None: |
845 | 782 | """Remove undisired vulnerability id values""" |
@@ -932,19 +869,7 @@ def mitigate_finding( |
932 | 869 | # Remove risk acceptance if present (vulnerability is now fixed) |
933 | 870 | # risk_unaccept will check if finding.risk_accepted is True before proceeding |
934 | 871 | ra_helper.risk_unaccept(self.user, finding, perform_save=False, post_comments=False) |
935 | | - if settings.V3_FEATURE_LOCATIONS: |
936 | | - # Mitigate the location statuses |
937 | | - dojo_dispatch_task( |
938 | | - LocationManager.mitigate_location_status, |
939 | | - finding.locations.all(), |
940 | | - self.user, |
941 | | - kwuser=self.user, |
942 | | - sync=True, |
943 | | - ) |
944 | | - else: |
945 | | - # TODO: Delete this after the move to Locations |
946 | | - # Accumulate endpoint statuses for bulk mitigate in persist() |
947 | | - self.endpoint_manager.record_statuses_to_mitigate(finding.status_finding.all()) |
| 872 | + self.location_handler.record_mitigations_for_finding(finding, self.user) |
948 | 873 | # to avoid pushing a finding group multiple times, we push those outside of the loop |
949 | 874 | if finding_groups_enabled and finding.finding_group: |
950 | 875 | # don't try to dedupe findings that we are closing |
|
0 commit comments