Skip to content

Commit 28da864

Browse files
committed
get validation result file from minio
1 parent a7f3601 commit 28da864

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

app/utils/minio_utils.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,52 @@ def update_validation_status_in_minio(crate_id: str, validation_status: str) ->
109109
raise
110110

111111

112+
def get_validation_status_from_minio(crate_id: str) -> dict | str:
113+
"""
114+
Checks for the existence of a validation report for the given RO-Crate in the MinIO bucket.
115+
Returns validation message if it exists, or notification that it is missing if not.
116+
117+
:param crate_id: The ID of the RO-Crate in MinIO
118+
:return validation_status: Either the validation status, or note that this does not exist
119+
:raises S3Error: If an error occurs during the MinIO operation
120+
:raises ValueError: If the required environment variables are not set
121+
:raises Exception: If an unexpected error occurs
122+
123+
"""
124+
125+
try:
126+
minio_client, bucket_name = get_minio_client_and_bucket()
127+
128+
# The object in MinIO is <crate_id>/validation_status.txt
129+
object_name = f"{crate_id}/validation_status.txt"
130+
131+
logging.info(f"Getting object {object_name}")
132+
133+
response = minio_client.get_object(
134+
bucket_name,
135+
object_name,
136+
)
137+
138+
validation_message = json.loads(response.data.decode())
139+
response.close()
140+
response.release_conn()
141+
142+
except S3Error as s3_error:
143+
logging.error(f"MinIO S3 Error: {s3_error}")
144+
raise
145+
146+
except ValueError as value_error:
147+
logging.error(f"Configuration Error: {value_error}")
148+
raise
149+
150+
except Exception as e:
151+
logging.error(f"Unexpected error retrieving validation status from MinIO: {e}")
152+
raise
153+
154+
else:
155+
return validation_message
156+
157+
112158
def get_minio_client_and_bucket() -> [Minio, str]:
113159
"""
114160
Initialises the MinIO client and retrieves the bucket name from environment variables.

0 commit comments

Comments
 (0)