From 9761b4b5578495928629195cf17f6cf337eaa16a Mon Sep 17 00:00:00 2001 From: DJensen94 <79864006+DJensen94@users.noreply.github.com> Date: Wed, 5 Feb 2025 09:38:42 -0700 Subject: [PATCH] Clean up comments Clean up comments --- .../xfd_api/tasks/credential_sync.py | 20 ++++++------------- .../xfd_django/xfd_api/tasks/shodan_sync.py | 2 +- .../xfd_django/xfd_api/tasks/xpanse_sync.py | 16 +++++---------- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/backend/src/xfd_django/xfd_api/tasks/credential_sync.py b/backend/src/xfd_django/xfd_api/tasks/credential_sync.py index efd2d2a5..adec4a8b 100644 --- a/backend/src/xfd_django/xfd_api/tasks/credential_sync.py +++ b/backend/src/xfd_django/xfd_api/tasks/credential_sync.py @@ -1,4 +1,4 @@ -"""ShodanSync scan.""" +"""CredentialSync scan.""" # Standard Python Libraries from datetime import datetime, timedelta import os @@ -40,15 +40,8 @@ def handler(event): def main(): """Fetch and save DMZ credential breaches and exposures.""" all_orgs = Organization.objects.all() + # For testing # all_orgs = Organization.objects.filter(acronym__in=['USAGM', 'DHS']) - # change this - # shodan_datasource, created = DataSource.objects.get_or_create( - # name="Shodan", - # defaults={ - # "description": "Scans the internet for publicly accessible devices, concentrating on SCADA (supervisory control and data acquisition) systems.", # You can customize this text - # "last_run": timezone.now() # Sets the current date and time - # } - # ) # Step 1: Get the current date and time in UTC current_time = datetime.now(datetime.timezone.utc) @@ -71,10 +64,9 @@ def main(): while not done: data = fetch_dmz_cred_task(org.acronym, page, per_page, since_timestamp_str) - print(data) if not data or data.get("status") != "Processing": print( - "Failed to start Shodan Sync task for org: {acronym}, {name}".format( + "Failed to start Credential Sync task for org: {acronym}, {name}".format( acronym=org.acronym, name=org.name ) ) @@ -111,9 +103,9 @@ def main(): ) total_pages = response.get("result", {}).get("total_pages", 1) current_page = response.get("result", {}).get("current_page", 1) - print("breaches") + print("Returned breaches") print(cred_breaches_array) - print("exposures") + print("Returned exposures") print(cred_exposures_array) save_findings_to_db(cred_exposures_array, cred_breaches_array, org) @@ -178,7 +170,7 @@ def fetch_dmz_cred_data(task_id): response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: - print("Error fetching DMZ Shodan data: {error}".format(error=e)) + print("Error fetching DMZ Credential data: {error}".format(error=e)) return None diff --git a/backend/src/xfd_django/xfd_api/tasks/shodan_sync.py b/backend/src/xfd_django/xfd_api/tasks/shodan_sync.py index d8a2e7ad..ca7c2254 100644 --- a/backend/src/xfd_django/xfd_api/tasks/shodan_sync.py +++ b/backend/src/xfd_django/xfd_api/tasks/shodan_sync.py @@ -40,7 +40,7 @@ def main(): shodan_datasource, created = DataSource.objects.get_or_create( name="Shodan", defaults={ - "description": "Scans the internet for publicly accessible devices, concentrating on SCADA (supervisory control and data acquisition) systems.", # You can customize this text + "description": "Scans the internet for publicly accessible devices, concentrating on SCADA (supervisory control and data acquisition) systems.", "last_run": timezone.now().date(), # Sets the current date and time }, ) diff --git a/backend/src/xfd_django/xfd_api/tasks/xpanse_sync.py b/backend/src/xfd_django/xfd_api/tasks/xpanse_sync.py index 57d4dbdf..1a15b141 100644 --- a/backend/src/xfd_django/xfd_api/tasks/xpanse_sync.py +++ b/backend/src/xfd_django/xfd_api/tasks/xpanse_sync.py @@ -43,10 +43,10 @@ def main(): """Fetch and save DMZ Xpanse alerts.""" # Step 1: Get the current date and time in UTC current_time = datetime.now(datetime.timezone.utc) - # Step 2: Subtract 8 days from the current date - eight_days_ago = current_time - timedelta(days=15) + # Step 2: Subtract days from the current date + days_ago = current_time - timedelta(days=15) # Step 3: Convert to an ISO 8601 string with timezone (e.g., UTC) - modified_timestamp_str = eight_days_ago.isoformat() + modified_timestamp_str = days_ago.isoformat() if is_bu_pull_day(): business_units = pull_and_save_business_units() else: @@ -54,9 +54,6 @@ def main(): random.shuffle(business_units) - # business_units = XpanseBusinessUnits.objects.filter(cyhy_db_name_id__in=['SEMTECH']) - # print(business_units) - for business_unit in business_units: done = False page = 1 @@ -94,7 +91,6 @@ def main(): total_pages = response.get("result", {}).get("total_pages", 1) current_page = response.get("result", {}).get("current_page", 1) save_alerts_to_db(xpanse_alerts) - # print(xpanse_alerts) print(len(xpanse_alerts)) if current_page >= total_pages: done = True @@ -157,8 +153,6 @@ def pull_and_save_business_units(): "rating": business_unit.get("rating"), "cyhy_db_name": organization, } - # if mapped_org is not None: - # defaults["cyhy_db_name"] = mapped_org ( mdl_business_unit_object, @@ -209,7 +203,7 @@ def fetch_dmz_xpanse_alert_task(org_acronym, page, per_page, modified_datetime): def fetch_dmz_xpanse_data(task_id): - """Fetch DMZ Shodan vulnerability and asset data for a task.""" + """Fetch DMZ xpanse alert data for a task.""" url = "https://api.staging-cd.crossfeed.cyber.dhs.gov/pe/apiv1/mdl_xpanse_alerts_task_status/task/{task_id}".format( task_id=task_id ) @@ -224,7 +218,7 @@ def fetch_dmz_xpanse_data(task_id): response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: - print("Error fetching DMZ Shodan data: {error}".format(error=e)) + print("Error fetching DMZ Xpanse data: {error}".format(error=e)) return None