Skip to content

Commit

Permalink
Clean up comments
Browse files Browse the repository at this point in the history
Clean up comments
  • Loading branch information
DJensen94 committed Feb 5, 2025
1 parent 9a0c0ce commit 9761b4b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
20 changes: 6 additions & 14 deletions backend/src/xfd_django/xfd_api/tasks/credential_sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""ShodanSync scan."""
"""CredentialSync scan."""
# Standard Python Libraries
from datetime import datetime, timedelta
import os
Expand Down Expand Up @@ -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)
Expand All @@ -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
)
)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion backend/src/xfd_django/xfd_api/tasks/shodan_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
Expand Down
16 changes: 5 additions & 11 deletions backend/src/xfd_django/xfd_api/tasks/xpanse_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,17 @@ 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:
business_units = list(XpanseBusinessUnits.objects.all())

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
Expand All @@ -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


Expand Down

0 comments on commit 9761b4b

Please sign in to comment.