From 5e41b4daf0a4f3c1530b1b517df3f191dc28e387 Mon Sep 17 00:00:00 2001 From: Thomas Zajac Date: Fri, 11 Oct 2024 15:36:11 +0200 Subject: [PATCH] Return storage alias in dataset information service response (#3) --- openapi.yaml | 6 ++++++ src/dins/core/information_service.py | 1 + src/dins/core/models.py | 5 +++++ tests/test_typical_journey.py | 14 +++++++++++--- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 279b09b..2842fee 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -53,10 +53,16 @@ components: exclusiveMinimum: 0.0 title: Size type: integer + storage_alias: + description: Alias of the storage location where the corresponding file + data resides in permanent storage. + title: Storage Alias + type: string required: - accession - size - sha256_hash + - storage_alias title: FileInformation type: object HTTPValidationError: diff --git a/src/dins/core/information_service.py b/src/dins/core/information_service.py index 5768af3..acff57f 100644 --- a/src/dins/core/information_service.py +++ b/src/dins/core/information_service.py @@ -88,6 +88,7 @@ async def register_file_information( accession=file.file_id, size=file.decrypted_size, sha256_hash=file.decrypted_sha256, + storage_alias=file.s3_endpoint_alias, ) file_id = file_information.accession diff --git a/src/dins/core/models.py b/src/dins/core/models.py index 4ade7b5..9571de5 100644 --- a/src/dins/core/models.py +++ b/src/dins/core/models.py @@ -40,6 +40,11 @@ class FileInformation(FileAccession): description="SHA256 hash of the unencrypted file content encoded as hexadecimal" " values as produced by hashlib.hexdigest().", ) + storage_alias: str = Field( + default=..., + description="Alias of the storage location where the corresponding file data resides" + " in permanent storage.", + ) class DatasetFileAccessions(BaseModel): diff --git a/tests/test_typical_journey.py b/tests/test_typical_journey.py index f789c01..84f5aae 100644 --- a/tests/test_typical_journey.py +++ b/tests/test_typical_journey.py @@ -80,14 +80,17 @@ ) INCOMING_FILE_PAYLOAD_2 = INCOMING_FILE_PAYLOAD.model_copy( - update={"file_id": FILE_ID_2} + update={"file_id": FILE_ID_2, "s3_endpoint_alias": "test-node-2"} ) INCOMING_FILE_PAYLOAD_3 = INCOMING_FILE_PAYLOAD.model_copy( - update={"file_id": FILE_ID_3} + update={"file_id": FILE_ID_3, "s3_endpoint_alias": "test-node-3"} ) FILE_INFORMATION = models.FileInformation( - accession=FILE_ID_1, sha256_hash=DECRYPTED_SHA256, size=DECRYPTED_SIZE + accession=FILE_ID_1, + sha256_hash=DECRYPTED_SHA256, + size=DECRYPTED_SIZE, + storage_alias="test-node", ) pytestmark = pytest.mark.asyncio() @@ -227,11 +230,13 @@ async def test_dataset_information_journey( "accession": FILE_ID_1, "size": DECRYPTED_SIZE, "sha256_hash": DECRYPTED_SHA256, + "storage_alias": "test-node", }, { "accession": FILE_ID_2, "size": DECRYPTED_SIZE, "sha256_hash": DECRYPTED_SHA256, + "storage_alias": "test-node-2", }, ] @@ -256,16 +261,19 @@ async def test_dataset_information_journey( "accession": FILE_ID_1, "size": DECRYPTED_SIZE, "sha256_hash": DECRYPTED_SHA256, + "storage_alias": "test-node", }, { "accession": FILE_ID_2, "size": DECRYPTED_SIZE, "sha256_hash": DECRYPTED_SHA256, + "storage_alias": "test-node-2", }, { "accession": FILE_ID_3, "size": DECRYPTED_SIZE, "sha256_hash": DECRYPTED_SHA256, + "storage_alias": "test-node-3", }, ]