[elbe-devel] [PATCH 3/3] elbepack: cyclonedx-sbom: always print timezones in JSON
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Fri Jul 5 15:28:48 CEST 2024
JSON schema only allows datetime objects with timezone specifications.
Always use and enforce UTC times, we don't need anything else.
For simplicity drop the logic for datetime.date as it's not used and
probably won't be.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/commands/cyclonedx-sbom.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/elbepack/commands/cyclonedx-sbom.py b/elbepack/commands/cyclonedx-sbom.py
index e27f28cb59f4..19173f6f2fb7 100644
--- a/elbepack/commands/cyclonedx-sbom.py
+++ b/elbepack/commands/cyclonedx-sbom.py
@@ -16,7 +16,9 @@ from elbepack.version import elbe_version
class CycloneDXEncoder(json.JSONEncoder):
def default(self, obj):
- if isinstance(obj, (datetime.date, datetime.datetime)):
+ if isinstance(obj, datetime.datetime):
+ if obj.tzinfo is not datetime.timezone.utc:
+ raise ValueError('only UTC datetimes are supported')
return obj.isoformat()
@@ -84,7 +86,7 @@ def run_command(argv):
oparser.add_option('-d', dest='elbe_build')
options, args = oparser.parse_args()
- ts = datetime.datetime.now()
+ ts = datetime.datetime.now(tz=datetime.timezone.utc)
project_dir = options.elbe_build
source_file = ElbeXML(os.path.join(project_dir, 'source.xml'))
--
2.45.2
More information about the elbe-devel
mailing list