pycti 6.1.0__tar.gz → 6.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pycti might be problematic. Click here for more details.

Files changed (73) hide show
  1. {pycti-6.1.0 → pycti-6.1.1}/PKG-INFO +1 -1
  2. {pycti-6.1.0 → pycti-6.1.1}/pycti/__init__.py +1 -1
  3. {pycti-6.1.0 → pycti-6.1.1}/pycti/connector/opencti_connector_helper.py +4 -2
  4. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_intrusion_set.py +9 -11
  5. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix_domain_object.py +3 -1
  6. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix_object_or_stix_relationship.py +34 -9
  7. {pycti-6.1.0 → pycti-6.1.1}/pycti/utils/opencti_stix2.py +116 -219
  8. {pycti-6.1.0 → pycti-6.1.1}/pycti.egg-info/PKG-INFO +1 -1
  9. {pycti-6.1.0 → pycti-6.1.1}/LICENSE +0 -0
  10. {pycti-6.1.0 → pycti-6.1.1}/README.md +0 -0
  11. {pycti-6.1.0 → pycti-6.1.1}/pycti/api/__init__.py +0 -0
  12. {pycti-6.1.0 → pycti-6.1.1}/pycti/api/opencti_api_client.py +0 -0
  13. {pycti-6.1.0 → pycti-6.1.1}/pycti/api/opencti_api_connector.py +0 -0
  14. {pycti-6.1.0 → pycti-6.1.1}/pycti/api/opencti_api_playbook.py +0 -0
  15. {pycti-6.1.0 → pycti-6.1.1}/pycti/api/opencti_api_work.py +0 -0
  16. {pycti-6.1.0 → pycti-6.1.1}/pycti/connector/__init__.py +0 -0
  17. {pycti-6.1.0 → pycti-6.1.1}/pycti/connector/opencti_connector.py +0 -0
  18. {pycti-6.1.0 → pycti-6.1.1}/pycti/connector/opencti_metric_handler.py +0 -0
  19. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/__init__.py +0 -0
  20. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_attack_pattern.py +0 -0
  21. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_campaign.py +0 -0
  22. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_case_incident.py +0 -0
  23. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_case_rfi.py +0 -0
  24. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_case_rft.py +0 -0
  25. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_channel.py +0 -0
  26. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_course_of_action.py +0 -0
  27. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_data_component.py +0 -0
  28. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_data_source.py +0 -0
  29. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_event.py +0 -0
  30. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_external_reference.py +0 -0
  31. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_feedback.py +0 -0
  32. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_grouping.py +0 -0
  33. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_identity.py +0 -0
  34. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_incident.py +0 -0
  35. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_indicator.py +0 -0
  36. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_infrastructure.py +0 -0
  37. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_kill_chain_phase.py +0 -0
  38. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_label.py +0 -0
  39. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_language.py +0 -0
  40. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_location.py +0 -0
  41. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_malware.py +0 -0
  42. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_malware_analysis.py +0 -0
  43. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_marking_definition.py +0 -0
  44. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_narrative.py +0 -0
  45. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_note.py +0 -0
  46. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_observed_data.py +0 -0
  47. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_opinion.py +0 -0
  48. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_report.py +0 -0
  49. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix.py +0 -0
  50. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix_core_object.py +0 -0
  51. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix_core_relationship.py +0 -0
  52. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix_cyber_observable.py +0 -0
  53. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix_nested_ref_relationship.py +0 -0
  54. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_stix_sighting_relationship.py +0 -0
  55. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_task.py +0 -0
  56. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_threat_actor.py +0 -0
  57. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_threat_actor_group.py +0 -0
  58. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_threat_actor_individual.py +0 -0
  59. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_tool.py +0 -0
  60. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_vocabulary.py +0 -0
  61. {pycti-6.1.0 → pycti-6.1.1}/pycti/entities/opencti_vulnerability.py +0 -0
  62. {pycti-6.1.0 → pycti-6.1.1}/pycti/utils/__init__.py +0 -0
  63. {pycti-6.1.0 → pycti-6.1.1}/pycti/utils/constants.py +0 -0
  64. {pycti-6.1.0 → pycti-6.1.1}/pycti/utils/opencti_logger.py +0 -0
  65. {pycti-6.1.0 → pycti-6.1.1}/pycti/utils/opencti_stix2_splitter.py +0 -0
  66. {pycti-6.1.0 → pycti-6.1.1}/pycti/utils/opencti_stix2_update.py +0 -0
  67. {pycti-6.1.0 → pycti-6.1.1}/pycti/utils/opencti_stix2_utils.py +0 -0
  68. {pycti-6.1.0 → pycti-6.1.1}/pycti.egg-info/SOURCES.txt +0 -0
  69. {pycti-6.1.0 → pycti-6.1.1}/pycti.egg-info/dependency_links.txt +0 -0
  70. {pycti-6.1.0 → pycti-6.1.1}/pycti.egg-info/requires.txt +0 -0
  71. {pycti-6.1.0 → pycti-6.1.1}/pycti.egg-info/top_level.txt +0 -0
  72. {pycti-6.1.0 → pycti-6.1.1}/pyproject.toml +0 -0
  73. {pycti-6.1.0 → pycti-6.1.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycti
3
- Version: 6.1.0
3
+ Version: 6.1.1
4
4
  Summary: Python API client for OpenCTI.
5
5
  Home-page: https://github.com/OpenCTI-Platform/client-python
6
6
  Author: Filigran
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = "6.1.0"
2
+ __version__ = "6.1.1"
3
3
 
4
4
  from .api.opencti_api_client import OpenCTIApiClient
5
5
  from .api.opencti_api_connector import OpenCTIApiConnector
@@ -314,7 +314,9 @@ class ListenQueue(threading.Thread):
314
314
  # If not playbook but enrichment, compute object on enrichment_entity
315
315
  opencti_entity = event_data["enrichment_entity"]
316
316
  stix_objects = self.helper.api.stix2.prepare_export(
317
- self.helper.api.stix2.generate_export(copy.copy(opencti_entity))
317
+ entity=self.helper.api.stix2.generate_export(
318
+ copy.copy(opencti_entity)
319
+ )
318
320
  )
319
321
  stix_entity = [
320
322
  e
@@ -1567,7 +1569,7 @@ class OpenCTIConnectorHelper: # pylint: disable=too-many-public-methods
1567
1569
  if bundle is None:
1568
1570
  # Generate bundle
1569
1571
  stix_objects = self.api.stix2.prepare_export(
1570
- self.api.stix2.generate_export(copy.copy(opencti_entity))
1572
+ entity=self.api.stix2.generate_export(copy.copy(opencti_entity))
1571
1573
  )
1572
1574
  else:
1573
1575
  stix_objects = bundle["objects"]
@@ -275,17 +275,15 @@ class IntrusionSet:
275
275
  }
276
276
  """
277
277
  )
278
- result = self.opencti.query(
279
- query,
280
- {
281
- "filters": filters,
282
- "search": search,
283
- "first": first,
284
- "after": after,
285
- "orderBy": order_by,
286
- "orderMode": order_mode,
287
- },
288
- )
278
+ variables = {
279
+ "filters": filters,
280
+ "search": search,
281
+ "first": first,
282
+ "after": after,
283
+ "orderBy": order_by,
284
+ "orderMode": order_mode,
285
+ }
286
+ result = self.opencti.query(query, variables)
289
287
  if get_all:
290
288
  final_data = []
291
289
  data = self.opencti.process_multiple(result["data"]["intrusionSets"])
@@ -1355,8 +1355,10 @@ class StixDomainObject:
1355
1355
  )
1356
1356
 
1357
1357
  def push_entity_export(
1358
- self, entity_id, file_name, data, file_markings, mime_type=None
1358
+ self, entity_id, file_name, data, file_markings=None, mime_type=None
1359
1359
  ):
1360
+ if file_markings is None:
1361
+ file_markings = []
1360
1362
  query = """
1361
1363
  mutation StixDomainObjectEdit(
1362
1364
  $id: ID!, $file: Upload!,
@@ -513,6 +513,7 @@ class StixObjectOrStixRelationship:
513
513
  search = kwargs.get("search", None)
514
514
  first = kwargs.get("first", 100)
515
515
  after = kwargs.get("after", None)
516
+ get_all = kwargs.get("getAll", False)
516
517
  with_pagination = kwargs.get("with_pagination", False)
517
518
  custom_attributes = kwargs.get("customAttributes", None)
518
519
 
@@ -542,16 +543,40 @@ class StixObjectOrStixRelationship:
542
543
  }
543
544
  """
544
545
  )
546
+ variables = {
547
+ "filters": filters,
548
+ "search": search,
549
+ "first": first,
550
+ "after": after,
551
+ }
545
552
  result = self.opencti.query(
546
553
  query,
547
- {
548
- "filters": filters,
549
- "search": search,
550
- "first": first,
551
- "after": after,
552
- },
554
+ variables,
553
555
  )
554
556
 
555
- return self.opencti.process_multiple(
556
- result["data"]["stixObjectOrStixRelationships"], with_pagination
557
- )
557
+ if get_all:
558
+ final_data = []
559
+ data = self.opencti.process_multiple(
560
+ result["data"]["stixObjectOrStixRelationships"]
561
+ )
562
+ final_data = final_data + data
563
+ while result["data"]["stixObjectOrStixRelationships"]["pageInfo"][
564
+ "hasNextPage"
565
+ ]:
566
+ after = result["data"]["stixObjectOrStixRelationships"]["pageInfo"][
567
+ "endCursor"
568
+ ]
569
+ self.opencti.app_logger.info(
570
+ "Listing stixObjectOrStixRelationships", {"after": after}
571
+ )
572
+ after_variables = {**variables, **{"after": after}}
573
+ result = self.opencti.query(query, after_variables)
574
+ data = self.opencti.process_multiple(
575
+ result["data"]["stixObjectOrStixRelationships"]
576
+ )
577
+ final_data = final_data + data
578
+ return final_data
579
+ else:
580
+ return self.opencti.process_multiple(
581
+ result["data"]["stixObjectOrStixRelationships"], with_pagination
582
+ )
@@ -135,43 +135,6 @@ class OpenCTIStix2:
135
135
  return stix_object["aliases"]
136
136
  return None
137
137
 
138
- def check_max_marking_definition(
139
- self, max_marking_definition_entity: Dict, entity_marking_definitions: List
140
- ) -> bool:
141
- """checks if a list of marking definitions conforms with a given max level
142
-
143
- :param max_marking_definition_entity: the maximum allowed marking definition level
144
- :type max_marking_definition_entity: str, optional
145
- :param entity_marking_definitions: list of entities to check
146
- :type entity_marking_definitions: list
147
- :return: `True` if the list conforms with max marking definition
148
- :rtype: bool
149
- """
150
-
151
- # Max is not set, return True
152
- if max_marking_definition_entity is None:
153
- return True
154
- # Filter entity markings definition to the max_marking_definition type
155
- typed_entity_marking_definitions = []
156
- for entity_marking_definition in entity_marking_definitions:
157
- if (
158
- entity_marking_definition["definition_type"]
159
- == max_marking_definition_entity["definition_type"]
160
- ):
161
- typed_entity_marking_definitions.append(entity_marking_definition)
162
- # No entity marking defintions of the max_marking_definition type
163
- if len(typed_entity_marking_definitions) == 0:
164
- return True
165
-
166
- # Check if level is less or equal to max
167
- for typed_entity_marking_definition in typed_entity_marking_definitions:
168
- if (
169
- typed_entity_marking_definition["x_opencti_order"]
170
- <= max_marking_definition_entity["x_opencti_order"]
171
- ):
172
- return True
173
- return False
174
-
175
138
  def import_bundle_from_file(
176
139
  self, file_path: str, update: bool = False, types: List = None
177
140
  ) -> Optional[List]:
@@ -1659,7 +1622,10 @@ class OpenCTIStix2:
1659
1622
 
1660
1623
  return {k: v for k, v in entity.items() if self.opencti.not_empty(v)}
1661
1624
 
1662
- def prepare_filters_export(self, id: str, access_filter: Dict = None) -> Dict:
1625
+ @staticmethod
1626
+ def prepare_id_filters_export(
1627
+ id: Union[str, List[str]], access_filter: Dict = None
1628
+ ) -> Dict:
1663
1629
  if access_filter is not None:
1664
1630
  return {
1665
1631
  "mode": "and",
@@ -1668,8 +1634,8 @@ class OpenCTIStix2:
1668
1634
  "mode": "or",
1669
1635
  "filters": [
1670
1636
  {
1671
- "key": "id",
1672
- "values": [id],
1637
+ "key": "ids",
1638
+ "values": id if isinstance(id, list) else [id],
1673
1639
  }
1674
1640
  ],
1675
1641
  "filterGroups": [],
@@ -1681,27 +1647,20 @@ class OpenCTIStix2:
1681
1647
  else:
1682
1648
  return {
1683
1649
  "mode": "and",
1684
- "filterGroups": [
1650
+ "filterGroups": [],
1651
+ "filters": [
1685
1652
  {
1653
+ "key": "ids",
1686
1654
  "mode": "or",
1687
- "filters": [
1688
- {
1689
- "key": "id",
1690
- "values": [id],
1691
- }
1692
- ],
1693
- "filterGroups": [],
1694
- },
1655
+ "values": id if isinstance(id, list) else [id],
1656
+ }
1695
1657
  ],
1696
- "filters": [],
1697
1658
  }
1698
1659
 
1699
1660
  def prepare_export(
1700
1661
  self,
1701
1662
  entity: Dict,
1702
1663
  mode: str = "simple",
1703
- max_marking_definition_entity: Dict = None,
1704
- main_filter: Dict = None,
1705
1664
  access_filter: Dict = None,
1706
1665
  no_custom_attributes: bool = False,
1707
1666
  ) -> List:
@@ -1711,37 +1670,16 @@ class OpenCTIStix2:
1711
1670
 
1712
1671
  # Container
1713
1672
  if "objects" in entity and len(entity["objects"]) > 0:
1714
- del entity["objects"]
1715
- regarding_of_filter = {
1716
- "mode": "and",
1717
- "filterGroups": [],
1718
- "filters": [
1719
- {
1720
- "key": "regardingOf",
1721
- "mode": "and",
1722
- "operator": "eq",
1723
- "values": [
1724
- {"key": "id", "values": [entity["x_opencti_id"]]},
1725
- {"key": "relationship_type", "values": ["object"]},
1726
- ],
1727
- }
1728
- ],
1729
- }
1730
- filter_groups = []
1731
- if regarding_of_filter is not None:
1732
- filter_groups.append(regarding_of_filter)
1733
- if access_filter is not None:
1734
- filter_groups.append(access_filter)
1735
- export_query_filter = {
1736
- "mode": "and",
1737
- "filterGroups": filter_groups,
1738
- "filters": [],
1739
- }
1740
- entity["objects"] = (
1673
+ object_ids = list(map(lambda e: e["standard_id"], entity["objects"]))
1674
+ export_query_filter = self.prepare_id_filters_export(
1675
+ id=object_ids, access_filter=access_filter
1676
+ )
1677
+ filtered_objects = (
1741
1678
  self.opencti.opencti_stix_object_or_stix_relationship.list(
1742
- filters=export_query_filter
1679
+ filters=export_query_filter, getAll=True
1743
1680
  )
1744
1681
  )
1682
+ entity["objects"] = filtered_objects
1745
1683
 
1746
1684
  # CreatedByRef
1747
1685
  if (
@@ -1749,7 +1687,7 @@ class OpenCTIStix2:
1749
1687
  and "createdBy" in entity
1750
1688
  and entity["createdBy"] is not None
1751
1689
  ):
1752
- created_by = self.generate_export(entity["createdBy"])
1690
+ created_by = self.generate_export(entity=entity["createdBy"])
1753
1691
  if entity["type"] in STIX_CYBER_OBSERVABLE_MAPPING:
1754
1692
  entity["x_opencti_created_by_ref"] = created_by["id"]
1755
1693
  else:
@@ -1927,7 +1865,7 @@ class OpenCTIStix2:
1927
1865
  entity["count"] = entity["attribute_count"]
1928
1866
  del entity["attribute_count"]
1929
1867
  from_to_check = entity["from"]["id"]
1930
- relationships_from_filter = self.prepare_filters_export(
1868
+ relationships_from_filter = self.prepare_id_filters_export(
1931
1869
  id=from_to_check, access_filter=access_filter
1932
1870
  )
1933
1871
  x = self.opencti.opencti_stix_object_or_stix_relationship.list(
@@ -1941,7 +1879,7 @@ class OpenCTIStix2:
1941
1879
  ) # what happen with unauthorized objects ?
1942
1880
 
1943
1881
  to_to_check = [entity["to"]["id"]]
1944
- relationships_to_filter = self.prepare_filters_export(
1882
+ relationships_to_filter = self.prepare_id_filters_export(
1945
1883
  id=to_to_check, access_filter=access_filter
1946
1884
  )
1947
1885
  y = self.opencti.opencti_stix_object_or_stix_relationship.list(
@@ -1958,7 +1896,7 @@ class OpenCTIStix2:
1958
1896
  entity["type"] = "relationship"
1959
1897
  if "from" in entity:
1960
1898
  from_to_check = entity["from"]["id"]
1961
- relationships_from_filter = self.prepare_filters_export(
1899
+ relationships_from_filter = self.prepare_id_filters_export(
1962
1900
  id=from_to_check, access_filter=access_filter
1963
1901
  )
1964
1902
  x = self.opencti.opencti_stix_object_or_stix_relationship.list(
@@ -1973,7 +1911,7 @@ class OpenCTIStix2:
1973
1911
  del entity["from"]
1974
1912
  if "to" in entity:
1975
1913
  to_to_check = [entity["to"]["id"]]
1976
- relationships_to_filter = self.prepare_filters_export(
1914
+ relationships_to_filter = self.prepare_id_filters_export(
1977
1915
  id=to_to_check, access_filter=access_filter
1978
1916
  )
1979
1917
  y = self.opencti.opencti_stix_object_or_stix_relationship.list(
@@ -2114,84 +2052,47 @@ class OpenCTIStix2:
2114
2052
  fromOrToId=entity["x_opencti_id"], getAll=True, filters=access_filter
2115
2053
  )
2116
2054
  for stix_core_relationship in stix_core_relationships:
2117
- if self.check_max_marking_definition(
2118
- max_marking_definition_entity,
2119
- (
2120
- stix_core_relationship["objectMarking"]
2121
- if "objectMarking" in stix_core_relationship
2122
- else None
2123
- ),
2124
- ):
2125
- objects_to_get.append(
2126
- stix_core_relationship["to"]
2127
- if stix_core_relationship["to"]["id"] != entity["x_opencti_id"]
2128
- else stix_core_relationship["from"]
2129
- )
2130
- relation_object_data = (
2131
- self.prepare_export( # ICI -> remove max marking ?
2132
- self.generate_export(stix_core_relationship),
2133
- "simple",
2134
- max_marking_definition_entity,
2135
- main_filter,
2136
- access_filter,
2137
- )
2138
- )
2139
- relation_object_bundle = self.filter_objects(
2140
- uuids, relation_object_data
2141
- )
2142
- uuids = uuids + [x["id"] for x in relation_object_bundle]
2143
- result = result + relation_object_bundle
2144
- else:
2145
- self.opencti.app_logger.info(
2146
- "Marking definitions are less than max definition, "
2147
- "not exporting the relation AND the target entity.",
2148
- {
2149
- "type": stix_core_relationship["entity_type"],
2150
- "id": stix_core_relationship["id"],
2151
- },
2055
+ objects_to_get.append(
2056
+ stix_core_relationship["to"]
2057
+ if stix_core_relationship["to"]["id"] != entity["x_opencti_id"]
2058
+ else stix_core_relationship["from"]
2059
+ )
2060
+ relation_object_data = (
2061
+ self.prepare_export( # ICI -> remove max marking ?
2062
+ entity=self.generate_export(stix_core_relationship),
2063
+ mode="simple",
2064
+ access_filter=access_filter,
2152
2065
  )
2066
+ )
2067
+ relation_object_bundle = self.filter_objects(
2068
+ uuids, relation_object_data
2069
+ )
2070
+ uuids = uuids + [x["id"] for x in relation_object_bundle]
2071
+ result = result + relation_object_bundle
2072
+
2153
2073
  # Get sighting
2154
2074
  stix_sighting_relationships = self.opencti.stix_sighting_relationship.list(
2155
2075
  fromOrToId=entity["x_opencti_id"], getAll=True, filters=access_filter
2156
2076
  )
2157
2077
  for stix_sighting_relationship in stix_sighting_relationships:
2158
- if self.check_max_marking_definition(
2159
- max_marking_definition_entity,
2160
- (
2161
- stix_sighting_relationship["objectMarking"]
2162
- if "objectMarking" in stix_sighting_relationship
2163
- else None
2164
- ),
2165
- ):
2166
- objects_to_get.append(
2167
- stix_sighting_relationship["to"]
2168
- if stix_sighting_relationship["to"]["id"]
2169
- != entity["x_opencti_id"]
2170
- else stix_sighting_relationship["from"]
2171
- )
2172
- relation_object_data = (
2173
- self.prepare_export( # ICI -> remove max marking ?
2174
- self.generate_export(stix_sighting_relationship),
2175
- "simple",
2176
- max_marking_definition_entity,
2177
- main_filter,
2178
- access_filter,
2179
- )
2180
- )
2181
- relation_object_bundle = self.filter_objects(
2182
- uuids, relation_object_data
2183
- )
2184
- uuids = uuids + [x["id"] for x in relation_object_bundle]
2185
- result = result + relation_object_bundle
2186
- else:
2187
- self.opencti.app_logger.info(
2188
- "Marking definitions are less than max definition, "
2189
- "not exporting the relation AND the target entity.",
2190
- {
2191
- "type": stix_sighting_relationship["entity_type"],
2192
- "id": stix_sighting_relationship["id"],
2193
- },
2078
+ objects_to_get.append(
2079
+ stix_sighting_relationship["to"]
2080
+ if stix_sighting_relationship["to"]["id"] != entity["x_opencti_id"]
2081
+ else stix_sighting_relationship["from"]
2082
+ )
2083
+ relation_object_data = (
2084
+ self.prepare_export( # ICI -> remove max marking ?
2085
+ entity=self.generate_export(stix_sighting_relationship),
2086
+ mode="simple",
2087
+ access_filter=access_filter,
2194
2088
  )
2089
+ )
2090
+ relation_object_bundle = self.filter_objects(
2091
+ uuids, relation_object_data
2092
+ )
2093
+ uuids = uuids + [x["id"] for x in relation_object_bundle]
2094
+ result = result + relation_object_bundle
2095
+
2195
2096
  if no_custom_attributes:
2196
2097
  del entity["x_opencti_id"]
2197
2098
  # Export
@@ -2219,16 +2120,16 @@ class OpenCTIStix2:
2219
2120
  {"type": entity_object["entity_type"]}
2220
2121
  ),
2221
2122
  )
2222
- entity_object_data = do_read(
2223
- id=entity_object["id"], filters=access_filter
2123
+
2124
+ query_filters = self.prepare_id_filters_export(
2125
+ entity_object["id"], access_filter
2224
2126
  )
2127
+ entity_object_data = do_read(filters=query_filters)
2225
2128
  if entity_object_data is not None:
2226
2129
  stix_entity_object = self.prepare_export(
2227
- self.generate_export(entity_object_data),
2228
- "simple",
2229
- max_marking_definition_entity,
2230
- main_filter,
2231
- access_filter,
2130
+ entity=self.generate_export(entity_object_data),
2131
+ mode="simple",
2132
+ access_filter=access_filter,
2232
2133
  )
2233
2134
  # Add to result
2234
2135
  entity_object_bundle = self.filter_objects(
@@ -2244,7 +2145,7 @@ class OpenCTIStix2:
2244
2145
  return current_relation_object.id == relation_object["id"]
2245
2146
 
2246
2147
  relation_object_data = self.prepare_export(
2247
- filter(
2148
+ entity=filter(
2248
2149
  find_relation_object_data,
2249
2150
  self.opencti.stix_core_relationship.list(filters=access_filter),
2250
2151
  )
@@ -2264,7 +2165,6 @@ class OpenCTIStix2:
2264
2165
  report_object_data = self.opencti.report.to_stix2(
2265
2166
  entity=report,
2266
2167
  mode="simple",
2267
- max_marking_definition_entity=max_marking_definition_entity,
2268
2168
  )
2269
2169
  report_object_bundle = self.filter_objects(
2270
2170
  uuids, report_object_data
@@ -2283,7 +2183,6 @@ class OpenCTIStix2:
2283
2183
  # note_object_data = self.opencti.note.to_stix2(
2284
2184
  # entity=note,
2285
2185
  # mode="simple",
2286
- # max_marking_definition_entity=max_marking_definition_entity,
2287
2186
  # )
2288
2187
  # note_object_bundle = self.filter_objects(
2289
2188
  # uuids, note_object_data
@@ -2312,14 +2211,12 @@ class OpenCTIStix2:
2312
2211
  else:
2313
2212
  return []
2314
2213
 
2315
- def export_entity(
2214
+ def get_stix_bundle_or_object_from_entity_id(
2316
2215
  self,
2317
2216
  entity_type: str,
2318
2217
  entity_id: str,
2319
2218
  mode: str = "simple",
2320
- main_filter: Dict = None,
2321
2219
  access_filter: Dict = None,
2322
- max_marking_definition: Dict = None,
2323
2220
  no_custom_attributes: bool = False,
2324
2221
  only_entity: bool = False,
2325
2222
  ) -> Dict:
@@ -2338,12 +2235,11 @@ class OpenCTIStix2:
2338
2235
  if LocationTypes.has_value(entity_type):
2339
2236
  entity_type = "Location"
2340
2237
 
2341
- # Lister
2342
- listers = self.get_listers()
2343
- do_list = listers.get(
2238
+ readers = self.get_readers()
2239
+ do_read = readers.get(
2344
2240
  entity_type, lambda **kwargs: self.unknown_type({"type": entity_type})
2345
2241
  )
2346
- entity = do_list(filters=main_filter)[0]
2242
+ entity = do_read(id=entity_id)
2347
2243
  if entity is None:
2348
2244
  self.opencti.app_logger.error(
2349
2245
  "Cannot export entity (not found)", {"id": entity_id}
@@ -2351,12 +2247,10 @@ class OpenCTIStix2:
2351
2247
  return bundle
2352
2248
  entity_standard_id = entity["standard_id"]
2353
2249
  stix_objects = self.prepare_export(
2354
- self.generate_export(entity, no_custom_attributes),
2355
- mode,
2356
- None,
2357
- main_filter,
2358
- access_filter,
2359
- no_custom_attributes,
2250
+ entity=self.generate_export(entity, no_custom_attributes),
2251
+ mode=mode,
2252
+ access_filter=access_filter,
2253
+ no_custom_attributes=no_custom_attributes,
2360
2254
  )
2361
2255
  if stix_objects is not None:
2362
2256
  bundle["objects"].extend(stix_objects)
@@ -2366,6 +2260,26 @@ class OpenCTIStix2:
2366
2260
  ]
2367
2261
  return bundle
2368
2262
 
2263
+ # Please use get_stix_bundle_or_object_from_entity_id instead
2264
+ @DeprecationWarning
2265
+ def export_entity(
2266
+ self,
2267
+ entity_type: str,
2268
+ entity_id: str,
2269
+ mode: str = "simple",
2270
+ access_filter: Dict = None,
2271
+ no_custom_attributes: bool = False,
2272
+ only_entity: bool = False,
2273
+ ) -> Dict:
2274
+ return self.get_stix_bundle_or_object_from_entity_id(
2275
+ entity_type=entity_type,
2276
+ entity_id=entity_id,
2277
+ mode=mode,
2278
+ access_filter=access_filter,
2279
+ no_custom_attributes=no_custom_attributes,
2280
+ only_entity=only_entity,
2281
+ )
2282
+
2369
2283
  def export_entities_list(
2370
2284
  self,
2371
2285
  entity_type: str,
@@ -2374,7 +2288,7 @@ class OpenCTIStix2:
2374
2288
  orderBy: str = None,
2375
2289
  orderMode: str = None,
2376
2290
  getAll: bool = True,
2377
- ) -> Dict:
2291
+ ) -> [Dict]:
2378
2292
  if IdentityTypes.has_value(entity_type):
2379
2293
  entity_type = "Identity"
2380
2294
 
@@ -2447,7 +2361,6 @@ class OpenCTIStix2:
2447
2361
  order_by: str = None,
2448
2362
  order_mode: str = None,
2449
2363
  mode: str = "simple",
2450
- main_filter: Dict = None,
2451
2364
  access_filter: Dict = None,
2452
2365
  ) -> Dict:
2453
2366
  bundle = {
@@ -2455,14 +2368,14 @@ class OpenCTIStix2:
2455
2368
  "id": "bundle--" + str(uuid.uuid4()),
2456
2369
  "objects": [],
2457
2370
  }
2458
- filterGroups = []
2371
+ filter_groups = []
2459
2372
  if filters is not None:
2460
- filterGroups.append(filters)
2373
+ filter_groups.append(filters)
2461
2374
  if access_filter is not None:
2462
- filterGroups.append(access_filter)
2375
+ filter_groups.append(access_filter)
2463
2376
  export_query_filter = {
2464
2377
  "mode": "and",
2465
- "filterGroups": filterGroups,
2378
+ "filterGroups": filter_groups,
2466
2379
  "filters": [],
2467
2380
  }
2468
2381
  entities_list = self.export_entities_list(
@@ -2477,11 +2390,9 @@ class OpenCTIStix2:
2477
2390
  uuids = []
2478
2391
  for entity in entities_list:
2479
2392
  entity_bundle = self.prepare_export(
2480
- self.generate_export(entity),
2481
- mode,
2482
- None,
2483
- main_filter,
2484
- access_filter,
2393
+ entity=self.generate_export(entity),
2394
+ mode=mode,
2395
+ access_filter=access_filter,
2485
2396
  )
2486
2397
  if entity_bundle is not None:
2487
2398
  entity_bundle_filtered = self.filter_objects(uuids, entity_bundle)
@@ -2492,45 +2403,31 @@ class OpenCTIStix2:
2492
2403
 
2493
2404
  def export_selected(
2494
2405
  self,
2495
- entities_list: [str],
2406
+ entities_list: [dict],
2496
2407
  mode: str = "simple",
2497
- main_filter: Dict = None,
2498
2408
  access_filter: Dict = None,
2499
2409
  ) -> Dict:
2500
2410
 
2501
- entity_data_sdo = self.opencti.stix_domain_object.list(filters=main_filter)
2502
- entity_data_sco = self.opencti.stix_cyber_observable.list(filters=main_filter)
2503
- entity_data_scr = self.opencti.stix_core_relationship.list(filters=main_filter)
2504
- entity_data_ssr = self.opencti.stix_sighting_relationship.list(
2505
- filters=main_filter
2506
- )
2507
-
2508
- entities_list = (
2509
- entity_data_sdo + entity_data_sco + entity_data_scr + entity_data_ssr
2510
- )
2511
2411
  bundle = {
2512
2412
  "type": "bundle",
2513
2413
  "id": "bundle--" + str(uuid.uuid4()),
2514
2414
  "objects": [],
2515
2415
  }
2516
2416
 
2517
- if entities_list is not None:
2518
- uuids = []
2519
- for entity in entities_list:
2520
- entity_bundle = self.prepare_export(
2521
- self.generate_export(entity),
2522
- mode,
2523
- None,
2524
- main_filter,
2525
- access_filter,
2526
- )
2527
- if entity_bundle is not None:
2528
- entity_bundle_filtered = self.filter_objects(uuids, entity_bundle)
2529
- for x in entity_bundle_filtered:
2530
- uuids.append(x["id"])
2531
- bundle["objects"] = (
2532
- bundle["objects"] + entity_bundle_filtered
2533
- ) # unsupported operand type(s) for +: 'dict' and 'list'
2417
+ uuids = []
2418
+ for entity in entities_list:
2419
+ entity_bundle = self.prepare_export(
2420
+ entity=self.generate_export(entity),
2421
+ mode=mode,
2422
+ access_filter=access_filter,
2423
+ )
2424
+ if entity_bundle is not None:
2425
+ entity_bundle_filtered = self.filter_objects(uuids, entity_bundle)
2426
+ for x in entity_bundle_filtered:
2427
+ uuids.append(x["id"])
2428
+ bundle["objects"] = (
2429
+ bundle["objects"] + entity_bundle_filtered
2430
+ ) # unsupported operand type(s) for +: 'dict' and 'list'
2534
2431
 
2535
2432
  return bundle
2536
2433
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycti
3
- Version: 6.1.0
3
+ Version: 6.1.1
4
4
  Summary: Python API client for OpenCTI.
5
5
  Home-page: https://github.com/OpenCTI-Platform/client-python
6
6
  Author: Filigran
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes