From fea7b071349d91f85404237283a7377ef813aca2 Mon Sep 17 00:00:00 2001 From: Terrtia Date: Mon, 5 Aug 2019 09:46:56 +0200 Subject: [PATCH] chg: [api] add api versioning --- doc/README.md | 36 ++++++++++++------------ var/www/modules/restApi/Flask_restApi.py | 18 ++++++------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/doc/README.md b/doc/README.md index 3c047e6e..ca7b8e75 100644 --- a/doc/README.md +++ b/doc/README.md @@ -27,7 +27,7 @@ curl --header "Authorization: YOUR_API_KEY" --header "Content-Type: application/ ## Item management -### Get item: `api/get/item/default/` +### Get item: `api/v1/get/item/default/` #### Description Get item default info. @@ -92,7 +92,7 @@ curl https://127.0.0.1:7000/api/get/item/default/submitted/2019/07/26/3efb8a79-0 -### Get item content: `api/get/item/content/` +### Get item content: `api/v1/get/item/content/` #### Description Get a specific item content. @@ -141,7 +141,7 @@ curl https://127.0.0.1:7000/api/get/item/content/submitted/2019/07/26/3efb8a79-0 -### Get item content: `api/get/item/tag/` +### Get item content: `api/v1/get/item/tag/` #### Description Get all tags from an item. @@ -164,7 +164,7 @@ Get all tags from an item. #### Example ``` -curl https://127.0.0.1:7000/api/get/item/tag/submitted/2019/07/26/3efb8a79-08e9-4776-94ab-615eb370b6d4.gz --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" +curl https://127.0.0.1:7000/api/v1/get/item/tag/submitted/2019/07/26/3efb8a79-08e9-4776-94ab-615eb370b6d4.gz --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" ``` #### Expected Success Response @@ -197,7 +197,7 @@ curl https://127.0.0.1:7000/api/get/item/tag/submitted/2019/07/26/3efb8a79-08e9- -### Advanced Get item: `api/get/item` +### Advanced Get item: `api/v1/get/item` #### Description Get item. Filter requested field. @@ -259,7 +259,7 @@ Get item. Filter requested field. #### Example ``` -curl https://127.0.0.1:7000/api/get/item --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST +curl https://127.0.0.1:7000/api/v1/get/item --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST ``` #### input.json Example @@ -306,7 +306,7 @@ curl https://127.0.0.1:7000/api/get/item --header "Authorization: iHc1_ChZxj1aXm -### add item tags: `api/add/item/tag` +### add item tags: `api/v1/add/item/tag` #### Description Add tags to an item. @@ -337,7 +337,7 @@ Add tags to an item. #### Example ``` -curl https://127.0.0.1:7000/api/import/item --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST +curl https://127.0.0.1:7000/api/v1/import/item --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST ``` #### input.json Example @@ -380,7 +380,7 @@ curl https://127.0.0.1:7000/api/import/item --header "Authorization: iHc1_ChZxj1 -### Delete item tags: `api/delete/item/tag` +### Delete item tags: `api/v1/delete/item/tag` #### Description Delete tags from an item. @@ -407,7 +407,7 @@ Delete tags from an item. #### Example ``` -curl https://127.0.0.1:7000/api/delete/item/tag --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X DELETE +curl https://127.0.0.1:7000/api/v1/delete/item/tag --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X DELETE ``` #### input.json Example @@ -452,7 +452,7 @@ curl https://127.0.0.1:7000/api/delete/item/tag --header "Authorization: iHc1_Ch ## Tag management -### Get all AIL tags: `api/get/tag/all` +### Get all AIL tags: `api/v1/get/tag/all` #### Description Get all tags used in AIL. @@ -465,7 +465,7 @@ Get all tags used in AIL. - *list* #### Example ``` -curl https://127.0.0.1:7000/api/get/tag/all --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" +curl https://127.0.0.1:7000/api/v1/get/tag/all --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" ``` #### Expected Success Response @@ -506,7 +506,7 @@ curl https://127.0.0.1:7000/api/get/tag/all --header "Authorization: iHc1_ChZxj1 -### Get tag metadata: `api/get/tag/metadata/` +### Get tag metadata: `api/v1/get/tag/metadata/` #### Description Get tag metadata. @@ -531,7 +531,7 @@ Get tag metadata. - *str - YYMMDD* #### Example ``` -curl https://127.0.0.1:7000/api/get/tag/metadata/infoleak:submission=\"manual\" --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" +curl https://127.0.0.1:7000/api/v1/get/tag/metadata/infoleak:submission=\"manual\" --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" ``` #### Expected Success Response @@ -559,7 +559,7 @@ curl https://127.0.0.1:7000/api/get/tag/metadata/infoleak:submission=\"manual\" -### Import item (currently: text only): `api/import/item` +### Import item (currently: text only): `api/v1/import/item` #### Description Allows users to import new items. asynchronous function. @@ -595,7 +595,7 @@ Allows users to import new items. asynchronous function. #### Example ``` -curl https://127.0.0.1:7000/api/import/item --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST +curl https://127.0.0.1:7000/api/v1/import/item --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST ``` #### input.json Example @@ -632,7 +632,7 @@ curl https://127.0.0.1:7000/api/import/item --header "Authorization: iHc1_ChZxj1 -### GET Import item info: `api/import/item/` +### GET Import item info: `api/v1/import/item/` #### Description @@ -661,7 +661,7 @@ Get import status and all items imported by uuid #### Example ``` -curl -k https://127.0.0.1:7000/api/import/item/b20a69f1-99ad-4cb3-b212-7ce24b763b50 --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" +curl -k https://127.0.0.1:7000/api/v1/import/item/b20a69f1-99ad-4cb3-b212-7ce24b763b50 --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" ``` #### Expected Success Response diff --git a/var/www/modules/restApi/Flask_restApi.py b/var/www/modules/restApi/Flask_restApi.py index f2c6f64a..489af778 100644 --- a/var/www/modules/restApi/Flask_restApi.py +++ b/var/www/modules/restApi/Flask_restApi.py @@ -156,7 +156,7 @@ def one(): # } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/get/item", methods=['GET', 'POST']) +@restApi.route("api/v1/get/item", methods=['GET', 'POST']) @token_required('admin') def get_item_id(): if request.method == 'POST': @@ -166,7 +166,7 @@ def get_item_id(): else: return 'description API endpoint' -@restApi.route("api/get/item/default/", methods=['GET']) +@restApi.route("api/v1/get/item/default/", methods=['GET']) @token_required('admin') def get_item_id_basic(item_id): """ @@ -227,7 +227,7 @@ def get_item_id_basic(item_id): # } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/get/item/tag/", methods=['GET']) +@restApi.route("api/v1/get/item/tag/", methods=['GET']) @token_required('admin') def get_item_tag(item_id): """ @@ -287,7 +287,7 @@ def get_item_tag(item_id): # } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/add/item/tag", methods=['POST']) +@restApi.route("api/v1/add/item/tag", methods=['POST']) @token_required('admin') def add_item_tags(): """ @@ -370,7 +370,7 @@ def add_item_tags(): # } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/delete/item/tag", methods=['DELETE']) +@restApi.route("api/v1/delete/item/tag", methods=['DELETE']) @token_required('admin') def delete_item_tags(): """ @@ -447,7 +447,7 @@ def delete_item_tags(): # } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/get/item/content/", methods=['GET']) +@restApi.route("api/v1/get/item/content/", methods=['GET']) @token_required('admin') def get_item_content(item_id): """ @@ -489,7 +489,7 @@ def get_item_content(item_id): # # # # # # # # # # # # # # TAGS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/get/tag/metadata/", methods=['GET']) +@restApi.route("api/v1/get/tag/metadata/", methods=['GET']) @token_required('admin') def get_tag_metadata(tag): if not Tag.is_tag_in_all_tag(tag): @@ -525,7 +525,7 @@ def get_all_tags(): # response: {"uuid": "uuid"} # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/import/item", methods=['POST']) +@restApi.route("api/v1/import/item", methods=['POST']) @token_required('admin') def import_item(): """ @@ -624,7 +624,7 @@ def import_item(): # } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/import/item/", methods=['GET']) +@restApi.route("api/v1/import/item/", methods=['GET']) @token_required('admin') def import_item_uuid(UUID): """