Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 9c5c1f4

Browse files
authored
[client] Set or modify the reliability of an organization (#97)
1 parent bc15565 commit 9c5c1f4

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

pycti/entities/opencti_identity.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, opencti):
2424
updated_at
2525
... on Organization {
2626
organization_class
27+
reliability
2728
}
2829
createdByRef {
2930
node {
@@ -38,6 +39,7 @@ def __init__(self, opencti):
3839
modified
3940
... on Organization {
4041
organization_class
42+
reliability
4143
}
4244
}
4345
relation {
@@ -226,6 +228,7 @@ def create_raw(self, **kwargs):
226228
marking_definitions = kwargs.get("markingDefinitions", None)
227229
tags = kwargs.get("tags", None)
228230
organization_class = kwargs.get("organization_class", None)
231+
reliability = kwargs.get("reliability", None)
229232

230233
if name is not None and description is not None:
231234
self.opencti.log("info", "Creating Identity {" + name + "}.")
@@ -254,6 +257,7 @@ def create_raw(self, **kwargs):
254257
}
255258
"""
256259
input_variables["organization_class"] = organization_class
260+
input_variables["reliability"] = reliability
257261
result_data_field = "organizationAdd"
258262
else:
259263
query = """
@@ -296,9 +300,11 @@ def create(self, **kwargs):
296300
marking_definitions = kwargs.get("markingDefinitions", None)
297301
tags = kwargs.get("tags", None)
298302
organization_class = kwargs.get("organization_class", None)
303+
reliability = kwargs.get("reliability", None)
299304
update = kwargs.get("update", False)
300305
custom_attributes = """
301306
id
307+
stix_id_key
302308
entity_type
303309
name
304310
description
@@ -308,6 +314,7 @@ def create(self, **kwargs):
308314
}
309315
... on Organization {
310316
organization_class
317+
reliability
311318
}
312319
createdByRef {
313320
node {
@@ -373,6 +380,16 @@ def create(self, **kwargs):
373380
value=organization_class,
374381
)
375382
object_result["organization_class"] = organization_class
383+
# reliability
384+
if (
385+
self.opencti.not_empty(reliability)
386+
and "reliability" in object_result
387+
and object_result["reliability"] != reliability
388+
):
389+
self.opencti.stix_domain_entity.update_field(
390+
id=object_result["id"], key="reliability", value=reliability,
391+
)
392+
object_result["reliability"] = reliability
376393
return object_result
377394
else:
378395
return self.create_raw(
@@ -389,6 +406,7 @@ def create(self, **kwargs):
389406
markingDefinitions=marking_definitions,
390407
tags=tags,
391408
organization_class=organization_class,
409+
reliability=reliability,
392410
)
393411

394412
"""
@@ -446,6 +464,9 @@ def import_from_stix2(self, **kwargs):
446464
organization_class=stix_object[CustomProperties.ORG_CLASS]
447465
if CustomProperties.ORG_CLASS in stix_object
448466
else None,
467+
reliability=stix_object[CustomProperties.RELIABILITY]
468+
if CustomProperties.RELIABILITY in stix_object
469+
else None,
449470
update=update,
450471
)
451472
else:
@@ -494,12 +515,15 @@ def to_stix2(self, **kwargs):
494515
identity["modified"] = self.opencti.stix2.format_date(entity["modified"])
495516
if self.opencti.not_empty(entity["alias"]):
496517
identity["aliases"] = entity["alias"]
497-
if (
498-
entity["entity_type"] == "organization"
499-
and "organization_class" in entity
500-
and self.opencti.not_empty(entity["organization_class"])
501-
):
502-
identity[CustomProperties.ORG_CLASS] = entity["organization_class"]
518+
if entity["entity_type"] == "organization":
519+
if "organization_class" in entity and self.opencti.not_empty(
520+
entity["organization_class"]
521+
):
522+
identity[CustomProperties.ORG_CLASS] = entity["organization_class"]
523+
if "reliability" in entity and self.opencti.not_empty(
524+
entity["reliability"]
525+
):
526+
identity[CustomProperties.RELIABILITY] = entity["reliability"]
503527
identity[CustomProperties.IDENTITY_TYPE] = entity["entity_type"]
504528
identity[CustomProperties.ID] = entity["id"]
505529
return self.opencti.stix2.prepare_export(

pycti/utils/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class CustomProperties:
143143

144144
# applies to STIX Identity
145145
ORG_CLASS = "x_opencti_organization_class"
146+
RELIABILITY = "x_opencti_reliability"
146147
IDENTITY_TYPE = (
147148
"x_opencti_identity_type" # this overrides the stix 'identity_class' property!
148149
)

pycti/utils/opencti_stix2.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,14 +1409,22 @@ def prepare_export(
14091409
created_by_ref["modified"] = self.format_date(
14101410
entity_created_by_ref["modified"]
14111411
)
1412-
if (
1413-
entity_created_by_ref["entity_type"] == "organization"
1414-
and "organization_class" in entity_created_by_ref
1415-
and self.opencti.not_empty(entity_created_by_ref["organization_class"])
1416-
):
1417-
created_by_ref[CustomProperties.ORG_CLASS] = entity_created_by_ref[
1418-
"organization_class"
1419-
]
1412+
if entity_created_by_ref["entity_type"] == "organization":
1413+
if (
1414+
"organization_class" in entity_created_by_ref
1415+
and self.opencti.not_empty(
1416+
entity_created_by_ref["organization_class"]
1417+
)
1418+
):
1419+
created_by_ref[CustomProperties.ORG_CLASS] = entity_created_by_ref[
1420+
"organization_class"
1421+
]
1422+
if "reliability" in entity_created_by_ref and self.opencti.not_empty(
1423+
entity_created_by_ref["reliability"]
1424+
):
1425+
created_by_ref[
1426+
CustomProperties.RELIABILITY
1427+
] = entity_created_by_ref["reliability"]
14201428
if self.opencti.not_empty(entity_created_by_ref["alias"]):
14211429
created_by_ref[CustomProperties.ALIASES] = entity_created_by_ref[
14221430
"alias"

0 commit comments

Comments
 (0)