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

Commit 7bf2aca

Browse files
author
peritz
committed
Correct minor issues around typing and args convention
1 parent fa1d099 commit 7bf2aca

File tree

4 files changed

+74
-59
lines changed

4 files changed

+74
-59
lines changed

pycti/entities/opencti_group.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Dict
1+
from typing import List, Dict, Optional
22

33

44
class Group:
@@ -187,17 +187,19 @@ def list(self, **kwargs) -> List[Dict]:
187187
return self.opencti.process_multiple(result["data"]["groups"],
188188
withPagination)
189189

190-
def read(self, **kwargs) -> Dict:
190+
def read(self, **kwargs) -> Optional[Dict]:
191191
"""Fetch a given group from OpenCTI
192192
193+
One of id or filters is required.
194+
193195
:param id: ID of the group to fetch
194196
:type id: str, optional
195197
:param filters: Filters to apply to find single group
196198
:type filters: dict, optional
197199
:param customAttributes: Custom attributes to fetch for the group
198200
:type customAttributes: str
199201
:return: Representation of a group.
200-
:rtype: dict
202+
:rtype: Optional[Dict]
201203
"""
202204
id = kwargs.get("id", None)
203205
filters = kwargs.get("filters", None)
@@ -222,14 +224,15 @@ def read(self, **kwargs) -> Dict:
222224
return self.opencti.process_multiple_fields(
223225
result["data"]["group"])
224226
elif filters is not None or search is not None:
225-
results = self.list(filters=filters, search=search)
227+
results = self.list(filters=filters, search=search,
228+
customAttributes=customAttributes)
226229
return results[0] if results else None
227230
else:
228231
self.opencti.admin_logger.error(
229232
"[opencti_group] Missing parameters: id or filters")
230233
return None
231234

