Skip to content

Commit

Permalink
Fixed time precision issues
Browse files Browse the repository at this point in the history
  • Loading branch information
brettforbes committed Feb 1, 2024
1 parent 5630568 commit ed07261
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
17 changes: 11 additions & 6 deletions stixorm/module/orm/export_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("=========================================")
Expand Down Expand Up @@ -126,7 +126,7 @@ def make_sdo(res, import_type: ImportType):
attack_object = True
if prop["typeql"] == "x-mitre-is-subtechnique" and prop["value"] is True:
sub_technique = True
if prop["typeql"] == "step_type":
if prop["typeql"] == "step-type":
step_type = prop["value"]

obj_tql, sdo_tql_name, is_list, protocol = sdo_type_to_tql(sdo_type, import_type, attack_object, sub_technique, step_type)
Expand Down Expand Up @@ -573,7 +573,12 @@ def make_extension_relations(reln, reln_name, stix_dict, is_list, obj_type, impo

local_dict = {}
local_dict = make_object(reln, reln_name, local_dict, is_list, obj_type, import_type)
stix_dict["extensions"] = local_dict
if "extensions" in stix_dict:
temp_dict = stix_dict["extensions"]
for key, value in local_dict.items():
temp_dict[key] = value
else:
stix_dict["extensions"] = local_dict
return stix_dict


Expand Down
58 changes: 39 additions & 19 deletions try_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,33 @@
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"
]
}
test_ident = {
"type": "identity",
"spec_version": "2.1",
"id": "identity--b349b84d-c237-4959-a658-d431e502b4b0",
"created": "2024-01-27T08:17:42.861Z",
"modified": "2024-01-27T08:17:42.861Z",
"name": "Whooping",
"description": "A Whooping Individual",
"roles": [
"user",
"sales"
],
"identity_class": "individual",
"sectors": [
"technology"
],
"extensions": {
"extension-definition--66e2492a-bbd3-4be6-88f5-cc91a017a498": {
"extension_type": "property-extension",
"first_name": "Whooping",
"last_name": "Whilly",
"middle_name": "Wee",
"prefix": "Mr",
"team": "Sales"
}
}
}

def test_generate_docs():
print("================================================================================")
Expand Down Expand Up @@ -1909,13 +1923,19 @@ def _get_objects_tql(obj, properties, embedded=[], sub_prop=[], import_type=impo


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"])
connection = {
"uri": "localhost",
"port": "1729",
"database": "stix_test",
"user": None,
"password": None
}
#typedb_sink = TypeDBSink(connection, True, import_type)
typedb_source = TypeDBSource(connection, all_imports)
#result = typedb_sink.add([test_ident])
returned = typedb_source.get("observed-data--a1a91d94-04be-4451-bb0f-5632414dd003")
ret = json.loads(returned.serialize())
print(f" created in {comp_ident['created']}")
print(f" created out {ret['created']}")

print(returned.serialize(pretty=True))


Expand Down

0 comments on commit ed07261

Please sign in to comment.