|
20 | 20 | EqualityComparisonExpression, |
21 | 21 | HashConstant, |
22 | 22 | ) |
23 | | -from pycti.utils.constants import ObservableTypes, IdentityTypes, CustomProperties |
| 23 | +from pycti.utils.constants import ( |
| 24 | + ObservableTypes, |
| 25 | + IdentityTypes, |
| 26 | + CustomProperties, |
| 27 | + StixObservableRelationTypes, |
| 28 | +) |
24 | 29 |
|
25 | 30 | datefinder.ValueError = ValueError, OverflowError |
26 | 31 | utc = pytz.UTC |
@@ -542,7 +547,9 @@ def import_relationship(self, stix_relation, update=False, types=None): |
542 | 547 | source_ref = stix_relation["source_ref"] |
543 | 548 | if source_ref in self.mapping_cache: |
544 | 549 | if ( |
545 | | - stix_relation["relationship_type"] in OBSERVABLE_RELATIONS |
| 550 | + StixObservableRelationTypes.has_value( |
| 551 | + stix_relation["relationship_type"] |
| 552 | + ) |
546 | 553 | and "observableRefs" in self.mapping_cache[source_ref] |
547 | 554 | and self.mapping_cache[source_ref]["observableRefs"] is not None |
548 | 555 | and len(self.mapping_cache[source_ref]["observableRefs"]) > 0 |
@@ -573,7 +580,9 @@ def import_relationship(self, stix_relation, update=False, types=None): |
573 | 580 | target_ref = stix_relation["target_ref"] |
574 | 581 | if target_ref in self.mapping_cache: |
575 | 582 | if ( |
576 | | - stix_relation["relationship_type"] in OBSERVABLE_RELATIONS |
| 583 | + StixObservableRelationTypes.has_value( |
| 584 | + stix_relation["relationship_type"] |
| 585 | + ) |
577 | 586 | and "observableRefs" in self.mapping_cache[target_ref] |
578 | 587 | and self.mapping_cache[target_ref]["observableRefs"] is not None |
579 | 588 | and len(self.mapping_cache[target_ref]["observableRefs"]) > 0 |
@@ -622,38 +631,81 @@ def import_relationship(self, stix_relation, update=False, types=None): |
622 | 631 | .isoformat() |
623 | 632 | ) |
624 | 633 |
|
625 | | - stix_relation_result = self.opencti.stix_relation.create( |
626 | | - fromId=source_id, |
627 | | - fromType=source_type, |
628 | | - toId=target_id, |
629 | | - toType=target_type, |
630 | | - relationship_type=stix_relation["relationship_type"], |
631 | | - description=self.convert_markdown(stix_relation["description"]) |
632 | | - if "description" in stix_relation |
633 | | - else None, |
634 | | - first_seen=stix_relation[CustomProperties.FIRST_SEEN] |
635 | | - if CustomProperties.FIRST_SEEN in stix_relation |
636 | | - else date, |
637 | | - last_seen=stix_relation[CustomProperties.LAST_SEEN] |
638 | | - if CustomProperties.LAST_SEEN in stix_relation |
639 | | - else date, |
640 | | - weight=stix_relation[CustomProperties.WEIGHT] |
641 | | - if CustomProperties.WEIGHT in stix_relation |
642 | | - else 1, |
643 | | - role_played=stix_relation[CustomProperties.ROLE_PLAYED] |
644 | | - if CustomProperties.ROLE_PLAYED in stix_relation |
645 | | - else None, |
646 | | - id=stix_relation[CustomProperties.ID] |
647 | | - if CustomProperties.ID in stix_relation |
648 | | - else None, |
649 | | - stix_id_key=stix_relation["id"] if "id" in stix_relation else None, |
650 | | - created=stix_relation["created"] if "created" in stix_relation else None, |
651 | | - modified=stix_relation["modified"] if "modified" in stix_relation else None, |
652 | | - update=update, |
653 | | - ignore_dates=stix_relation[CustomProperties.IGNORE_DATES] |
654 | | - if CustomProperties.IGNORE_DATES in stix_relation |
655 | | - else None, |
656 | | - ) |
| 634 | + stix_relation_result = None |
| 635 | + if StixObservableRelationTypes.has_value(stix_relation["relationship_type"]): |
| 636 | + stix_relation_result = self.opencti.stix_observable_relation.create( |
| 637 | + fromId=source_id, |
| 638 | + fromType=source_type, |
| 639 | + toId=target_id, |
| 640 | + toType=target_type, |
| 641 | + relationship_type=stix_relation["relationship_type"], |
| 642 | + description=self.convert_markdown(stix_relation["description"]) |
| 643 | + if "description" in stix_relation |
| 644 | + else None, |
| 645 | + first_seen=stix_relation[CustomProperties.FIRST_SEEN] |
| 646 | + if CustomProperties.FIRST_SEEN in stix_relation |
| 647 | + else date, |
| 648 | + last_seen=stix_relation[CustomProperties.LAST_SEEN] |
| 649 | + if CustomProperties.LAST_SEEN in stix_relation |
| 650 | + else date, |
| 651 | + weight=stix_relation[CustomProperties.WEIGHT] |
| 652 | + if CustomProperties.WEIGHT in stix_relation |
| 653 | + else 1, |
| 654 | + role_played=stix_relation[CustomProperties.ROLE_PLAYED] |
| 655 | + if CustomProperties.ROLE_PLAYED in stix_relation |
| 656 | + else None, |
| 657 | + id=stix_relation[CustomProperties.ID] |
| 658 | + if CustomProperties.ID in stix_relation |
| 659 | + else None, |
| 660 | + stix_id_key=stix_relation["id"] if "id" in stix_relation else None, |
| 661 | + created=stix_relation["created"] |
| 662 | + if "created" in stix_relation |
| 663 | + else None, |
| 664 | + modified=stix_relation["modified"] |
| 665 | + if "modified" in stix_relation |
| 666 | + else None, |
| 667 | + update=update, |
| 668 | + ignore_dates=stix_relation[CustomProperties.IGNORE_DATES] |
| 669 | + if CustomProperties.IGNORE_DATES in stix_relation |
| 670 | + else None, |
| 671 | + ) |
| 672 | + else: |
| 673 | + stix_relation_result = self.opencti.stix_relation.create( |
| 674 | + fromId=source_id, |
| 675 | + fromType=source_type, |
| 676 | + toId=target_id, |
| 677 | + toType=target_type, |
| 678 | + relationship_type=stix_relation["relationship_type"], |
| 679 | + description=self.convert_markdown(stix_relation["description"]) |
| 680 | + if "description" in stix_relation |
| 681 | + else None, |
| 682 | + first_seen=stix_relation[CustomProperties.FIRST_SEEN] |
| 683 | + if CustomProperties.FIRST_SEEN in stix_relation |
| 684 | + else date, |
| 685 | + last_seen=stix_relation[CustomProperties.LAST_SEEN] |
| 686 | + if CustomProperties.LAST_SEEN in stix_relation |
| 687 | + else date, |
| 688 | + weight=stix_relation[CustomProperties.WEIGHT] |
| 689 | + if CustomProperties.WEIGHT in stix_relation |
| 690 | + else 1, |
| 691 | + role_played=stix_relation[CustomProperties.ROLE_PLAYED] |
| 692 | + if CustomProperties.ROLE_PLAYED in stix_relation |
| 693 | + else None, |
| 694 | + id=stix_relation[CustomProperties.ID] |
| 695 | + if CustomProperties.ID in stix_relation |
| 696 | + else None, |
| 697 | + stix_id_key=stix_relation["id"] if "id" in stix_relation else None, |
| 698 | + created=stix_relation["created"] |
| 699 | + if "created" in stix_relation |
| 700 | + else None, |
| 701 | + modified=stix_relation["modified"] |
| 702 | + if "modified" in stix_relation |
| 703 | + else None, |
| 704 | + update=update, |
| 705 | + ignore_dates=stix_relation[CustomProperties.IGNORE_DATES] |
| 706 | + if CustomProperties.IGNORE_DATES in stix_relation |
| 707 | + else None, |
| 708 | + ) |
657 | 709 | if stix_relation_result is not None: |
658 | 710 | self.mapping_cache[stix_relation["id"]] = { |
659 | 711 | "id": stix_relation_result["id"], |
|
0 commit comments