Skip to content

Commit 4e97549

Browse files
committed
[client] Implement get_all everywhere
1 parent cd25966 commit 4e97549

6 files changed

+162
-30
lines changed

pycti/entities/opencti_campaign.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def list(self, **kwargs):
160160
get_all = kwargs.get("getAll", False)
161161
with_pagination = kwargs.get("withPagination", False)
162162
if get_all:
163-
first = 500
163+
first = 100
164164

165165
LOGGER.info("Listing Campaigns with filters %s.", json.dumps(filters))
166166
query = (
@@ -196,9 +196,31 @@ def list(self, **kwargs):
196196
"orderMode": order_mode,
197197
},
198198
)
199-
return self.opencti.process_multiple(
200-
result["data"]["campaigns"], with_pagination
201-
)
199+
if get_all:
200+
final_data = []
201+
data = self.opencti.process_multiple(result["data"]["campaigns"])
202+
final_data = final_data + data
203+
while result["data"]["campaigns"]["pageInfo"]["hasNextPage"]:
204+
after = result["data"]["campaigns"]["pageInfo"]["endCursor"]
205+
LOGGER.info("Listing Campaigns after " + after)
206+
result = self.opencti.query(
207+
query,
208+
{
209+
"filters": filters,
210+
"search": search,
211+
"first": first,
212+
"after": after,
213+
"orderBy": order_by,
214+
"orderMode": order_mode,
215+
},
216+
)
217+
data = self.opencti.process_multiple(result["data"]["campaigns"])
218+
final_data = final_data + data
219+
return final_data
220+
else:
221+
return self.opencti.process_multiple(
222+
result["data"]["campaigns"], with_pagination
223+
)
202224

203225
"""
204226
Read a Campaign object

pycti/entities/opencti_course_of_action.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ def list(self, **kwargs):
161161
get_all = kwargs.get("getAll", False)
162162
with_pagination = kwargs.get("withPagination", False)
163163
if get_all:
164-
first = 500
164+
first = 100
165165

166-
LOGGER.info("Listing Course-Of-Actions with filters %s.", json.dumps(filters))
166+
LOGGER.info("Listing Courses-Of-Action with filters %s.", json.dumps(filters))
167167
query = (
168168
"""
169169
query CoursesOfAction($filters: [CoursesOfActionFiltering], $search: String, $first: Int, $after: ID, $orderBy: CoursesOfActionOrdering, $orderMode: OrderingMode) {
@@ -197,9 +197,31 @@ def list(self, **kwargs):
197197
"orderMode": order_mode,
198198
},
199199
)
200-
return self.opencti.process_multiple(
201-
result["data"]["coursesOfAction"], with_pagination
202-
)
200+
if get_all:
201+
final_data = []
202+
data = self.opencti.process_multiple(result["data"]["coursesOfAction"])
203+
final_data = final_data + data
204+
while result["data"]["coursesOfAction"]["pageInfo"]["hasNextPage"]:
205+
after = result["data"]["coursesOfAction"]["pageInfo"]["endCursor"]
206+
LOGGER.info("Listing Courses-Of-Action after " + after)
207+
result = self.opencti.query(
208+
query,
209+
{
210+
"filters": filters,
211+
"search": search,
212+
"first": first,
213+
"after": after,
214+
"orderBy": order_by,
215+
"orderMode": order_mode,
216+
},
217+
)
218+
data = self.opencti.process_multiple(result["data"]["coursesOfAction"])
219+
final_data = final_data + data
220+
return final_data
221+
else:
222+
return self.opencti.process_multiple(
223+
result["data"]["coursesOfAction"], with_pagination
224+
)
203225

204226
"""
205227
Read a Course-Of-Action object

pycti/entities/opencti_data_component.py

+29-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from stix2.canonicalization.Canonicalize import canonicalize
77

8+
from pycti.entities import LOGGER
9+
810

911
class DataComponent:
1012
def __init__(self, opencti):
@@ -173,12 +175,9 @@ def list(self, **kwargs):
173175
get_all = kwargs.get("getAll", False)
174176
with_pagination = kwargs.get("withPagination", False)
175177
if get_all:
176-
first = 500
178+
first = 100
177179

178-
self.opencti.log(
179-
"info",
180-
"Listing Data-Components with filters " + json.dumps(filters) + ".",
181-
)
180+
LOGGER.info("Listing Data-Components with filters " + json.dumps(filters) + ".")
182181
query = (
183182
"""
184183
query DataComponents($filters: [DataComponentsFiltering!], $search: String, $first: Int, $after: ID, $orderBy: DataComponentsOrdering, $orderMode: OrderingMode) {
@@ -212,10 +211,31 @@ def list(self, **kwargs):
212211
"orderMode": order_mode,
213212
},
214213
)
215-
# TODO: get_all ?
216-
return self.opencti.process_multiple(
217-
result["data"]["dataComponents"], with_pagination
218-
)
214+
if get_all:
215+
final_data = []
216+
data = self.opencti.process_multiple(result["data"]["dataComponents"])
217+
final_data = final_data + data
218+
while result["data"]["dataComponents"]["pageInfo"]["hasNextPage"]:
219+
after = result["data"]["dataComponents"]["pageInfo"]["endCursor"]
220+
LOGGER.info("Listing Data-Components after " + after)
221+
result = self.opencti.query(
222+
query,
223+
{
224+
"filters": filters,
225+
"search": search,
226+
"first": first,
227+
"after": after,
228+
"orderBy": order_by,
229+
"orderMode": order_mode,
230+
},
231+
)
232+
data = self.opencti.process_multiple(result["data"]["dataComponents"])
233+
final_data = final_data + data
234+
return final_data
235+
else:
236+
return self.opencti.process_multiple(
237+
result["data"]["dataComponents"], with_pagination
238+
)
219239

220240
"""
221241
Read a Data-Component object

pycti/entities/opencti_data_source.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from stix2.canonicalization.Canonicalize import canonicalize
77

8+
from pycti.entities import LOGGER
9+
810

911
class DataSource:
1012
def __init__(self, opencti):
@@ -157,7 +159,7 @@ def list(self, **kwargs):
157159
get_all = kwargs.get("getAll", False)
158160
with_pagination = kwargs.get("withPagination", False)
159161
if get_all:
160-
first = 500
162+
first = 100
161163

162164
self.opencti.log(
163165
"info",
@@ -196,10 +198,31 @@ def list(self, **kwargs):
196198
"orderMode": order_mode,
197199
},
198200
)
199-
# TODO: get_all ?
200-
return self.opencti.process_multiple(
201-
result["data"]["dataSources"], with_pagination
202-
)
201+
if get_all:
202+
final_data = []
203+
data = self.opencti.process_multiple(result["data"]["dataSources"])
204+
final_data = final_data + data
205+
while result["data"]["dataSources"]["pageInfo"]["hasNextPage"]:
206+
after = result["data"]["dataSources"]["pageInfo"]["endCursor"]
207+
LOGGER.info("Listing Data-Sources after " + after)
208+
result = self.opencti.query(
209+
query,
210+
{
211+
"filters": filters,
212+
"search": search,
213+
"first": first,
214+
"after": after,
215+
"orderBy": order_by,
216+
"orderMode": order_mode,
217+
},
218+
)
219+
data = self.opencti.process_multiple(result["data"]["dataSources"])
220+
final_data = final_data + data
221+
return final_data
222+
else:
223+
return self.opencti.process_multiple(
224+
result["data"]["dataSources"], with_pagination
225+
)
203226

204227
"""
205228
Read a Data-Source object

pycti/entities/opencti_external_reference.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def list(self, **kwargs):
7474
get_all = kwargs.get("getAll", False)
7575
with_pagination = kwargs.get("withPagination", False)
7676
if get_all:
77-
first = 500
77+
first = 100
7878

7979
LOGGER.info("Listing External-Reference with filters %s.", json.dumps(filters))
8080
query = (
@@ -109,9 +109,32 @@ def list(self, **kwargs):
109109
"orderMode": order_mode,
110110
},
111111
)
112-
return self.opencti.process_multiple(
113-
result["data"]["externalReferences"], with_pagination
114-
)
112+
if get_all:
113+
final_data = []
114+
data = self.opencti.process_multiple(result["data"]["externalReferences"])
115+
final_data = final_data + data
116+
while result["data"]["externalReferences"]["pageInfo"]["hasNextPage"]:
117+
after = result["data"]["externalReferences"]["pageInfo"]["endCursor"]
118+
LOGGER.info("Listing External-References after " + after)
119+
result = self.opencti.query(
120+
query,
121+
{
122+
"filters": filters,
123+
"first": first,
124+
"after": after,
125+
"orderBy": order_by,
126+
"orderMode": order_mode,
127+
},
128+
)
129+
data = self.opencti.process_multiple(
130+
result["data"]["externalReferences"]
131+
)
132+
final_data = final_data + data
133+
return final_data
134+
else:
135+
return self.opencti.process_multiple(
136+
result["data"]["externalReferences"], with_pagination
137+
)
115138

116139
"""
117140
Read a External-Reference object

pycti/entities/opencti_identity.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,31 @@ def list(self, **kwargs):
207207
"orderMode": order_mode,
208208
},
209209
)
210-
return self.opencti.process_multiple(
211-
result["data"]["identities"], with_pagination
212-
)
210+
if get_all:
211+
final_data = []
212+
data = self.opencti.process_multiple(result["data"]["identities"])
213+
final_data = final_data + data
214+
while result["data"]["identities"]["pageInfo"]["hasNextPage"]:
215+
after = result["data"]["identities"]["pageInfo"]["endCursor"]
216+
LOGGER.info("Listing Identities after " + after)
217+
result = self.opencti.query(
218+
query,
219+
{
220+
"filters": filters,
221+
"search": search,
222+
"first": first,
223+
"after": after,
224+
"orderBy": order_by,
225+
"orderMode": order_mode,
226+
},
227+
)
228+
data = self.opencti.process_multiple(result["data"]["identities"])
229+
final_data = final_data + data
230+
return final_data
231+
else:
232+
return self.opencti.process_multiple(
233+
result["data"]["identities"], with_pagination
234+
)
213235

214236
"""
215237
Read a Identity object

0 commit comments

Comments
 (0)