diff --git a/stixorm/module/orm/export_object.py b/stixorm/module/orm/export_object.py index 3fe3940..cb7eab5 100644 --- a/stixorm/module/orm/export_object.py +++ b/stixorm/module/orm/export_object.py @@ -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("=========================================") diff --git a/stixorm/module/orm/export_test.json b/stixorm/module/orm/export_test.json deleted file mode 100644 index e189a9e..0000000 --- a/stixorm/module/orm/export_test.json +++ /dev/null @@ -1,93 +0,0 @@ -[ - { - "type": "entity", - "symbol": "observed-data0", - "T_id": "0x826e80018000000000000001", - "T_name": "observed-data", - "has": [ - { - "typeql": "stix-type", - "value": "observed-data", - "datetime": false - }, - { - "typeql": "stix-id", - "value": "observed-data--bb3aaad5-accc-4e55-8375-f4b30b17c980", - "datetime": false - }, - { - "typeql": "spec-version", - "value": "2.1", - "datetime": false - }, - { - "typeql": "last-observed", - "value": "2020-10-18T14:01:01.000000Z", - "datetime": true - }, - { - "typeql": "modified", - "value": "2023-11-06T21:53:15.616000Z", - "datetime": true - }, - { - "typeql": "number-observed", - "value": 1, - "datetime": false - }, - { - "typeql": "first-observed", - "value": "2020-10-18T14:01:01.000000Z", - "datetime": true - }, - { - "typeql": "created", - "value": "2023-11-06T21:53:15.616000Z", - "datetime": true - } - ], - "relns": [ - { - "T_name": "sighting", - "T_id": "0x847080178000000000000001", - "roles": [] - }, - { - "T_name": "sighting", - "T_id": "0x847080178000000000000002", - "roles": [] - }, - { - "T_name": "obj-refs", - "T_id": "0x847080628000000000000001", - "roles": [ - { - "role": "object", - "player": [ - { - "type": "entity", - "tql": "observed-data", - "stix_id": "observed-data--bb3aaad5-accc-4e55-8375-f4b30b17c980" - } - ] - }, - { - "role": "referred", - "player": [ - { - "type": "entity", - "tql": "ipv4-addr", - "stix_id": "ipv4-addr--a40768a0-5841-50d2-838d-bcb35ee92131" - }, - { - "type": "entity", - "tql": "domain-name", - "stix_id": "domain-name--aa90a5c6-6a78-520b-bcfd-e2bf0c25bce1" - } - ] - } - ] - } - ] - } -] \ No newline at end of file diff --git a/stixorm/module/orm/export_utilities.py b/stixorm/module/orm/export_utilities.py index 476019a..08e3e2b 100644 --- a/stixorm/module/orm/export_utilities.py +++ b/stixorm/module/orm/export_utilities.py @@ -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() diff --git a/try_refactor.py b/try_refactor.py index b32aa2e..12b3dcf 100644 --- a/try_refactor.py +++ b/try_refactor.py @@ -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()