Skip to content

Commit e487b7a

Browse files
committed
include progress report on endpoint to location migration
1 parent 0a03518 commit e487b7a

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

dojo/management/commands/migrate_endpoints_to_locations.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
logger = logging.getLogger(__name__)
1313

14+
# Chunk size for DB cursor and progress report
15+
CHUNK_SIZE = 1000
1416

1517
class Command(BaseCommand):
1618

@@ -88,11 +90,31 @@ def _associate_location_with_findings(self, endpoint: Endpoint, location: Locati
8890
location.associate_with_product(product)
8991

9092
def handle(self, *args, **options):
93+
# Allow endpoints to work with V3/Locations enabled
9194
with Endpoint.allow_endpoint_init():
95+
# Progress counter
96+
i = 0
9297
# Start off with the endpoint objects - it should contain everything we need
93-
for endpoint in Endpoint.objects.all().iterator():
98+
queryset = Endpoint.objects.all()
99+
# Grab the total count so we can communicate progress
100+
endpoint_count = queryset.count()
101+
102+
# Process each endpoint
103+
for i, endpoint in enumerate(queryset.iterator(chunk_size=CHUNK_SIZE), 1):
104+
# Progress report every chunk
105+
if not i % CHUNK_SIZE:
106+
self.stdout.write(
107+
self.style.SUCCESS(
108+
f"Migrated {i}/{endpoint_count} endpoints..."
109+
)
110+
)
94111
# Get the URL object first
95112
location = self._endpoint_to_url(endpoint)
96113
# Associate the URL with the findings associated with the Findings
97114
# the association to a finding will also apply to a product automatically
98115
self._associate_location_with_findings(endpoint, location)
116+
self.stdout.write(
117+
self.style.SUCCESS(
118+
f"Migrated {i} total endpoints."
119+
)
120+
)

0 commit comments

Comments
 (0)