Skip to content

Commit

Permalink
ignore new extensions, use the correct table name for property extens…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
rpiazza committed Apr 4, 2024
1 parent def9f19 commit eb4b2f1
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions stix2/datastore/relational_db/input_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,24 @@ def generate_insert_information(self, name, stix_object, **kwargs): # noqa: F81
def generate_insert_information(self, name, stix_object, data_sink=None, table_name=None, schema_name=None, parent_table_name=None, **kwargs): # noqa: F811
input_statements = list()
for ex_name, ex in stix_object["extensions"].items():
bindings = {
"id": stix_object["id"],
"ext_table_name": canonicalize_table_name(ex_name, schema_name),
}
ex_table = data_sink.tables_dictionary[table_name + "_" + "extensions"]
input_statements.append(insert(ex_table).values(bindings))
input_statements.extend(
generate_insert_for_sub_object(
data_sink, ex, ex_name, schema_name, stix_object["id"],
parent_table_name=parent_table_name,
is_extension=True,
),
)
# ignore new extensions - they have no properties
if ex.extension_type and not ex.extension_type.startswith("new"):
if ex_name.startswith("extension-definition"):
ex_name = ex_name[0:30]
ex_name = ex_name.replace("extension-definition-", "ext_def")
bindings = {
"id": stix_object["id"],
"ext_table_name": canonicalize_table_name(ex_name, schema_name),
}
ex_table = data_sink.tables_dictionary[table_name + "_" + "extensions"]
input_statements.append(insert(ex_table).values(bindings))
input_statements.extend(
generate_insert_for_sub_object(
data_sink, ex, ex_name, schema_name, stix_object["id"],
parent_table_name=parent_table_name,
is_extension=True,
),
)
return input_statements


Expand Down Expand Up @@ -347,6 +352,9 @@ def generate_insert_for_sub_object(
bindings["id"] = foreign_key_value
if parent_table_name and (not is_extension or level > 0):
type_name = parent_table_name + "_" + type_name
if type_name.startswith("extension-definition"):
type_name = type_name[0:30]
type_name = type_name.replace("extension-definition-", "ext_def")
table_name = canonicalize_table_name(type_name, schema_name)
object_table = data_sink.tables_dictionary[table_name]
sub_insert_statements = list()
Expand Down

0 comments on commit eb4b2f1

Please sign in to comment.