Skip to content

Commit 5734205

Browse files
committed
chg: [API] add Tracker documentation
1 parent fb35be7 commit 5734205

File tree

2 files changed

+62
-25
lines changed

2 files changed

+62
-25
lines changed

doc/README.md

+59-22
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,13 @@ curl https://127.0.0.1:7000/api/v1/get/cryptocurrency/bitcoin/item --header "Aut
748748

749749

750750

751-
### Add term tracker: `api/v1/add/tracker/term`<a name="add_term_tracker"></a>
751+
### Add term tracker: `api/v1/add/tracker`<a name="add_tracker"></a>
752752

753753
#### Description
754-
Add term tracker
754+
Create a new tracker (word, set, regex).
755+
756+
You need to use a regex if you want to use one of the following special characters [<>~!?@#$%^&*|()_-+={}\":;,.\'\n\r\t]/\\
757+
755758

756759
**Method** : `POST`
757760

@@ -788,13 +791,24 @@ Add term tracker
788791

789792
#### Example
790793
```
791-
curl https://127.0.0.1:7000/api/v1/add/tracker/term --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST
794+
curl https://127.0.0.1:7000/api/v1/add/tracker --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST
792795
```
793796

794797
#### input.json Example
795798
```json
796799
{
797-
800+
"term": "test test2 test3",
801+
"type": "set",
802+
"nb_words": 2,
803+
"tags": [
804+
"mytags",
805+
"othertags"
806+
],
807+
"mails": [
808+
"mail@mail.test",
809+
"othermail@mail.test"
810+
],
811+
"level": 1
798812
}
799813
```
800814

@@ -803,24 +817,31 @@ curl https://127.0.0.1:7000/api/v1/add/tracker/term --header "Authorization: iHc
803817

804818
```json
805819
{
806-
820+
"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8"
807821
}
808822
```
809823

810824
#### Expected Fail Response
811-
**HTTP Status Code** : `400`
825+
**HTTP Status Code** : 400
812826

813827
```json
814-
828+
{"status": "error", "reason": "Term not provided"}
829+
{"status": "error", "reason": "Term type not provided"}
830+
{"status": "error", "reason": "special character not allowed", "message": "Please use a regex or remove all special characters"}
831+
{"status": "error", "reason": "Incorrect type"}
815832
```
833+
**HTTP Status Code** : 409
816834

835+
```json
836+
{"status": "error", "reason": "Term already tracked"}
837+
```
817838

818839

819840

820-
### Delete term tracker: `api/v1/delete/tracker/term`<a name="delete_term_tracker"></a>
841+
### Delete term tracker: `api/v1/delete/tracker`<a name="delete_tracker"></a>
821842

822843
#### Description
823-
Delete term tracker
844+
Delete a tracker
824845

825846
**Method** : `DELETE`
826847

@@ -837,13 +858,13 @@ Delete term tracker
837858

838859
#### Example
839860
```
840-
curl https://127.0.0.1:7000/api/v1/add/tracker/term --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST
861+
curl https://127.0.0.1:7000/api/v1/delete/tracker --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST
841862
```
842863

843864
#### input.json Example
844865
```json
845866
{
846-
867+
"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8"
847868
}
848869
```
849870

@@ -852,25 +873,30 @@ curl https://127.0.0.1:7000/api/v1/add/tracker/term --header "Authorization: iHc
852873

853874
```json
854875
{
855-
876+
"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8"
856877
}
857878
```
858879

859880
#### Expected Fail Response
860881
**HTTP Status Code** : `400`
861882

862883
```json
884+
{"status": "error", "reason": "Invalid uuid"}
863885

864886
```
865887

888+
**HTTP Status Code** : `404`
866889

890+
```json
891+
({"status": "error", "reason": "Unknown uuid"}
867892

893+
```
868894

869895

870-
### Delete term tracker: `api/v1/delete/tracker/term/item`<a name="delete_term_tracker"></a>
896+
### Delete term tracker: `api/v1/get/tracker/item`<a name="get_tracker_item"></a>
871897

872898
#### Description
873-
Delete term tracker
899+
Get tracked items by date-range
874900

875901
**Method** : `POST`
876902

@@ -904,29 +930,40 @@ Delete term tracker
904930

905931
#### Example
906932
```
907-
curl https://127.0.0.1:7000/api/v1/add/tracker/term --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST
933+
curl https://127.0.0.1:7000/api/v1/get/tracker/item --header "Authorization: iHc1_ChZxj1aXmiFiF1mkxxQkzawwriEaZpPqyTQj " -H "Content-Type: application/json" --data @input.json -X POST
908934
```
909935

910936
#### input.json Example
911937
```json
912938
{
913-
939+
"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8",
940+
"date_from": "20190823",
941+
"date_to": "20190829",
942+
"items": [
943+
{
944+
"id": "submitted/2019/08/25/4f929998-3921-4be3-b448-be3bf1722d6b.gz",
945+
"date": 20190825,
946+
"tags": [
947+
"infoleak:automatic-detection=\"credential\"",
948+
"mytags",
949+
"othertags",
950+
]
951+
}
952+
]
914953
}
915954
```
916955

917-
#### Expected Success Response
918-
**HTTP Status Code** : `200`
956+
**HTTP Status Code** : `400`
919957

920958
```json
921-
{
959+
{"status": "error", "reason": "Invalid uuid"}
922960

923-
}
924961
```
925962

926-
#### Expected Fail Response
927-
**HTTP Status Code** : `400`
963+
**HTTP Status Code** : `404`
928964

929965
```json
966+
({"status": "error", "reason": "Unknown uuid"}
930967

931968
```
932969

var/www/modules/restApi/Flask_restApi.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def get_all_tags():
317317
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
318318
# # # # # # # # # # # # # # TRACKER # # # # # # # # # # # # # # # # #
319319
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
320-
@restApi.route("api/v1/add/tracker/term", methods=['POST'])
320+
@restApi.route("api/v1/add/tracker", methods=['POST'])
321321
@token_required('analyst')
322322
def add_tracker_term():
323323
data = request.get_json()
@@ -326,7 +326,7 @@ def add_tracker_term():
326326
res = Term.parse_json_term_to_add(data, user_id)
327327
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
328328

329-
@restApi.route("api/v1/delete/tracker/term", methods=['DELETE'])
329+
@restApi.route("api/v1/delete/tracker", methods=['DELETE'])
330330
@token_required('analyst')
331331
def delete_tracker_term():
332332
data = request.get_json()
@@ -335,7 +335,7 @@ def delete_tracker_term():
335335
res = Term.parse_tracked_term_to_delete(data, user_id)
336336
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
337337

338-
@restApi.route("api/v1/get/tracker/term/item", methods=['POST'])
338+
@restApi.route("api/v1/get/tracker/item", methods=['POST'])
339339
@token_required('analyst')
340340
def get_tracker_term_item():
341341
data = request.get_json()

0 commit comments

Comments
 (0)