NASA-IMPACT / HLS-Transfer-Catalog

Data Catalog to manage HLS S2 transfers from ESA to NASA
Apache License 2.0
2 stars 1 forks source link

RESTful API #6

Closed NISH1001 closed 2 years ago

NISH1001 commented 2 years ago

This PR introduces CRUD-based REST APIs for the catalog database.

This server acts as a storage server to track the progress of files being transferred by the orchestration layer (cc: @smarru ). The orchestration layer and the UI layer will be able to interact with this server through REST APIs.

This iteration of the catalogue server consists of 8 major APIs with simple JWT-based token authentication (cc: @ub0005 )

These APIs so far are listed below (copied verbose from README of this same PR):

1) /catalogue/bulk/csv - POST, Upload CSV

Enables anyone to upload csv of specific format to populate the catalogue table in bulk.

curl --location --request POST 'http://127.0.0.1:5000/catalogue/bulk/csv/' \
--header 'token: <token>' \
--form 'csv=@"/Users/udaykumarbommala/Downloads/test.csv"

2) /catalogue/ - GET, all items

Enables anyone to fetch catalogue metadata items. We can use 2 query params to filter the result:

curl --location --request GET 'http://127.0.0.1:5000/catalogue/?transfer_status=NOT_STARTED' \
--header 'token: <token>'

3) /catalogue/uuid/ - GET single item

curl --location --request GET 'http://127.0.0.1:5000/catalogue/6a1f5438-50d1-4e02-a11b-52f9018da69f/' \
--header 'token: <token>'

4) /catalogue/ - POST single item

This is used to create a single catalogue item for the database

curl --location --request POST 'http://127.0.0.1:5000/catalogue/' \
--header 'token: <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "uuid": "8e547de43cbf43a3a50dffb81d255bb2",
    "transfer_status": "failed",
    "name": "test",
    "checksum_algorithm": "test",
    "checksum_value": "test"
}'

Note: The json data should have name, checksum_value and checksum_algorithm mandatory. If uuid is provided in the json data, it will be re-used. If not, new uuid will be created.

5) /catalogue/uuid/ - PATCH single item

Used for updating a specific catalogue item referenced by the given uuid.

curl --location --request PATCH 'http://127.0.0.1:5000/catalogue/c266dc7b9fad4d64aaa7d103b6f0af09/' \
--header 'token: <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "test",
    "transfer_status": "failed"
}'

6) /catalogue/uuid/ - DELETE single item

Delets a given catalogue item

curl --location --request DELETE 'http://127.0.0.1:5000/catalogue/8e547de43cbf43a3a50dffb81d255bb2/' \
--header 'token: <token>'

7) /catalogue/bulk/ - PATCH multiple items

Used for updating multiple items in a single request.

curl --location --request PATCH 'http://127.0.0.1:5000/catalogue/bulk/' \
--header 'token: <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "abcdef": {}
}'

Here the json data posted is of the structure:

{
    <uuid1>: {<json>},
    <uuid2>: {<json>},
}

8) /auth/login/ - POST Generate JWT Token

Used for generating JWT token based on user credentails

curl --location --request POST 'http://127.0.0.1:5000/auth/login/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "username",
    "password": "password"
}'

For setting up the server, please refer to the README

TODO (cc: @ub0005 ) :

xhagrg commented 2 years ago

LGTM.