From ddfe9107afeadfdfa113d3f68133cf75b85afdc3 Mon Sep 17 00:00:00 2001 From: Garrett Marconet Date: Wed, 5 Feb 2025 13:55:44 -0800 Subject: [PATCH 1/6] fix timestamp_format timezone --- .../lambdas/layers/heimdall_utils/heimdall_utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py index 69c8b660..4f3d978d 100644 --- a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py +++ b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py @@ -17,7 +17,7 @@ logging.getLogger("botocore").setLevel(logging.WARNING) DYNAMODB_TTL_DAYS = 60 -TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ" +TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S%z" # -- This constant represents the maximum age for a HEIMDALL Scan -- From 1079c194f5c5c2aef3fa1d10d9aa3351ab00cf7f Mon Sep 17 00:00:00 2001 From: Garrett Marconet Date: Wed, 5 Feb 2025 14:14:00 -0800 Subject: [PATCH 2/6] add tests for is_valid_timestamp --- .../heimdall_utils/heimdall_utils/utils.py | 4 ++-- orchestrator/lambdas/tests/test_utils.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py index 4f3d978d..22008cb2 100644 --- a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py +++ b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py @@ -3,7 +3,7 @@ import logging import time from collections import namedtuple -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from json import JSONDecodeError from typing import Optional @@ -133,6 +133,6 @@ def is_valid_timestamp(timestamp: str) -> bool: def get_datetime_from_past(days: int) -> datetime: - current_timestamp = datetime.now() + current_timestamp = datetime.now(timezone.utc) three_months_ago = current_timestamp - timedelta(days=days) return three_months_ago diff --git a/orchestrator/lambdas/tests/test_utils.py b/orchestrator/lambdas/tests/test_utils.py index 5458c144..bfd24009 100644 --- a/orchestrator/lambdas/tests/test_utils.py +++ b/orchestrator/lambdas/tests/test_utils.py @@ -26,3 +26,19 @@ def test_get_json_from_response_success(self): result = self.json_utils.get_json_from_response(json.dumps(test_dict)) self.assertEqual(test_dict, result) + + def test_is_valid_timestamp_utc(self): + # Checks relative to current time plus a max scan age. + # Make sure to change this before 9998 + time = "9999-01-01T00:00:00Z"; + + self.assertTrue(utils.is_valid_timestamp(time)); + + def test_is_valid_timestamp_localized(self): + # Checks relative to current time minus a max scan age. + # Make sure to change this before 9998 + time = "9999-01-01T00:00:00-08:00"; + + self.assertTrue(utils.is_valid_timestamp(time)); + + From 500887ad87cb7463fb8264238b21c02ef2bc9d68 Mon Sep 17 00:00:00 2001 From: Garrett Marconet Date: Wed, 5 Feb 2025 14:15:55 -0800 Subject: [PATCH 3/6] ruff format --- orchestrator/lambdas/tests/test_utils.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/orchestrator/lambdas/tests/test_utils.py b/orchestrator/lambdas/tests/test_utils.py index bfd24009..686d1e55 100644 --- a/orchestrator/lambdas/tests/test_utils.py +++ b/orchestrator/lambdas/tests/test_utils.py @@ -30,15 +30,11 @@ def test_get_json_from_response_success(self): def test_is_valid_timestamp_utc(self): # Checks relative to current time plus a max scan age. # Make sure to change this before 9998 - time = "9999-01-01T00:00:00Z"; - - self.assertTrue(utils.is_valid_timestamp(time)); + time = "9999-01-01T00:00:00Z" + self.assertTrue(utils.is_valid_timestamp(time)) def test_is_valid_timestamp_localized(self): # Checks relative to current time minus a max scan age. # Make sure to change this before 9998 - time = "9999-01-01T00:00:00-08:00"; - - self.assertTrue(utils.is_valid_timestamp(time)); - - + time = "9999-01-01T00:00:00-08:00" + self.assertTrue(utils.is_valid_timestamp(time)) From 5f89da9e003869dd9874cc94670eefddbacf6975 Mon Sep 17 00:00:00 2001 From: Garrett Marconet Date: Wed, 5 Feb 2025 14:17:02 -0800 Subject: [PATCH 4/6] make comments consistent --- orchestrator/lambdas/tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchestrator/lambdas/tests/test_utils.py b/orchestrator/lambdas/tests/test_utils.py index 686d1e55..c8efe0cc 100644 --- a/orchestrator/lambdas/tests/test_utils.py +++ b/orchestrator/lambdas/tests/test_utils.py @@ -28,7 +28,7 @@ def test_get_json_from_response_success(self): self.assertEqual(test_dict, result) def test_is_valid_timestamp_utc(self): - # Checks relative to current time plus a max scan age. + # Checks relative to current time minus a max scan age. # Make sure to change this before 9998 time = "9999-01-01T00:00:00Z" self.assertTrue(utils.is_valid_timestamp(time)) From a5a1aedf885d13c7e772902d0b203c7e2267f4d7 Mon Sep 17 00:00:00 2001 From: Garrett Marconet Date: Thu, 6 Feb 2025 08:19:08 -0800 Subject: [PATCH 5/6] update generated timezone comment --- .../lambdas/layers/heimdall_utils/heimdall_utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py index 22008cb2..76904675 100644 --- a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py +++ b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py @@ -102,7 +102,7 @@ def parse_timestamp(timestamp: Optional[str] = None) -> str: Examples: >>> parse_timestamp() {"level":"DEBUG","location":"parse_timestamp","message":"Generating Default timestamp"} - "2024-04-24T22:35:36Z" # Output will vary based on the current date and time + "2024-01-01T6:14:57-0800" # Output will vary based on the current date, time, and timezone >>> parse_timestamp("2024-06-24T22:50:00Z") "2024-06-24T22:50:00Z" From c74ce63eddd9f60b3d6010402f4f68e29735eedd Mon Sep 17 00:00:00 2001 From: Garrett Marconet Date: Thu, 6 Feb 2025 09:07:19 -0800 Subject: [PATCH 6/6] delete utc blurb --- .../lambdas/layers/heimdall_utils/heimdall_utils/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py index 76904675..522d86cf 100644 --- a/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py +++ b/orchestrator/lambdas/layers/heimdall_utils/heimdall_utils/utils.py @@ -109,7 +109,6 @@ def parse_timestamp(timestamp: Optional[str] = None) -> str: Notes: - The function uses the current system time to calculate the 3-month offset. - - All returned timestamps are in UTC (denoted by the 'Z' suffix). """ if timestamp and is_valid_timestamp(timestamp): return timestamp