232-
def create(self, **kwargs) -> dict:
235+
def create(self, **kwargs) -> Optional[Dict]:
233236
"""Create a group with required details
234237
235238
Groups can be configured after creation using other functions.
@@ -257,7 +260,7 @@ def create(self, **kwargs) -> dict:
257260
:param customAttributes: Attributes to retrieve from the new group
258261
:type customAttributes: str, optional
259262
:return: Representation of the group.
260-
:rtype: dict
263+
:rtype: Optional[Dict]
261264
"""
262265
name = kwargs.get("name", None)
263266
group_confidence_level = kwargs.get("group_confidence_level", None)
@@ -325,7 +328,7 @@ def delete(self, id: str):
325328
"""
326329
self.opencti.query(query, {"id": id})
327330

328-
def update_field(self, **kwargs) -> Dict:
331+
def update_field(self, **kwargs) -> Optional[Dict]:
329332
"""Update a group using fieldPatch
330333
331334
:param id: ID of the group to update
@@ -335,7 +338,7 @@ def update_field(self, **kwargs) -> Dict:
335338
:param customAttributes: Custom attributes to retrieve from group
336339
:type customAttribues: str, optional
337340
:return: Representation of a group
338-
:rtype: dict
341+
:rtype: Optional[Dict]
339342
"""
340343
id = kwargs.get("id", None)
341344
input = kwargs.get("input", None)
@@ -366,15 +369,15 @@ def update_field(self, **kwargs) -> Dict:
366369
return self.opencti.process_multiple_fields(
367370
result["data"]["groupEdit"]["fieldPatch"])
368371

369-
def add_member(self, **kwargs) -> dict:
372+
def add_member(self, **kwargs) -> Optional[Dict]:
370373
"""Add a member to a given group.
371374
372375
:param id: ID of the group to add a member to
373376
:type id: str
374377
:param user_id: ID to add to the group
375378
:type user_id: str
376379
:return: Representation of the relationship
377-
:rtype: dict
380+
:rtype: Optional[Dict]
378381
"""
379382
id = kwargs.get("id", None)
380383
user_id = kwargs.get("user_id", None)
@@ -412,15 +415,15 @@ def add_member(self, **kwargs) -> dict:
412415
return self.opencti.process_multiple_fields(
413416
result["data"]["groupEdit"]["relationAdd"])
414417

415-
def delete_member(self, **kwargs) -> dict:
418+
def delete_member(self, **kwargs) -> Optional[Dict]:
416419
"""Remove a given user from a group
417420
418421
:param id: ID to remove a user from
419422
:type id: str
420423
:param user: ID to remove from the group
421424
:type user: str
422425
:return: Representation of the group after the member has been removed
423-
:rtype: dict
426+
:rtype: Optional[Dict]
424427
"""
425428
id = kwargs.get("id", None)
426429
user_id = kwargs.get("user_id", None)
@@ -450,15 +453,15 @@ def delete_member(self, **kwargs) -> dict:
450453
return self.opencti.process_multiple_fields(
451454
result["data"]["groupEdit"]["relationDelete"])
452455

453-
def add_role(self, **kwargs) -> Dict:
456+
def add_role(self, **kwargs) -> Optional[Dict]:
454457
"""Add a role to a given group
455458
456459
:param id: ID to add a role to
457460
:type id: str
458461
:param role_id: Role ID to add to the group
459462
:type role: str
460463
:return: Representation of the group after a role has been added
461-
:rtype: dict
464+
:rtype: Optional[Dict]
462465
"""
463466
id = kwargs.get("id", None)
464467
role_id = kwargs.get("role_id", None)
@@ -494,15 +497,15 @@ def add_role(self, **kwargs) -> Dict:
494497
return self.opencti.process_multiple_fields(
495498
result["data"]["groupEdit"]["relationAdd"])
496499

497-
def delete_role(self, **kwargs) -> Dict:
500+
def delete_role(self, **kwargs) -> Optional[Dict]:
498501
"""Removes a role from a given group
499502
500503
:param id: ID to remove role from
501504
:type id: str
502505
:param role_id: Role ID to remove from the group
503506
:type role_id: str
504507
:return: Representation of the group after role is removed
505-
:rtype: dict
508+
:rtype: Optional[Dict]
506509
"""
507510
id = kwargs.get("id", None)
508511
role_id = kwargs.get("role_id", None)
@@ -531,7 +534,7 @@ def delete_role(self, **kwargs) -> Dict:
531534
return self.opencti.process_multiple_fields(
532535
result["data"]["groupEdit"]["relationDelete"])
533536

534-
def edit_default_marking(self, **kwargs) -> Dict:
537+
def edit_default_marking(self, **kwargs) -> Optional[Dict]:
535538
"""Adds a default marking to the group.
536539
537540
:param id: ID of the group.
@@ -544,7 +547,7 @@ def edit_default_marking(self, **kwargs) -> Dict:
544547
defaults to "GLOBAL".
545548
:type entity: str, optional
546549
:return: Group after adding the default marking.
547-
:rtype: dict
550+
:rtype: Optional[Dict]
548551
"""
549552
id = kwargs.get("id", None)
550553
marking_ids = kwargs.get("marking_ids", None)
@@ -586,15 +589,15 @@ def edit_default_marking(self, **kwargs) -> Dict:
586589
return self.opencti.process_multiple_fields(
587590
result["data"]["groupEdit"]["editDefaultMarking"])
588591

589-
def add_allowed_marking(self, **kwargs) -> Dict:
592+
def add_allowed_marking(self, **kwargs) -> Optional[Dict]:
590593
"""Allow a group to access a marking
591594
592595
:param id: ID of group to authorise
593596
:type id: str
594597
:param marking_id: ID of marking to authorise
595598
:type marking_id: str
596599
:return: Relationship from the group to the marking definition
597-
:rtype: dict
600+
:rtype: Optional[Dict]
598601
"""
599602
id = kwargs.get("id", None)
600603
marking_id = kwargs.get("marking_id", None)
@@ -653,15 +656,15 @@ def add_allowed_marking(self, **kwargs) -> Dict:
653656
return self.opencti.process_multiple_fields(
654657
result["data"]["groupEdit"]["relationAdd"])
655658

656-
def delete_allowed_marking(self, **kwargs) -> Dict:
659+
def delete_allowed_marking(self, **kwargs) -> Optional[Dict]:
657660
"""Removes access to a marking for a group
658661
659662
:param id: ID of group to forbid
660663
:type id: str
661664
:param marking_id: ID of marking to deny
662665
:type marking_id: str
663666
:return: Group after denying access to marking definition
664-
:rtype: dict
667+
:rtype: Optional[Dict]
665668
"""
666669
id = kwargs.get("id", None)
667670
marking_id = kwargs.get("marking_id", None)

pycti/entities/opencti_role.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List
1+
from typing import Dict, List, Optional
22

33

44
class Role:
@@ -138,7 +138,7 @@ def list(self, **kwargs) -> List[Dict]:
138138
return self.opencti.process_multiple(result["data"]["roles"],
139139
withPagination)
140140

141-
def read(self, **kwargs) -> Dict:
141+
def read(self, **kwargs) -> Optional[Dict]:
142142
"""Get a role given its ID or a search term
143143
144144
One of id or search must be provided.
@@ -151,7 +151,7 @@ def read(self, **kwargs) -> Dict:
151151
:type customAttributes: str, optional
152152
153153
:return: Representation of the role
154-
:rtype: Dict
154+
:rtype: Optional[Dict]
155155
"""
156156
id = kwargs.get("id", None)
157157
search = kwargs.get("search", None)
@@ -185,8 +185,8 @@ def read(self, **kwargs) -> Dict:
185185
def delete(self, **kwargs):
186186
"""Delete a role given its ID
187187
188-
:param role: ID for the role on the platform.
189-
:type role: str
188+
:param id: ID for the role on the platform.
189+
:type id: str
190190
"""
191191
id = kwargs.get("id", None)
192192

@@ -206,7 +206,7 @@ def delete(self, **kwargs):
206206
"""
207207
self.opencti.query(query, {"id": id})
208208

209-
def create(self, **kwargs) -> Dict:
209+
def create(self, **kwargs) -> Optional[Dict]:
210210
"""Add a new role to OpenCTI.
211211
212212
:param name: Name to assign to the role.
@@ -217,7 +217,7 @@ def create(self, **kwargs) -> Dict:
217217
:param customAttributes: Custom attributes to return on role
218218
:type customAttributes: str, optional
219219
:return: Representation of the role.
220-
:rtype: Dict
220+
:rtype: Optional[Dict]
221221
"""
222222
name = kwargs.get("name", None)
223223
description = kwargs.get("description", None)
@@ -252,7 +252,7 @@ def create(self, **kwargs) -> Dict:
252252
})
253253
return self.opencti.process_multiple_fields(result["data"]["roleAdd"])
254254

255-
def update_field(self, **kwargs) -> Dict:
255+
def update_field(self, **kwargs) -> Optional[Dict]:
256256
"""Updates a given role with the given inputs
257257
258258
Example of input::
@@ -276,7 +276,7 @@ def update_field(self, **kwargs) -> Dict:
276276
:type customAttributes: str, optional
277277
278278
:return: Representation of the role
279-
:rtype: Dict
279+
:rtype: Optional[Dict]
280280
"""
281281
id = kwargs.get("id", None)
282282
input = kwargs.get("input", None)
@@ -308,7 +308,7 @@ def update_field(self, **kwargs) -> Dict:
308308
return self.opencti.process_multiple_fields(
309309
result["data"]["roleEdit"]["fieldPatch"])
310310

311-
def add_capability(self, **kwargs) -> Dict:
311+
def add_capability(self, **kwargs) -> Optional[Dict]:
312312
"""Adds a capability to a role
313313
314314
:param id: ID of the role.
@@ -317,7 +317,7 @@ def add_capability(self, **kwargs) -> Dict:
317317
:type capability_id: str
318318
:return: Representation of the relationship, including the role and
319319
capability
320-
:rtype: Dict
320+
:rtype: Optional[Dict]
321321
"""
322322
id = kwargs.get("id", None)
323323
capability_id = kwargs.get("capability_id", None)
@@ -366,15 +366,15 @@ def add_capability(self, **kwargs) -> Dict:
366366
return self.opencti.process_multiple_fields(
367367
result["data"]["roleEdit"]["relationAdd"])
368368

369-
def delete_capability(self, **kwargs) -> Dict:
369+
def delete_capability(self, **kwargs) -> Optional[Dict]:
370370
"""Removes a capability from a role
371371
372372
:param id: ID of the role
373373
:type id: str
374374
:param capability_id: ID of the capability to remove
375375
:type capability_id: str
376376
:return: Representation of the role after removing the capability
377-
:rtype: Dict
377+
:rtype: Optional[Dict]
378378
"""
379379
id = kwargs.get("id", None)
380380
capability_id = kwargs.get("capability_id", None)

pycti/entities/opencti_settings.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict
1+
from typing import Dict, Optional
22

33

44
class Settings:
@@ -247,7 +247,7 @@ def read(self, **kwargs) -> Dict:
247247
result = self.opencti.query(query)
248248
return self.opencti.process_multiple_fields(result["data"]["settings"])
249249

250-
def update_field(self, **kwargs) -> Dict:
250+
def update_field(self, **kwargs) -> Optional[Dict]:
251251
"""Update settings using input to fieldPatch
252252
253253
:param id: ID of the settings object to update
@@ -263,7 +263,7 @@ def update_field(self, **kwargs) -> Dict:
263263
in query response.
264264
:type include_messages: bool, optional
265265
:return: Representation of the platform settings
266-
:rtype: Dict
266+
:rtype: Optional[Dict]
267267
"""
268268
id = kwargs.get("id", None)
269269
input = kwargs.get("input", None)
@@ -302,7 +302,7 @@ def update_field(self, **kwargs) -> Dict:
302302
return self.opencti.process_multiple_fields(
303303
result["data"]["settingsEdit"]["fieldPatch"])
304304

305-
def edit_message(self, **kwargs) -> Dict:
305+
def edit_message(self, **kwargs) -> Optional[Dict]:
306306
"""Edit or add a message to the platform
307307
308308
To add a message, don't include an ID in the input object. To edit a
@@ -313,7 +313,7 @@ def edit_message(self, **kwargs) -> Dict:
313313
:param input: SettingsMessageInput object
314314
:type input: Dict
315315
:return: Settings ID and message objects
316-
:rtype: Dict
316+
:rtype: Optional[Dict]
317317
"""
318318
id = kwargs.get("id", None)
319319
input = kwargs.get("input", None)
@@ -341,15 +341,15 @@ def edit_message(self, **kwargs) -> Dict:
341341
return self.opencti.process_multiple_fields(
342342
result["data"]["settingsEdit"]["editMessage"])
343343

344-
def delete_message(self, **kwargs) -> Dict:
344+
def delete_message(self, **kwargs) -> Optional[Dict]:
345345
"""Delete a message from the platform
346346
347347
:param id: ID of the settings object on the platform
348348
:type id: str
349349
:param input: ID of the message to delete
350350
:type input: str
351351
:return: Settings ID and message objects
352-
:rtype: Dict
352+
:rtype: Optional[Dict]
353353
"""
354354
id = kwargs.get("id", None)
355355
input = kwargs.get("input", None)

0 commit comments

Comments
 (0)