From add12fdbf1a12c6e22214dcebdc1b7e0557c4d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Blenku=C5=A1?= Date: Wed, 24 Jul 2024 15:41:22 +0200 Subject: [PATCH] Return date in RFC-3339 fromat on upload credentials endpoint --- resolwe/storage/utils.py | 12 ++++++++++++ resolwe/storage/views.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 resolwe/storage/utils.py diff --git a/resolwe/storage/utils.py b/resolwe/storage/utils.py new file mode 100644 index 000000000..c9ced9e8d --- /dev/null +++ b/resolwe/storage/utils.py @@ -0,0 +1,12 @@ +"""Storage Utils.""" + + +def iso8601_to_rfc3339(iso_string): + """Convert ISO8601 to RFC3339 format.""" + if "+" in iso_string or "-" in iso_string: + offset_sign = "+" if "+" in iso_string else "-" + date_time, offset = iso_string.split(offset_sign) + offset = offset[:2] + ":" + offset[2:] + return date_time + offset_sign + offset + + return iso_string diff --git a/resolwe/storage/views.py b/resolwe/storage/views.py index 9b1841c40..acd35fccc 100644 --- a/resolwe/storage/views.py +++ b/resolwe/storage/views.py @@ -31,6 +31,7 @@ from resolwe.storage.connectors import connectors from resolwe.storage.connectors.baseconnector import BaseStorageConnector from resolwe.storage.models import FileStorage, ReferencedPath +from resolwe.storage.utils import iso8601_to_rfc3339 from resolwe.test.utils import ignore_in_tests logger = logging.getLogger(__name__) @@ -79,7 +80,7 @@ def get(self, request, *args, **kwargs): "AccessKeyId": credentials["AccessKeyId"], "SecretAccessKey": credentials["SecretAccessKey"], "Token": credentials["SessionToken"], - "Expiration": credentials["Expiration"], + "Expiration": iso8601_to_rfc3339(credentials["Expiration"]), } return Response(self.serializer_class(response).data)