11# coding: utf-8
22
33import json
4- from pycti .utils .constants import CustomProperties
4+ from pycti .utils .constants import CustomProperties , IdentityTypes
55from 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 """
0 commit comments