Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Add '/id/delete/{session_id}' route to admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
davedittrich committed May 23, 2020
1 parent 4c5fbaa commit e1d1f23
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
36 changes: 36 additions & 0 deletions admin/app/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import shutil
import socket

import falcon
Expand All @@ -20,6 +21,41 @@ def on_get(self, req, resp):
resp.status = falcon.HTTP_200


class IDDelete(object):

def on_get(self, req, resp, session_id):
id_path = f'/id/{session_id}'
file_path = f'/files/{session_id}'
errors = []
if not (os.path.exists(id_path) or os.path.exists(file_path)):
print(f"no data found for session: {session_id}")
resp.media = {'status': 'Error',
'error': f'No data found for session {session_id}'}
resp.status = falcon.HTTP_500
else:
# If an internal server error occurred on 'upload' there may
# be something in /files but not in /id. Handle gracefully.
if os.path.exists(file_path):
try:
shutil.rmtree(file_path)
except Exception as e: # pragma: no cover
print(f'Failed to delete {file_path} because: {e}')
errors.append(str(e))
if os.path.exists(id_path):
try:
shutil.rmtree(id_path)
except Exception as e: # pragma: no cover
print(f'Failed to delete {id_path} because: {e}')
errors.append(str(e))
if bool(len(errors)):
resp.media = {'status': 'Error',
'error(s)': f'{"; ".join(errors)}'}
resp.status = falcon.HTTP_500
else:
resp.media = {'status': 'Success'}
resp.status = falcon.HTTP_200


class IDFiles(object):

def on_get(self, req, resp):
Expand Down
15 changes: 12 additions & 3 deletions admin/app/routes.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
def routes():
from .data import Endpoints, IDFiles, IDResults, IDs, Info, Logs
from .data import Endpoints, IDDelete, IDFiles, IDResults, IDs, Info, Logs
p = paths()
endpoints = Endpoints()
id_delete = IDDelete()
id_files = IDFiles()
id_results = IDResults()
ids = IDs()
info = Info()
logs = Logs()
funcs = [endpoints, id_files, id_results, ids, info, logs]
funcs = [endpoints, id_delete, id_files, id_results, ids, info, logs]
return dict(zip(p, funcs))


def paths():
return ['', '/id/files', '/id/results', '/ids', '/info', '/logs/{req_id}']
return [
'',
'/id/delete/{session_id}',
'/id/files',
'/id/results',
'/ids',
'/info',
'/logs/{req_id}'
]


def version():
Expand Down
32 changes: 32 additions & 0 deletions design/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,38 @@ TO BE IMPLEMENTED
{% endapi-method-spec %}
{% endapi-method %}

{% api-method method="get" host="http://0.0.0.0" path="/api/v1/delete/:sess\_id" %}
{% api-method-summary %}
/api/v1/delete/:sess\_id
{% endapi-method-summary %}

{% api-method-description %}
Deletes files and id associated with a session.
{% endapi-method-description %}

{% api-method-spec %}
{% api-method-request %}
{% api-method-path-parameters %}
{% api-method-parameter name="sess\_id" type="string" required=true %}
Session ID
{% endapi-method-parameter %}
{% endapi-method-path-parameters %}
{% endapi-method-request %}

{% api-method-response %}
{% api-method-response-example httpCode=200 %}
{% api-method-response-example-description %}

{% endapi-method-response-example-description %}

```
TO BE IMPLEMENTED
```
{% endapi-method-response-example %}
{% endapi-method-response %}
{% endapi-method-spec %}
{% endapi-method %}

{% api-method method="get" host="http://0.0.0.0" path="/api/v1/tools" %}
{% api-method-summary %}
/api/v1/tools
Expand Down
17 changes: 13 additions & 4 deletions web/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ def routes():


def paths():
return ['', '/id/{session_id}/{req_id}/{tool}/{pcap}/{counter}/{filename}',
'/ids/{session_id}',
'/info', '/raw/{tool}/{counter}/{session_id}/{req_id}', '/results/{tool}/{counter}/{session_id}/{req_id}', '/status/{session_id}/{req_id}',
'/stop/{session_id}/{req_id}', '/tools', '/upload']
return [
'',
'/id/{session_id}/{req_id}/{tool}/{pcap}/{counter}/{filename}',
'/ids/{session_id}',
'/info',
'/raw/{tool}/{counter}/{session_id}/{req_id}',
'/results/{tool}/{counter}/{session_id}/{req_id}',
'/status/{session_id}/{req_id}',
'/stop/{session_id}/{req_id}',
'/tools',
'/upload'
]


def version():
return '/api/v1'

0 comments on commit e1d1f23

Please sign in to comment.