Skip to content

Commit d2c730d

Browse files
committed
add minio config to api get route
1 parent 0d4c307 commit d2c730d

2 files changed

Lines changed: 53 additions & 15 deletions

File tree

app/ro_crates/routes/get_routes.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@
55
# Copyright (c) 2025 eScience Lab, The University of Manchester
66

77
from apiflask import APIBlueprint, Schema
8-
from apiflask.fields import String
8+
from apiflask.fields import String, Boolean
9+
from marshmallow.fields import Nested
910
from flask import Response
1011

1112
from app.services.validation_service import get_ro_crate_validation_task
1213

1314
get_routes_bp = APIBlueprint("get_routes", __name__)
1415

1516

17+
class MinioConfig(Schema):
18+
endpoint = String(required=True)
19+
accesskey = String(required=True)
20+
secret = String(required=True)
21+
ssl = Boolean(required=True)
22+
bucket = String(required=True)
23+
24+
1625
class ValidateResult(Schema):
17-
minio_bucket = String(required=True)
26+
minio_config = Nested(MinioConfig, required=True)
1827
root_path = String(required=False)
1928

2029

@@ -28,7 +37,12 @@ def get_ro_crate_validation_by_id(json_data, crate_id) -> tuple[Response, int]:
2837
- **crate_id**: The RO-Crate ID. _Required_.
2938
3039
Request Body Parameters:
31-
- **minio_bucket**: The MinIO bucket containing the RO-Crate. _Required_
40+
- **minio_config**: The MinIO bucket containing the RO-Crate. _Required_
41+
- **endpoint**: Endpoint, e.g. 'localhost:9000'
42+
- **accesskey**: Access key / username
43+
- **secret**: Secret / password
44+
- **ssl**: Use SSL encryption? True/False
45+
- **bucket**: The MinIO bucket to access
3246
- **root_path**: The root path containing the RO-Crate. _Optional_
3347
3448
Returns:
@@ -38,11 +52,11 @@ def get_ro_crate_validation_by_id(json_data, crate_id) -> tuple[Response, int]:
3852
- KeyError: If required parameters (`crate_id`) are missing.
3953
"""
4054

41-
minio_bucket = json_data["minio_bucket"]
55+
minio_config = json_data["minio_config"]
4256

4357
if "root_path" in json_data:
4458
root_path = json_data["root_path"]
4559
else:
4660
root_path = None
4761

48-
return get_ro_crate_validation_task(minio_bucket, crate_id, root_path)
62+
return get_ro_crate_validation_task(minio_config, crate_id, root_path)

tests/test_api_routes.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,25 @@ def test_validate_metadata_failure(client: FlaskClient, payload: dict, status_co
200200
"crate_id, payload, status_code",
201201
[
202202
(
203-
"",{
204-
"minio_bucket": "test_bucket",
203+
"", {
204+
"minio_config": {
205+
"endpoint": "localhost:9000",
206+
"accesskey": "admin",
207+
"secret": "password123",
208+
"ssl": False,
209+
"bucket": "test_bucket"
210+
},
205211
"root_path": "base_path"
206212
}, 404
207213
),
208214
(
209-
"crate-123",{
215+
"crate-123", {
216+
"minio_config": {
217+
"endpoint": "localhost:9000",
218+
"accesskey": "admin",
219+
"secret": "password123",
220+
"ssl": False,
221+
},
210222
"root_path": "base_path"
211223
}, 422
212224
),
@@ -221,7 +233,13 @@ def test_get_validation_by_id_failures(client: FlaskClient, crate_id: str, paylo
221233
def test_get_validation_by_id_success(client):
222234
crate_id = "crate-123"
223235
payload = {
224-
"minio_bucket": "test_bucket",
236+
"minio_config": {
237+
"endpoint": "localhost:9000",
238+
"accesskey": "admin",
239+
"secret": "password123",
240+
"ssl": False,
241+
"bucket": "test_bucket"
242+
},
225243
"root_path": "base_path"
226244
}
227245

@@ -232,20 +250,26 @@ def test_get_validation_by_id_success(client):
232250

233251
assert response.status_code == 200
234252
assert response.json == {"status": "valid"}
235-
mock_get.assert_called_once_with("test_bucket", "crate-123", "base_path")
253+
mock_get.assert_called_once_with(payload["minio_config"], "crate-123", "base_path")
236254

237255

238256
def test_get_validation_by_id_missing_root_path(client):
239257
crate_id = "crate-123"
240258
payload = {
241-
"minio_bucket": "test_bucket",
259+
"minio_config": {
260+
"endpoint": "localhost:9000",
261+
"accesskey": "admin",
262+
"secret": "password123",
263+
"ssl": False,
264+
"bucket": "test_bucket"
265+
}
242266
}
243267

244268
with patch("app.ro_crates.routes.get_routes.get_ro_crate_validation_task") as mock_get:
245-
mock_get.return_value = ({"message": "Validation in progress"}, 202)
269+
mock_get.return_value = ({"status": "valid"}, 200)
246270

247271
response = client.get(f"/v1/ro_crates/{crate_id}/validation", json=payload)
248272

249-
assert response.status_code == 202
250-
assert response.json == {"message": "Validation in progress"}
251-
mock_get.assert_called_once_with("test_bucket", "crate-123", None)
273+
assert response.status_code == 200
274+
assert response.json == {"status": "valid"}
275+
mock_get.assert_called_once_with(payload["minio_config"], "crate-123", None)

0 commit comments

Comments
 (0)