Skip to content

Commit

Permalink
Fix lambda parameters: needs event and context
Browse files Browse the repository at this point in the history
  • Loading branch information
aloftus23 committed Dec 13, 2024
1 parent dde89d6 commit b1cb234
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
14 changes: 7 additions & 7 deletions backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion backend/src/xfd_django/xfd_api/tasks/lambda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/src/xfd_django/xfd_api/tasks/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")

Expand Down

0 comments on commit b1cb234

Please sign in to comment.