Skip to content

Commit

Permalink
[client] Implement missing granted_refs at creation
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed Jul 20, 2023
1 parent a973066 commit 7ca2dd2
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 77 deletions.
12 changes: 6 additions & 6 deletions pycti/entities/opencti_attack_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ def import_from_stix2(self, **kwargs):
stix_object[
"x_opencti_stix_ids"
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
if "granted_refs" not in stix_object:
stix_object["granted_refs"] = self.opencti.get_attribute_in_extension(
"granted_refs", stix_object
)
if "x_opencti_granted_refs" not in stix_object:
stix_object[
"x_opencti_granted_refs"
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)

return self.create(
stix_id=stix_object["id"],
Expand Down Expand Up @@ -478,8 +478,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
12 changes: 6 additions & 6 deletions pycti/entities/opencti_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ def import_from_stix2(self, **kwargs):
stix_object[
"x_opencti_stix_ids"
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
if "granted_refs" not in stix_object:
stix_object["granted_refs"] = self.opencti.get_attribute_in_extension(
"granted_refs", stix_object
)
if "x_opencti_granted_refs" not in stix_object:
stix_object[
"x_opencti_granted_refs"
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)

return self.create(
stix_id=stix_object["id"],
Expand Down Expand Up @@ -395,8 +395,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
12 changes: 6 additions & 6 deletions pycti/entities/opencti_case_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,10 @@ def import_from_stix2(self, **kwargs):
stix_object[
"x_opencti_stix_ids"
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
if "granted_refs" not in stix_object:
stix_object["granted_refs"] = self.opencti.get_attribute_in_extension(
"granted_refs", stix_object
)
if "x_opencti_granted_refs" not in stix_object:
stix_object[
"x_opencti_granted_refs"
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)
if "x_opencti_workflow_id" not in stix_object:
stix_object[
"x_opencti_workflow_id"
Expand Down Expand Up @@ -681,8 +681,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
x_opencti_workflow_id=stix_object["x_opencti_workflow_id"]
if "x_opencti_workflow_id" in stix_object
Expand Down
12 changes: 6 additions & 6 deletions pycti/entities/opencti_case_rfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,10 @@ def import_from_stix2(self, **kwargs):
stix_object[
"x_opencti_stix_ids"
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
if "granted_refs" not in stix_object:
stix_object["granted_refs"] = self.opencti.get_attribute_in_extension(
"granted_refs", stix_object
)
if "x_opencti_granted_refs" not in stix_object:
stix_object[
"x_opencti_granted_refs"
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)

return self.create(
stix_id=stix_object["id"],
Expand Down Expand Up @@ -662,8 +662,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
information_types=stix_object["information_types"]
Expand Down
12 changes: 6 additions & 6 deletions pycti/entities/opencti_case_rft.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,10 @@ def import_from_stix2(self, **kwargs):
stix_object[
"x_opencti_stix_ids"
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
if "granted_refs" not in stix_object:
stix_object["granted_refs"] = self.opencti.get_attribute_in_extension(
"granted_refs", stix_object
)
if "x_opencti_granted_refs" not in stix_object:
stix_object[
"x_opencti_granted_refs"
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)

return self.create(
stix_id=stix_object["id"],
Expand Down Expand Up @@ -661,8 +661,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_course_of_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ def import_from_stix2(self, **kwargs):
else None,
x_opencti_aliases=self.opencti.stix2.pick_aliases(stix_object),
x_mitre_id=x_mitre_id,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_data_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
x_opencti_aliases=self.opencti.stix2.pick_aliases(stix_object),
update=update,
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_create_observables=stix_object["x_opencti_create_observables"]
if "x_opencti_create_observables" in stix_object
else False,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
21 changes: 14 additions & 7 deletions pycti/entities/opencti_infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def create(self, **kwargs):
last_seen = kwargs.get("last_seen", None)
kill_chain_phases = kwargs.get("killChainPhases", None)
x_opencti_stix_ids = kwargs.get("x_opencti_stix_ids", None)
granted_refs = kwargs.get("objectOrganization", None)
update = kwargs.get("update", False)

if name is not None:
Expand All @@ -343,6 +344,7 @@ def create(self, **kwargs):
"createdBy": created_by,
"objectMarking": object_marking,
"objectLabel": object_label,
"objectOrganization": granted_refs,
"externalReferences": external_references,
"revoked": revoked,
"confidence": confidence,
Expand Down Expand Up @@ -381,14 +383,16 @@ def import_from_stix2(self, **kwargs):
stix_object = kwargs.get("stixObject", None)
extras = kwargs.get("extras", {})
update = kwargs.get("update", False)

# Search in extensions
if "x_opencti_stix_ids" not in stix_object:
stix_object["x_opencti_stix_ids"] = self.opencti.get_attribute_in_extension(
"stix_ids", stix_object
)

if stix_object is not None:
# Search in extensions
if "x_opencti_stix_ids" not in stix_object:
stix_object[
"x_opencti_stix_ids"
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
if "x_opencti_granted_refs" not in stix_object:
stix_object[
"x_opencti_granted_refs"
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)
return self.create(
stix_id=stix_object["id"],
createdBy=extras["created_by_id"]
Expand Down Expand Up @@ -432,6 +436,9 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
else:
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_intrusion_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_malware.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_malware_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_narrative.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ def import_from_stix2(self, **kwargs):
likelihood=stix_object["likelihood"]
if "likelihood" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_observed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_opinion.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ def import_from_stix2(self, **kwargs):
if "x_opencti_stix_ids" in stix_object
else None,
opinion=stix_object["opinion"] if "opinion" in stix_object else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ def import_from_stix2(self, **kwargs):
if "description" in stix_object
else None,
due_date=stix_object["due_date"] if "due_date" in stix_object else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_threat_actor_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
4 changes: 2 additions & 2 deletions pycti/entities/opencti_threat_actor_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ def import_from_stix2(self, **kwargs):
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
if "x_opencti_stix_ids" in stix_object
else None,
objectOrganization=stix_object["granted_refs"]
if "granted_refs" in stix_object
objectOrganization=stix_object["x_opencti_granted_refs"]
if "x_opencti_granted_refs" in stix_object
else None,
update=update,
)
Expand Down
Loading

0 comments on commit 7ca2dd2

Please sign in to comment.