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

Commit f5ee777

Browse files
authored
[client] Add support for x_opencti_organization_class (#91)
1 parent 48043ee commit f5ee777

File tree

3 files changed

+64
-30
lines changed

3 files changed

+64
-30
lines changed

pycti/entities/opencti_identity.py

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf-8
22

33
import json
4-
from pycti.utils.constants import CustomProperties
4+
from pycti.utils.constants import CustomProperties, IdentityTypes
55
from pycti.utils.opencti_stix2 import SPEC_VERSION
66

77

@@ -223,39 +223,53 @@ def create_raw(self, **kwargs):
223223
created_by_ref = kwargs.get("createdByRef", None)
224224
marking_definitions = kwargs.get("markingDefinitions", None)
225225
tags = kwargs.get("tags", None)
226+
organization_class = kwargs.get("organization_class", None)
226227

227228
if name is not None and description is not None:
228229
self.opencti.log("info", "Creating Identity {" + name + "}.")
229-
query = (
230+
231+
input_variables = {
232+
"name": name,
233+
"description": description,
234+
"alias": alias,
235+
"internal_id_key": id,
236+
"stix_id_key": stix_id_key,
237+
"created": created,
238+
"modified": modified,
239+
"createdByRef": created_by_ref,
240+
"markingDefinitions": marking_definitions,
241+
"tags": tags,
242+
}
243+
244+
if type == IdentityTypes.ORGANIZATION.value:
245+
query = f"""
246+
mutation OrganizationAdd($input: OrganizationAddInput) {{
247+
organizationAdd(input: $input) {{
248+
{self.properties}
249+
}}
250+
}}
230251
"""
231-
mutation IdentityAdd($input: IdentityAddInput) {
232-
identityAdd(input: $input) {
233-
"""
234-
+ self.properties
235-
+ """
236-
}
237-
}
238-
"""
239-
)
240-
result = self.opencti.query(
241-
query,
242-
{
243-
"input": {
244-
"name": name,
245-
"description": description,
246-
"alias": alias,
247-
"type": type,
248-
"internal_id_key": id,
249-
"stix_id_key": stix_id_key,
250-
"created": created,
251-
"modified": modified,
252-
"createdByRef": created_by_ref,
253-
"markingDefinitions": marking_definitions,
254-
"tags": tags,
255-
}
256-
},
252+
253+
input_variables["organization_class"] = organization_class
254+
255+
result_data_field = "organizationAdd"
256+
else:
257+
query = f"""
258+
mutation IdentityAdd($input: IdentityAddInput) {{
259+
identityAdd(input: $input) {{
260+
{self.properties}
261+
}}
262+
}}
263+
"""
264+
265+
input_variables["type"] = type
266+
267+
result_data_field = "identityAdd"
268+
269+
result = self.opencti.query(query, {"input": input_variables,},)
270+
return self.opencti.process_multiple_fields(
271+
result["data"][result_data_field]
257272
)
258-
return self.opencti.process_multiple_fields(result["data"]["identityAdd"])
259273
else:
260274
self.opencti.log("error", "Missing parameters: name and description")
261275

@@ -278,13 +292,17 @@ def create(self, **kwargs):
278292
created_by_ref = kwargs.get("createdByRef", None)
279293
marking_definitions = kwargs.get("markingDefinitions", None)
280294
tags = kwargs.get("tags", None)
295+
organization_class = kwargs.get("organization_class", None)
281296
update = kwargs.get("update", False)
282297
custom_attributes = """
283298
id
284299
entity_type
285300
name
286301
description
287302
alias
303+
... on Organization {
304+
organization_class
305+
}
288306
createdByRef {
289307
node {
290308
id
@@ -326,6 +344,18 @@ def create(self, **kwargs):
326344
id=object_result["id"], key="alias", value=new_aliases
327345
)
328346
object_result["alias"] = new_aliases
347+
# organization_class
348+
if (
349+
organization_class is not None
350+
and "organization_class" in object_result
351+
and object_result["organization_class"] != organization_class
352+
):
353+
self.opencti.stix_domain_entity.update_field(
354+
id=object_result["id"],
355+
key="organization_class",
356+
value=organization_class,
357+
)
358+
object_result["organization_class"] = organization_class
329359
return object_result
330360
else:
331361
return self.create_raw(
@@ -340,6 +370,7 @@ def create(self, **kwargs):
340370
createdByRef=created_by_ref,
341371
markingDefinitions=marking_definitions,
342372
tags=tags,
373+
organization_class=organization_class,
343374
)
344375

345376
"""

pycti/entities/opencti_stix_domain_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def read(self, **kwargs):
392392
)
393393
elif filters is not None:
394394
result = self.list(
395-
types=types, filters=filters, customAttribute=custom_attributes
395+
types=types, filters=filters, customAttributes=custom_attributes
396396
)
397397
if len(result) > 0:
398398
return result[0]

pycti/utils/opencti_stix2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,9 @@ def create_identity(self, stix_object, extras, update=False):
17301730
if "marking_definitions_ids" in extras
17311731
else [],
17321732
tags=extras["tags_ids"] if "tags_ids" in extras else [],
1733+
organization_class=stix_object[CustomProperties.ORG_CLASS]
1734+
if CustomProperties.ORG_CLASS in stix_object
1735+
else None,
17331736
update=update,
17341737
)
17351738

0 commit comments

Comments
 (0)