Skip to content
195 changes: 162 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,155 @@

This project presents a Flask-based API for validating RO-Crates.

## Project Structure
## API

#### Request Validation of RO-Crate

<details>
<summary><code>POST</code> <code><b>v1/ro_crates/{crate_id}/validation</b></code> <code>(Request validation of RO-Crate validation in Object Store)</code></summary>

##### Path Parameters

| name | type | data type | description |
|------------|-----------|-------------------------|-----------------------------------------------------------------------|
| crate_id | required | string | RO-Crate identifer string |

##### Parameters

| name | type | data type | description |
|------------|-----------|-------------------------|-----------------------------------------------------------------------|
| root_path | optional | string | Root path which contains the RO-Crate |
| webhook_url | optional | string | Webhook to send validation result to |
| minio_config | required | dictionary | MinIO Configuration Details |

`minio_config`
> | name | type | data type | description |
> |------------|-----------|-------------------------|-----------------------------------------------------------------------|
> | endpoint | required | string | MinIO endpoint |
> | accesskey | required | string | MinIO access key or username |
> | secret | required | string | MinIO secret or password |
> | ssl | required | boolean | Use SSL encryption for MinIO access? |
> | bucket | required | string | MinIO bucket containing RO-Crate |

##### Responses

| http code | content-type | response |
|---------------|-----------------------------------|---------------------------------------------------------------------|
| `202` | `application/json` | `{"message": "Validation in progress"}` |
| `400` | `application/json` | `{"message": "No RO-Crate with prefix: <crate_id>"}` |
| `500` | `application/json` | `{"message": "Internal server errors"}` |

```javascript
curl -X 'POST' \
'http://localhost:5001/v1/ro_crates/<crate_id>/validation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"minio_config": {
"accesskey": "<key>",
"bucket": "ro-crates",
"endpoint": "minio:9000",
"secret": "<secret>",
"ssl": false
},
"profile_name": "<profile>",
"webhook_url": "<webhook>"
}'
```
app/
├── ro_crates/
│ ├── routes/
│ │ ├── __init__.py # Registers blueprints
│ │ └── post_routes.py # POST API routes
│ └── __init__.py
├── services/
│ ├── logging_service.py # Centralised logging
│ └── validation_service.py # Queue RO-Crates for validation
├── tasks/
│ └── validation_tasks.py # Validate RO-Crates
├── utils/
│ ├── config.py # Configuration
│ ├── minio_utils.py # Methods for interacting with MinIO
│ └── webhook_utils.py # Methods for sending webhooks

</details>


#### Get RO-Crate Validation Result

<details>
<summary><code>GET</code> <code><b>v1/ro_crates/{crate_id}/validation</b></code> <code>(Obtain RO-Crate validation result from Object Store)</code></summary>

##### Path Parameters

| name | type | data type | description |
|------------|-----------|-------------------------|-----------------------------------------------------------------------|
| crate_id | required | string | RO-Crate identifer string |

##### Parameters

| name | type | data type | description |
|------------|-----------|-------------------------|-----------------------------------------------------------------------|
| root_path | optional | string | Root path which contains the RO-Crate |
| minio_config | required | dictionary | MinIO Configuration Details |

`minio_config`
> | name | type | data type | description |
> |------------|-----------|-------------------------|-----------------------------------------------------------------------|
> | endpoint | required | string | MinIO endpoint |
> | accesskey | required | string | MinIO access key or username |
> | secret | required | string | MinIO secret or password |
> | ssl | required | boolean | Use SSL encryption for MinIO access? |
> | bucket | required | string | MinIO bucket containing RO-Crate |

##### Responses

| http code | content-type | response |
|---------------|-----------------------------------|---------------------------------------------------------------------|
| `200` | `application/json` | `Successful Validation` |
| `422` | `application/json` | `Error: Details of Validation Error` |
| `404` | `application/json` | `Not found` |

##### Example cURL

```javascript
curl -X 'GET' \
'http://localhost:5001/v1/ro_crates/<crate_id>/validation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"minio_config": {
"accesskey": "<key>",
"bucket": "ro-crates",
"endpoint": "minio:9000",
"secret": "<secret>",
"ssl": false
}
}'
```

</details>

#### Validate RO-Crate Metadata

<details>
<summary><code>POST</code> <code><b>v1/ro_crates/validate_metadata</b></code> <code>(validates submitted RO-Crate Metadata)</code></summary>

##### Parameters

| name | type | data type | description |
|------------|-----------|-------------------------|-----------------------------------------------------------------------|
| crate_json | required | string | RO-Crate metadata, stored as a single string |
| profile_name | optional | string | RO-Crate profile to validate against |


##### Responses

| http code | content-type | response |
|---------------|-----------------------------------|---------------------------------------------------------------------|
| `200` | `application/json` | `Successful Validation` |
| `422` | `application/json` | `Error: Details of Validation Error` |

##### Example cURL

```javascript
curl -X 'POST' \
'http://localhost:5001/v1/ro_crates/validate_metadata' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"crate_json": "{'\''test1'\'':'\''test2'\''}"
}'
```

</details>


## Setting up the project

### Prerequisites
Expand Down Expand Up @@ -68,22 +197,22 @@ For testing locally developed containers use the alternate Docker Compose file:
docker compose --file docker-compose-develop.yml up --build
```

## Example Usage
### Project Structure

Submission of validation of RO-Crate with the ID of `ro_crate_1`. No webhook is used here:
```bash
curl -X 'POST' \
'http://localhost:5001/ro_crates/v1/ro_crate_1/validation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{}'
```

Retrieval of validation result for RO-Crate `ro_crate_1`:
```bash
curl -X 'GET' \
'http://localhost:5001/ro_crates/v1/ro_crate_1/validation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{}'
```
app/
├── ro_crates/
│ ├── routes/
│ │ ├── __init__.py # Registers blueprints
│ │ └── post_routes.py # POST API routes
│ └── __init__.py
├── services/
│ ├── logging_service.py # Centralised logging
│ └── validation_service.py # Queue RO-Crates for validation
├── tasks/
│ └── validation_tasks.py # Validate RO-Crates
├── utils/
│ ├── config.py # Configuration
│ ├── minio_utils.py # Methods for interacting with MinIO
│ └── webhook_utils.py # Methods for sending webhooks
```
4 changes: 2 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
celery==5.5.3
minio==7.2.16
requests==2.32.4
Flask==3.0.3
requests==2.32.5
Flask==3.1.2
Werkzeug==3.1.3
redis==6.4.0
python-dotenv==1.1.1
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ colorlog==6.9.0
# via roc-validator
enum-tools==0.12.0
# via roc-validator
flask==3.0.3
flask==3.1.2
# via
# -r requirements.in
# apiflask
Expand Down Expand Up @@ -83,6 +83,7 @@ markdown-it-py==3.0.0
# via rich
markupsafe==3.0.2
# via
# flask
# jinja2
# werkzeug
marshmallow==4.0.0
Expand Down Expand Up @@ -135,7 +136,7 @@ rdflib[html]==7.1.4
# roc-validator
redis==6.4.0
# via -r requirements.in
requests==2.32.4
requests==2.32.5
# via
# -r requirements.in
# requests-cache
Expand Down