@@ -23,6 +23,7 @@ def __init__(self, opencti):
23
23
modified
24
24
created_at
25
25
updated_at
26
+ fromRole
26
27
from {
27
28
id
28
29
stix_id_key
@@ -32,6 +33,7 @@ def __init__(self, opencti):
32
33
description
33
34
}
34
35
}
36
+ toRole
35
37
to {
36
38
id
37
39
stix_id_key
@@ -625,16 +627,26 @@ def to_stix2(self, **kwargs):
625
627
if id is not None and entity is None :
626
628
entity = self .read (id = id )
627
629
if entity is not None :
630
+ roles = self .opencti .resolve_role (entity ["relationship_type" ], entity ["from" ]["entity_type" ], entity ["to" ]["entity_type" ])
631
+ if roles is not None :
632
+ final_from_id = entity ["from" ]["stix_id_key" ]
633
+ final_to_id = entity ["to" ]["stix_id_key" ]
634
+ else :
635
+ roles = self .opencti .resolve_role (entity ["relationship_type" ], entity ["to" ]["entity_type" ], entity ["from" ]["entity_type" ])
636
+ if roles is not None :
637
+ final_from_id = entity ["to" ]["stix_id_key" ]
638
+ final_to_id = entity ["from" ]["stix_id_key" ]
639
+
628
640
stix_relation = dict ()
629
641
stix_relation ["id" ] = entity ["stix_id_key" ]
630
642
stix_relation ["type" ] = "relationship"
631
643
stix_relation ["relationship_type" ] = entity ["relationship_type" ]
632
644
if self .opencti .not_empty (entity ["description" ]):
633
645
stix_relation ["description" ] = entity ["description" ]
634
- stix_relation ["source_ref" ] = entity [ "from" ][ "stix_id_key" ]
635
- stix_relation ["target_ref" ] = entity [ "to" ][ "stix_id_key" ]
636
- stix_relation [CustomProperties .SOURCE_REF ] = entity [ "from" ][ "stix_id_key" ]
637
- stix_relation [CustomProperties .TARGET_REF ] = entity [ "to" ][ "stix_id_key" ]
646
+ stix_relation ["source_ref" ] = final_from_id
647
+ stix_relation ["target_ref" ] = final_to_id
648
+ stix_relation [CustomProperties .SOURCE_REF ] = final_from_id
649
+ stix_relation [CustomProperties .TARGET_REF ] = final_to_id
638
650
stix_relation ["created" ] = self .opencti .stix2 .format_date (entity ["created" ])
639
651
stix_relation ["modified" ] = self .opencti .stix2 .format_date (
640
652
entity ["modified" ]
0 commit comments