Skip to content

Commit

Permalink
Fixed time precision issues
Browse files Browse the repository at this point in the history
brettforbes committed Jan 27, 2024
1 parent de291fd commit 5630568
Showing 4 changed files with 34 additions and 101 deletions.
8 changes: 4 additions & 4 deletions stixorm/module/orm/export_object.py
Original file line number Diff line number Diff line change
@@ -44,15 +44,15 @@ def convert_ans_to_stix(query, answer_iterator, r_tx, import_type: ImportType):
"""
res = convert_ans_to_res(answer_iterator, r_tx, import_type)
path = pathlib.Path(__file__).parent.joinpath("export_test.json")
with open(str(path), 'w') as outfile:
json.dump(res, outfile)
# with open(str(path), 'w') as outfile:
# json.dump(res, outfile)
logger.debug(f'got res, now for stix')
stix_dict = convert_res_to_stix(res, import_type)
logger.debug((f'got stix now for object'))
logger.debug("=========================================")
path2 = pathlib.Path(__file__).parent.joinpath("export_test2.json")
with open(str(path2), 'w') as outfile:
json.dump(stix_dict, outfile)
# with open(str(path2), 'w') as outfile:
# json.dump(stix_dict, outfile)
json_object = json.dumps(stix_dict, indent=4)
logger.debug(json_object)
logger.debug("=========================================")
93 changes: 0 additions & 93 deletions stixorm/module/orm/export_test.json

This file was deleted.

7 changes: 5 additions & 2 deletions stixorm/module/orm/export_utilities.py
Original file line number Diff line number Diff line change
@@ -180,8 +180,11 @@ def process_props(props_obj):
prop = {"typeql": a.get_type().get_label().name}
if a.is_datetime():
nt_obj = a.get_value()
dt_obj = nt_obj.astimezone(timezone.utc)
prop["value"] = dt_obj.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
#dt_obj = nt_obj.astimezone(timezone.utc)
dt = nt_obj.strftime("%Y-%m-%dT%H:%M:%S.%f")
millisecs = int(round(nt_obj.microsecond/1000))
dt_split = dt.split('.')
prop["value"] = dt_split[0] + "." + str(millisecs) + "Z"
prop['datetime'] = True
elif a.is_string():
temp_string = a.get_value()
27 changes: 25 additions & 2 deletions try_refactor.py
Original file line number Diff line number Diff line change
@@ -58,7 +58,19 @@
test_id = "identity--f431f809-377b-45e0-aa1c-6a4751cae5ff"
marking_id = "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da"
file_id = 'file--364fe3e5-b1f4-5ba3-b951-ee5983b3538d'

comp_ident = {
"type": "identity",
"spec_version": "2.1",
"id": "identity--c90a815e-46ee-4e05-9a6e-20daf7b5348d",
"created": "2024-01-27T02:28:18.780Z",
"modified": "2024-01-27T02:28:18.780Z",
"name": "Example Company",
"description": "An Example Organisation",
"identity_class": "organization",
"sectors": [
"technology"
]
}

def test_generate_docs():
print("================================================================================")
@@ -1896,6 +1908,16 @@ def _get_objects_tql(obj, properties, embedded=[], sub_prop=[], import_type=impo
return match + value + get


def test_time():
typedb_sink = TypeDBSink(connection, True, import_type)
typedb_source = TypeDBSource(connection)
result = typedb_sink.add([comp_ident])
returned = typedb_source.get(comp_ident["id"])
ret = json.loads(returned.serialize())
print(f" created in {comp_ident['created']}")
print(f" created out {ret['created']}")
print(returned.serialize(pretty=True))



##############################################################################
@@ -2012,7 +2034,7 @@ def _get_objects_tql(obj, properties, embedded=[], sub_prop=[], import_type=impo
#check_dir_ids2(osthreat)
#check_dir_ids(path1)
#check_dir(path1)
load_file(incident_test + "/evidence.json")
#load_file(incident_test + "/evidence.json")
#test_delete(data_path+file1)
#test_get(stid1)
#test_get_delete(incident)
@@ -2039,3 +2061,4 @@ def _get_objects_tql(obj, properties, embedded=[], sub_prop=[], import_type=impo
#try_subgraph_get(reports + poison)
#try_nodes_and_edges(incident_test + "/evidence.json")
#test_get_objects()
test_time()

0 comments on commit 5630568

Please sign in to comment.