Skip to content

Commit ada6e7d

Browse files
committed
fixed dates not stixed
1 parent 18c5b00 commit ada6e7d

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

backend/app.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import secrets
1212
from base64 import b64encode, b64decode
13+
import datetime
1314

1415
DISARM_MATRIX_PATH = path.join(path.dirname(__file__), 'data', 'DISARM.json')
1516
DEFAULT_PAGE = 1
@@ -365,14 +366,22 @@ def top_locations():
365366
def stix2_objects_endpoint():
366367
# Fetch all the STIX2 objects stored in the database
367368
newer_than = request.args.get('newer_than', default=None, type=str)
369+
newer_than = datetime.datetime.fromisoformat(newer_than.rstrip("Z") + "+00:00") if newer_than else None
370+
app.logger.info(f"Fetching STIX2 objects newer than {newer_than}")
368371
# Fetch the incidents from the database
369372
if newer_than:
370373
total_objects = stix2_objects.count_documents({"modified": {"$gt": newer_than}})
371374
objects_cursor = stix2_objects.find({"modified": {"$gt": newer_than}})
372375
else:
373376
total_objects = stix2_objects.count_documents({})
374377
objects_cursor = stix2_objects.find({})
375-
return build_paginated_json(request, objects_cursor, total_objects), 200
378+
379+
objects = list(objects_cursor)
380+
# Remove the _id field from the documents
381+
for object in objects:
382+
object.pop('_id', None)
383+
bundle = Bundle(objects=objects, allow_custom=True)
384+
return bundle.serialize(), 200, {'Content-Type': 'application/json'}
376385

377386

378387
'''

backend/app_readonly.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import secrets
1212
from base64 import b64encode, b64decode
13+
import datetime
1314

1415
DISARM_MATRIX_PATH = path.join(path.dirname(__file__), 'data', 'DISARM.json')
1516
DEFAULT_PAGE = 1
@@ -204,14 +205,22 @@ def threat_actor(threat_actor_id):
204205
def stix2_objects_endpoint():
205206
# Fetch all the STIX2 objects stored in the database
206207
newer_than = request.args.get('newer_than', default=None, type=str)
208+
newer_than = datetime.datetime.fromisoformat(newer_than.rstrip("Z") + "+00:00") if newer_than else None
209+
app.logger.info(f"Fetching STIX2 objects newer than {newer_than}")
207210
# Fetch the incidents from the database
208211
if newer_than:
209212
total_objects = stix2_objects.count_documents({"modified": {"$gt": newer_than}})
210213
objects_cursor = stix2_objects.find({"modified": {"$gt": newer_than}})
211214
else:
212215
total_objects = stix2_objects.count_documents({})
213216
objects_cursor = stix2_objects.find({})
214-
return build_paginated_json(request, objects_cursor, total_objects), 200
217+
218+
objects = list(objects_cursor)
219+
# Remove the _id field from the documents
220+
for object in objects:
221+
object.pop('_id', None)
222+
bundle = Bundle(objects=objects, allow_custom=True)
223+
return bundle.serialize(), 200, {'Content-Type': 'application/json'}
215224

216225
@app.route('/threat-actors/top', methods=['GET'])
217226
def top_threat_actors():

public-api/app.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,11 @@ def incidents():
5151
response = requests.get(BACKEND_ROOT + 'stix2-objects', params={'newer_than': newer_than})
5252
if response.status_code != 200:
5353
return jsonify({'message': 'Error getting incidents from the DISINFOX backend server'}), 500
54-
response_json = response.json()
55-
incidents = response_json.get('objects', [])
56-
next_link = response_json['links'].get('next', None)
57-
# Gather all the incidents from the paginated responses
58-
while next_link:
59-
response = requests.get(next_link)
60-
if response.status_code != 200:
61-
return jsonify({'message': 'Error getting incidents from the DISINFOX backend server'}), 500
62-
response_json = response.json()
63-
incidents.extend(response_json['objects'])
64-
next_link = response_json['links'].get('next', None)
65-
return jsonify({'incidents': incidents})
54+
bundle = response.json()
55+
app.logger.info("Returning incidents " + str(bundle) + " to the client")
56+
if 'objects' not in bundle:
57+
return jsonify({}), 200, {'Content-Type': 'application/json'}
58+
return jsonify(bundle), 200, {'Content-Type': 'application/json'}
6659

6760

6861

0 commit comments

Comments
 (0)