Skip to content

Commit

Permalink
fixed binary list, dictionary insert
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiazza committed Sep 13, 2024
1 parent 9814e6c commit f4f1828
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
3 changes: 3 additions & 0 deletions stix2/datastore/relational_db/input_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def generate_insert_information(self, dictionary_name, stix_object, **kwargs):
# integer, string, timestamp
valid_types = stix_object._properties[dictionary_name].valid_types
for name, value in stix_object[dictionary_name].items():
bindings = dict()
if not valid_types or len(self.valid_types) == 1:
value_binding = "value"
elif isinstance(value, int) and IntegerProperty in valid_types:
Expand All @@ -61,6 +62,8 @@ def generate_insert_information(self, dictionary_name, stix_object, **kwargs):
value_binding = "string_value"
elif isinstance(value, bool) and BooleanProperty in valid_types:
value_binding = "boolean_value"
elif isinstance(value, float) and FloatProperty in valid_types:
value_binding = "float_value"
elif isinstance(value, STIXdatetime) and TimestampProperty in valid_types:
value_binding = "timestamp_value"
else:
Expand Down
71 changes: 71 additions & 0 deletions stix2/datastore/relational_db/relational_db_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,63 @@ def custom_obj():
return obj


@stix2.CustomObject(
"test-object", [
("prop_name", stix2.properties.ListProperty(stix2.properties.BinaryProperty()))
],
"extension-definition--15de9cdb-3515-4271-8479-8141154c5647",
is_sdo=True
)
class TestClass:
pass


def test_binary_list():
return TestClass(prop_name=["AREi", "7t3M"])

@stix2.CustomObject(
"test2-object", [
("prop_name", stix2.properties.ListProperty(
stix2.properties.HexProperty()
))
],
"extension-definition--15de9cdb-4567-4271-8479-8141154c5647",
is_sdo=True
)

class Test2Class:
pass

def test_hex_list():
return Test2Class(
prop_name=["1122", "fedc"]
)

@stix2.CustomObject(
"test3-object", [
("prop_name",
stix2.properties.DictionaryProperty(
valid_types=[
stix2.properties.IntegerProperty,
stix2.properties.FloatProperty,
stix2.properties.StringProperty
]
)
)
],
"extension-definition--15de9cdb-1234-4271-8479-8141154c5647",
is_sdo=True
)
class Test3Class:
pass


def test_dictionary():
return Test3Class(
prop_name={"a": 1, "b": 2.3, "c": "foo"}
)


def main():
store = RelationalDBStore(
"postgresql://localhost/stix-data-sink",
Expand All @@ -205,6 +262,20 @@ def main():
store.sink.generate_stix_schema()
store.sink.clear_tables()

td = test_dictionary()

store.add(td)

th = test_hex_list()

# store.add(th)

tb = test_binary_list()

store.add(tb)



co = custom_obj()

store.add(co)
Expand Down
2 changes: 1 addition & 1 deletion stix2/datastore/relational_db/table_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def determine_sql_type(self): # noqa: F811

@add_method(BinaryProperty)
def determine_sql_type(self): # noqa: F811
return Boolean
return Text


@add_method(BooleanProperty)
Expand Down

0 comments on commit f4f1828

Please sign in to comment.