From b1cb2345f1cc512531eedc7378c3fa90f6b7a7ff Mon Sep 17 00:00:00 2001 From: aloftus23 Date: Thu, 12 Dec 2024 19:19:42 -0500 Subject: [PATCH] Fix lambda parameters: needs event and context --- .../management/commands/populate_by_orgs_cache.py | 2 +- .../commands/populate_latest_vulns_cache.py | 2 +- .../commands/populate_most_common_vulns_cache.py | 2 +- .../management/commands/populate_ports_cache.py | 2 +- .../management/commands/populate_services_cache.py | 2 +- .../commands/populate_severity_count_cache.py | 2 +- .../management/commands/populate_vulns_cache.py | 2 +- .../xfd_django/xfd_api/tasks/elasticache_tasks.py | 14 +++++++------- .../src/xfd_django/xfd_api/tasks/lambda_client.py | 2 +- backend/src/xfd_django/xfd_api/tasks/scheduler.py | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/src/xfd_django/xfd_api/management/commands/populate_by_orgs_cache.py b/backend/src/xfd_django/xfd_api/management/commands/populate_by_orgs_cache.py index 0b0a1ad4..a1bc960f 100644 --- a/backend/src/xfd_django/xfd_api/management/commands/populate_by_orgs_cache.py +++ b/backend/src/xfd_django/xfd_api/management/commands/populate_by_orgs_cache.py @@ -7,5 +7,5 @@ class Command(BaseCommand): help = "Populates the vulnerabilities stats cache in AWS Elasticache" def handle(self, *args, **options): - result = populate_by_org_cache() + result = populate_by_org_cache({}, {}) self.stdout.write(self.style.SUCCESS(result["message"])) diff --git a/backend/src/xfd_django/xfd_api/management/commands/populate_latest_vulns_cache.py b/backend/src/xfd_django/xfd_api/management/commands/populate_latest_vulns_cache.py index e92930cc..dee859f5 100644 --- a/backend/src/xfd_django/xfd_api/management/commands/populate_latest_vulns_cache.py +++ b/backend/src/xfd_django/xfd_api/management/commands/populate_latest_vulns_cache.py @@ -7,5 +7,5 @@ class Command(BaseCommand): help = "Populates the vulnerabilities stats cache in AWS Elasticache" def handle(self, *args, **options): - result = populate_latest_vulns_cache() + result = populate_latest_vulns_cache({}, {}) self.stdout.write(self.style.SUCCESS(result["message"])) diff --git a/backend/src/xfd_django/xfd_api/management/commands/populate_most_common_vulns_cache.py b/backend/src/xfd_django/xfd_api/management/commands/populate_most_common_vulns_cache.py index a2cde041..52d20977 100644 --- a/backend/src/xfd_django/xfd_api/management/commands/populate_most_common_vulns_cache.py +++ b/backend/src/xfd_django/xfd_api/management/commands/populate_most_common_vulns_cache.py @@ -7,5 +7,5 @@ class Command(BaseCommand): help = "Populates the vulnerabilities stats cache in AWS Elasticache" def handle(self, *args, **options): - result = populate_most_common_vulns_cache() + result = populate_most_common_vulns_cache({}, {}) self.stdout.write(self.style.SUCCESS(result["message"])) diff --git a/backend/src/xfd_django/xfd_api/management/commands/populate_ports_cache.py b/backend/src/xfd_django/xfd_api/management/commands/populate_ports_cache.py index a0dc7f8b..90534e1b 100644 --- a/backend/src/xfd_django/xfd_api/management/commands/populate_ports_cache.py +++ b/backend/src/xfd_django/xfd_api/management/commands/populate_ports_cache.py @@ -10,5 +10,5 @@ class Command(BaseCommand): ) def handle(self, *args, **options): - result = populate_ports_cache() + result = populate_ports_cache({}, {}) self.stdout.write(self.style.SUCCESS(result["message"])) diff --git a/backend/src/xfd_django/xfd_api/management/commands/populate_services_cache.py b/backend/src/xfd_django/xfd_api/management/commands/populate_services_cache.py index 89d78411..368aaef7 100644 --- a/backend/src/xfd_django/xfd_api/management/commands/populate_services_cache.py +++ b/backend/src/xfd_django/xfd_api/management/commands/populate_services_cache.py @@ -10,5 +10,5 @@ class Command(BaseCommand): ) def handle(self, *args, **options): - result = populate_services_cache() + result = populate_services_cache({}, {}) self.stdout.write(self.style.SUCCESS(result["message"])) diff --git a/backend/src/xfd_django/xfd_api/management/commands/populate_severity_count_cache.py b/backend/src/xfd_django/xfd_api/management/commands/populate_severity_count_cache.py index 236e44e9..9c8d9c17 100644 --- a/backend/src/xfd_django/xfd_api/management/commands/populate_severity_count_cache.py +++ b/backend/src/xfd_django/xfd_api/management/commands/populate_severity_count_cache.py @@ -7,5 +7,5 @@ class Command(BaseCommand): help = "Populates the vulnerabilities stats cache in AWS Elasticache" def handle(self, *args, **options): - result = populate_severity_cache() + result = populate_severity_cache({}, {}) self.stdout.write(self.style.SUCCESS(result["message"])) diff --git a/backend/src/xfd_django/xfd_api/management/commands/populate_vulns_cache.py b/backend/src/xfd_django/xfd_api/management/commands/populate_vulns_cache.py index 674bc3ff..070a315e 100644 --- a/backend/src/xfd_django/xfd_api/management/commands/populate_vulns_cache.py +++ b/backend/src/xfd_django/xfd_api/management/commands/populate_vulns_cache.py @@ -7,5 +7,5 @@ class Command(BaseCommand): help = "Populates the vulnerabilities stats cache in AWS Elasticache" def handle(self, *args, **options): - result = populate_num_vulns_cache() + result = populate_num_vulns_cache({}, {}) self.stdout.write(self.style.SUCCESS(result["message"])) diff --git a/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py b/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py index 2deab701..99f9c3bf 100644 --- a/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py +++ b/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py @@ -21,7 +21,7 @@ from xfd_api.models import Service, Vulnerability -def populate_services_cache(): +def populate_services_cache(event, context): return populate_stats_cache( model=Service, group_by_field="domain__organization_id", @@ -35,7 +35,7 @@ def populate_services_cache(): ) -def populate_ports_cache(): +def populate_ports_cache(event, context): return populate_stats_cache( model=Service, group_by_field="domain__organization_id", @@ -49,7 +49,7 @@ def populate_ports_cache(): ) -def populate_num_vulns_cache(): +def populate_num_vulns_cache(event, context): return populate_stats_cache( model=Vulnerability, group_by_field="domain__organization_id", @@ -69,7 +69,7 @@ def populate_num_vulns_cache(): ) -def populate_latest_vulns_cache(max_results=100): +def populate_latest_vulns_cache(event, context, max_results=100): """ Populate Redis with the latest vulnerabilities for each organization. """ @@ -164,7 +164,7 @@ def populate_latest_vulns_cache(max_results=100): } -def populate_most_common_vulns_cache(max_results=100): +def populate_most_common_vulns_cache(event, context, max_results=100): """ Populate Redis with the most common vulnerabilities grouped by title, description, and severity. """ @@ -220,7 +220,7 @@ def populate_most_common_vulns_cache(max_results=100): } -def populate_severity_cache(): +def populate_severity_cache(event, context): """ Populate Redis with severity statistics for vulnerabilities. """ @@ -237,7 +237,7 @@ def populate_severity_cache(): ) -def populate_by_org_cache(): +def populate_by_org_cache(event, context): """ Populate Redis with the count of open vulnerabilities grouped by organization. Each organization's data is stored under its own Redis key. diff --git a/backend/src/xfd_django/xfd_api/tasks/lambda_client.py b/backend/src/xfd_django/xfd_api/tasks/lambda_client.py index d3cb4ea1..74f58ca8 100644 --- a/backend/src/xfd_django/xfd_api/tasks/lambda_client.py +++ b/backend/src/xfd_django/xfd_api/tasks/lambda_client.py @@ -26,7 +26,7 @@ def run_command(self, name: str): print(f"Invoking lambda function: {name}") if self.is_local: # If running locally, directly call the scheduler function - scheduler({}) + scheduler({}, {}) return {"status": 200, "message": ""} else: # Invoke the lambda function asynchronously diff --git a/backend/src/xfd_django/xfd_api/tasks/scheduler.py b/backend/src/xfd_django/xfd_api/tasks/scheduler.py index fe5018d6..0325644f 100644 --- a/backend/src/xfd_django/xfd_api/tasks/scheduler.py +++ b/backend/src/xfd_django/xfd_api/tasks/scheduler.py @@ -267,7 +267,7 @@ def filter_scan_tasks(tasks): return True -def handler(event): +def handler(event, context): """Handler for manually invoking the scheduler to run scans.""" print("Running scheduler...")