Skip to content

Commit 0046fed

Browse files
[client] Add Data Component and Data Sourcer entities (OpenCTI-Platform#304)
Co-authored-by: Julien Richard <julien.richard@filigran.io>
1 parent b8e974e commit 0046fed

10 files changed

+1005
-0
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@ To learn about how to use the OpenCTI Python client and read some examples and c
5454

5555
To learn about the methods available for executing queries and retrieving their answers, refer to [the client API Reference](https://opencti-client-for-python.readthedocs.io/en/latest/pycti/pycti.html).
5656

57+
## Tests
58+
59+
### Install dependencies
60+
61+
```bash
62+
$ pip install -r ./test-requirements.txt
63+
```
64+
65+
[pytest](https://docs.pytest.org/en/7.2.x/) is used to launch the tests.
66+
67+
### Launch tests
68+
69+
#### Prerequisite
70+
71+
Your OpenCTI API should be running.
72+
Your conftest.py should be configured with your API url and your token.
73+
74+
#### Launching
75+
76+
Unit tests
77+
```bash
78+
$ pytest ./tests/01-unit/
79+
```
80+
81+
Integration testing
82+
```bash
83+
$ pytest ./tests/02-integration/
84+
```
85+
5786
## About
5887

5988
OpenCTI is a product powered by the collaboration of the private company [Filigran](https://www.filigran.io), the [French national cybersecurity agency (ANSSI)](https://ssi.gouv.fr), the [CERT-EU](https://cert.europa.eu) and the [Luatix](https://www.luatix.org) non-profit organization.

pycti/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from .entities.opencti_attack_pattern import AttackPattern
1313
from .entities.opencti_campaign import Campaign
1414
from .entities.opencti_course_of_action import CourseOfAction
15+
from .entities.opencti_data_component import DataComponent
16+
from .entities.opencti_data_source import DataSource
1517
from .entities.opencti_external_reference import ExternalReference
1618
from .entities.opencti_grouping import Grouping
1719
from .entities.opencti_identity import Identity
@@ -56,6 +58,8 @@
5658
"Campaign",
5759
"ConnectorType",
5860
"CourseOfAction",
61+
"DataComponent",
62+
"DataSource",
5963
"ExternalReference",
6064
"Grouping",
6165
"Identity",

pycti/api/opencti_api_client.py

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from pycti.entities.opencti_campaign import Campaign
1818
from pycti.entities.opencti_channel import Channel
1919
from pycti.entities.opencti_course_of_action import CourseOfAction
20+
from pycti.entities.opencti_data_component import DataComponent
21+
from pycti.entities.opencti_data_source import DataSource
2022
from pycti.entities.opencti_event import Event
2123
from pycti.entities.opencti_external_reference import ExternalReference
2224
from pycti.entities.opencti_grouping import Grouping
@@ -52,6 +54,7 @@
5254
from pycti.entities.opencti_tool import Tool
5355
from pycti.entities.opencti_vulnerability import Vulnerability
5456
from pycti.utils.opencti_stix2 import OpenCTIStix2
57+
from pycti.utils.opencti_stix2_utils import OpenCTIStix2Utils
5558

5659
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
5760

@@ -177,6 +180,8 @@ def __init__(
177180
self.vulnerability = Vulnerability(self)
178181
self.attack_pattern = AttackPattern(self)
179182
self.course_of_action = CourseOfAction(self)
183+
self.data_component = DataComponent(self)
184+
self.data_source = DataSource(self)
180185
self.report = Report(self)
181186
self.note = Note(self)
182187
self.observed_data = ObservedData(self)
@@ -497,6 +502,13 @@ def process_multiple_fields(self, data):
497502
:rtype: dict
498503
"""
499504

505+
# Handle process_multiple_fields specific case
506+
attribute = OpenCTIStix2Utils.retrieveClassForMethod(
507+
self, data, "entity_type", "process_multiple_fields"
508+
)
509+
if attribute is not None:
510+
data = attribute.process_multiple_fields(data)
511+
500512
if data is None:
501513
return data
502514
if "createdBy" in data and data["createdBy"] is not None:

0 commit comments

Comments
 (0)