Skip to content

Commit

Permalink
chg: [API] add Tracker documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Sep 13, 2019
1 parent fb35be7 commit 5734205
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 25 deletions.
81 changes: 59 additions & 22 deletions doc/README.md
Expand Up @@ -748,10 +748,13 @@ curl https://127.0.0.1:7000/api/v1/get/cryptocurrency/bitcoin/item --header "Aut



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

#### Description
Add term tracker
Create a new tracker (word, set, regex).

You need to use a regex if you want to use one of the following special characters [<>~!?@#$%^&*|()_-+={}\":;,.\'\n\r\t]/\\


**Method** : `POST`

Expand Down Expand Up @@ -788,13 +791,24 @@ Add term tracker

#### Example
```
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
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
```

#### input.json Example
```json
{

"term": "test test2 test3",
"type": "set",
"nb_words": 2,
"tags": [
"mytags",
"othertags"
],
"mails": [
"mail@mail.test",
"othermail@mail.test"
],
"level": 1
}
```

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

```json
{

"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8"
}
```

#### Expected Fail Response
**HTTP Status Code** : `400`
**HTTP Status Code** : 400

```json

{"status": "error", "reason": "Term not provided"}
{"status": "error", "reason": "Term type not provided"}
{"status": "error", "reason": "special character not allowed", "message": "Please use a regex or remove all special characters"}
{"status": "error", "reason": "Incorrect type"}
```
**HTTP Status Code** : 409

```json
{"status": "error", "reason": "Term already tracked"}
```



### Delete term tracker: `api/v1/delete/tracker/term`<a name="delete_term_tracker"></a>
### Delete term tracker: `api/v1/delete/tracker`<a name="delete_tracker"></a>

#### Description
Delete term tracker
Delete a tracker

**Method** : `DELETE`

Expand All @@ -837,13 +858,13 @@ Delete term tracker

#### Example
```
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
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
```

#### input.json Example
```json
{

"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8"
}
```

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

```json
{

"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8"
}
```

#### Expected Fail Response
**HTTP Status Code** : `400`

```json
{"status": "error", "reason": "Invalid uuid"}

```

**HTTP Status Code** : `404`

```json
({"status": "error", "reason": "Unknown uuid"}

```


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

#### Description
Delete term tracker
Get tracked items by date-range

**Method** : `POST`

Expand Down Expand Up @@ -904,29 +930,40 @@ Delete term tracker

#### Example
```
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
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
```

#### input.json Example
```json
{

"uuid": "6a16b06e-38e5-41e1-904d-3960610647e8",
"date_from": "20190823",
"date_to": "20190829",
"items": [
{
"id": "submitted/2019/08/25/4f929998-3921-4be3-b448-be3bf1722d6b.gz",
"date": 20190825,
"tags": [
"infoleak:automatic-detection=\"credential\"",
"mytags",
"othertags",
]
}
]
}
```

#### Expected Success Response
**HTTP Status Code** : `200`
**HTTP Status Code** : `400`

```json
{
{"status": "error", "reason": "Invalid uuid"}

}
```

#### Expected Fail Response
**HTTP Status Code** : `400`
**HTTP Status Code** : `404`

```json
({"status": "error", "reason": "Unknown uuid"}

```

Expand Down
6 changes: 3 additions & 3 deletions var/www/modules/restApi/Flask_restApi.py
Expand Up @@ -317,7 +317,7 @@ def get_all_tags():
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # TRACKER # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@restApi.route("api/v1/add/tracker/term", methods=['POST'])
@restApi.route("api/v1/add/tracker", methods=['POST'])
@token_required('analyst')
def add_tracker_term():
data = request.get_json()
Expand All @@ -326,7 +326,7 @@ def add_tracker_term():
res = Term.parse_json_term_to_add(data, user_id)
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]

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

@restApi.route("api/v1/get/tracker/term/item", methods=['POST'])
@restApi.route("api/v1/get/tracker/item", methods=['POST'])
@token_required('analyst')
def get_tracker_term_item():
data = request.get_json()
Expand Down

0 comments on commit 5734205

Please sign in to comment.