Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit c99eea9

Browse files
authored
[client-python] Adapt client python to support new filters format (#499)
Related to OpenCTI-Platform/opencti#2686
1 parent 21c1b1e commit c99eea9

File tree

58 files changed

+390
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+390
-157
lines changed

examples/cmd_line_tag_latest_indicators_of_threat.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ def main():
6363

6464
# Resolve the entity
6565
threat = opencti_api_client.stix_domain_object.read(
66-
types=[entity_type], filters=[{"key": "name", "values": [name]}]
66+
types=[entity_type],
67+
filters={
68+
"mode": "and",
69+
"filters": [{"key": "name", "values": [name]}],
70+
"filterGroups": [],
71+
},
6772
)
6873

6974
if not threat:
@@ -87,11 +92,15 @@ def main():
8792
first=50,
8893
after=after,
8994
customAttributes=custom_attributes,
90-
filters=[
91-
{"key": "indicates", "values": [threat["id"]]},
92-
{"key": "created_at", "values": [created_after], "operator": "gt"},
93-
{"key": "created_at", "values": [created_before], "operator": "lt"},
94-
],
95+
filters={
96+
"mode": "and",
97+
"filters": [
98+
{"key": "indicates", "values": [threat["id"]]},
99+
{"key": "created_at", "values": [created_after], "operator": "gt"},
100+
{"key": "created_at", "values": [created_before], "operator": "lt"},
101+
],
102+
"filterGroups": [],
103+
},
95104
orderBy="created_at",
96105
orderMode="asc",
97106
withPagination=True,

examples/delete_intrusion_set.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
# Get the intrusion set APT28
2222
intrusion_set = opencti_api_client.intrusion_set.read(
23-
filters=[{"key": "name", "values": ["EvilSET123"]}]
23+
filters={
24+
"mode": "and",
25+
"filters": [{"key": "name", "values": ["EvilSET123"]}],
26+
"filterGroups": [],
27+
}
2428
)
2529

2630
# Delete the intrusion set

examples/export_incident_stix2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
# Get the incident created in the create_incident_with_ttps_and_indicators.py
1717
incident = opencti_api_client.incident.read(
18-
filters=[{"key": "name", "values": ["My new incident"]}]
18+
filters={
19+
"mode": "and",
20+
"filters": [{"key": "name", "values": ["My new incident"]}],
21+
"filterGroups": [],
22+
}
1923
)
2024

2125
# Create the bundle

examples/get_attack_pattern_by_mitre_id.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
# Get the Attack-Pattern T1514
1313
attack_pattern = opencti_api_client.attack_pattern.read(
14-
filters=[{"key": "x_mitre_id", "values": ["T1514"]}]
14+
filters={
15+
"mode": "and",
16+
"filters": [{"key": "x_mitre_id", "values": ["T1514"]}],
17+
"filterGroups": [],
18+
}
1519
)
1620

1721
# Print

examples/get_malwares_of_intrusion_set.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
# Get the intrusion set APT28
2323
intrusion_set = opencti_api_client.intrusion_set.read(
24-
filters=[{"key": "name", "values": ["APT28"]}]
24+
filters={
25+
"mode": "and",
26+
"filters": [{"key": "name", "values": ["APT28"]}],
27+
"filterGroups": [],
28+
}
2529
)
2630

2731
# Get the relations from APT28 to malwares

examples/get_observable_exact_match.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
)
1616
print("IP ADDRESS")
1717
observable = opencti_api_client.stix_cyber_observable.read(
18-
filters=[{"key": "value", "values": ["110.172.180.180"]}]
18+
filters={
19+
"mode": "and",
20+
"filters": [{"key": "value", "values": ["110.172.180.180"]}],
21+
"filterGroups": [],
22+
}
1923
)
2024
print(observable)
2125

@@ -25,7 +29,11 @@
2529
)
2630
print("FILE NAME")
2731
observable = opencti_api_client.stix_cyber_observable.read(
28-
filters=[{"key": "name", "values": ["activeds.dll"]}]
32+
filters={
33+
"mode": "and",
34+
"filters": [{"key": "name", "values": ["activeds.dll"]}],
35+
"filterGroups": [],
36+
}
2937
)
3038
print(observable)
3139

@@ -36,6 +44,12 @@
3644
)
3745
print("FILE MD5")
3846
observable = opencti_api_client.stix_cyber_observable.read(
39-
filters=[{"key": "hashes_MD5", "values": ["3aad33e025303dbae12c12b4ec5258c1"]}]
47+
filters={
48+
"mode": "and",
49+
"filters": [
50+
{"key": "hashes.MD5", "values": ["3aad33e025303dbae12c12b4ec5258c1"]}
51+
],
52+
"filterGroups": [],
53+
}
4054
)
4155
print(observable)

examples/get_reports_about_intrusion_set.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@
2222

2323
# Get the intrusion set Sandworm
2424
intrusion_set = opencti_api_client.intrusion_set.read(
25-
filters=[{"key": "name", "values": ["Sandworm Team"]}]
25+
filters={
26+
"mode": "and",
27+
"filters": [{"key": "name", "values": ["Sandworm Team"]}],
28+
"filterGroups": [],
29+
}
2630
)
2731

2832
# Get all reports
2933
reports = opencti_api_client.report.list(
30-
filters=[{"key": "objectContains", "values": [intrusion_set["id"]]}],
34+
filters={
35+
"mode": "and",
36+
"filters": [{"key": "contains", "values": [intrusion_set["id"]]}],
37+
"filterGroups": [],
38+
},
3139
orderBy="published",
3240
orderMode="asc",
3341
)

examples/update_entity_attribute.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
# Get the intrusion set APT28
2323
intrusion_set = opencti_api_client.intrusion_set.read(
24-
filters=[{"key": "name", "values": ["APT28"]}]
24+
filters={
25+
"mode": "and",
26+
"filters": [{"key": "name", "values": ["APT28"]}],
27+
"filterGroups": [],
28+
}
2529
)
2630

2731
# Update the description

pycti/api/opencti_api_work.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def get_connector_works(self, connector_id: str) -> List[Dict]:
161161
$count: Int
162162
$orderBy: WorksOrdering
163163
$orderMode: OrderingMode
164-
$filters: [WorksFiltering]
164+
$filters: FilterGroup
165165
) {
166166
works(
167167
first: $count
@@ -207,9 +207,11 @@ def get_connector_works(self, connector_id: str) -> List[Dict]:
207207
query,
208208
{
209209
"count": 50,
210-
"filters": [
211-
{"key": "connector_id", "values": [connector_id]},
212-
],
210+
"filters": {
211+
"mode": "and",
212+
"filters": [{"key": "connector_id", "values": [connector_id]}],
213+
"filterGroups": [],
214+
},
213215
},
214216
)
215217
result = result["data"]["works"]["edges"]

pycti/entities/opencti_attack_pattern.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def list(self, **kwargs):
292292
LOGGER.info("Listing Attack-Patterns with filters %s.", json.dumps(filters))
293293
query = (
294294
"""
295-
query AttackPatterns($filters: [AttackPatternsFiltering], $search: String, $first: Int, $after: ID, $orderBy: AttackPatternsOrdering, $orderMode: OrderingMode) {
295+
query AttackPatterns($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: AttackPatternsOrdering, $orderMode: OrderingMode) {
296296
attackPatterns(filters: $filters, search: $search, first: $first, after: $after, orderBy: $orderBy, orderMode: $orderMode) {
297297
edges {
298298
node {

0 commit comments

Comments
 (0)