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

Commit 8c7b815

Browse files
richard-julienJeremyCloarec
authored andcommitted
[client] Introduce new class
1 parent 74f9249 commit 8c7b815

13 files changed

+169
-21
lines changed

pycti/api/opencti_api_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
from pycti.api.opencti_api_connector import OpenCTIApiConnector
1313
from pycti.api.opencti_api_draft import OpenCTIApiDraft
1414
from pycti.api.opencti_api_playbook import OpenCTIApiPlaybook
15+
from pycti.api.opencti_api_public_dashboard import OpenCTIApiPublicDashboard
1516
from pycti.api.opencti_api_trash import OpenCTIApiTrash
1617
from pycti.api.opencti_api_work import OpenCTIApiWork
18+
from pycti.api.opencti_api_workspace import OpenCTIApiWorkspace
1719
from pycti.entities.opencti_attack_pattern import AttackPattern
1820
from pycti.entities.opencti_campaign import Campaign
1921
from pycti.entities.opencti_capability import Capability
@@ -171,6 +173,8 @@ def __init__(
171173
self.work = OpenCTIApiWork(self)
172174
self.trash = OpenCTIApiTrash(self)
173175
self.draft = OpenCTIApiDraft(self)
176+
self.workspace = OpenCTIApiWorkspace(self)
177+
self.public_dashboard = OpenCTIApiPublicDashboard(self)
174178
self.playbook = OpenCTIApiPlaybook(self)
175179
self.connector = OpenCTIApiConnector(self)
176180
self.stix2 = OpenCTIStix2(self)

pycti/api/opencti_api_draft.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class OpenCTIApiDraft:
44
def __init__(self, api):
55
self.api = api
66

7-
def delete(self, draft_id: str):
7+
def delete(self, **kwargs):
8+
id = kwargs.get("id", None)
89
query = """
910
mutation DraftWorkspaceDelete($id: ID!) {
1011
draftWorkspaceDelete(id: $id)
@@ -13,6 +14,6 @@ def delete(self, draft_id: str):
1314
self.api.query(
1415
query,
1516
{
16-
"id": draft_id,
17+
"id": id,
1718
},
1819
)

pycti/api/opencti_api_playbook.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ def playbook_step_execution(self, playbook: dict, bundle: str):
3232
"bundle": bundle,
3333
},
3434
)
35+
36+
def delete(self, **kwargs):
37+
id = kwargs.get("id", None)
38+
query = """
39+
mutation PlaybookDelete($id: ID!) {
40+
playbookDelete(id: $id)
41+
}
42+
"""
43+
self.api.query(
44+
query,
45+
{
46+
"id": id,
47+
},
48+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class OpenCTIApiPublicDashboard:
2+
"""OpenCTIApiPublicDashboard"""
3+
4+
def __init__(self, api):
5+
self.api = api
6+
7+
def delete(self, **kwargs):
8+
id = kwargs.get("id", None)
9+
query = """
10+
mutation PublicDashboardDelete($id: ID!) {
11+
publicDashboardDelete(id: $id)
12+
}
13+
"""
14+
self.api.query(
15+
query,
16+
{
17+
"id": id,
18+
},
19+
)

pycti/api/opencti_api_trash.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class OpenCTIApiTrash:
44
def __init__(self, api):
55
self.api = api
66

7-
def delete_operation_restore(self, operation_id: str):
7+
def restore(self, operation_id: str):
88
query = """
99
mutation DeleteOperationRestore($id: ID!) {
1010
deleteOperationRestore(id: $id)
@@ -16,3 +16,26 @@ def delete_operation_restore(self, operation_id: str):
1616
"id": operation_id,
1717
},
1818
)
19+
20+
def delete(self, **kwargs):
21+
"""Delete a role given its ID
22+
23+
:param id: ID for the role on the platform.
24+
:type id: str
25+
"""
26+
id = kwargs.get("id", None)
27+
if id is None:
28+
self.api.admin_logger.error("[opencti_role] Missing parameter: id")
29+
return None
30+
31+
query = """
32+
mutation DeleteOperationConfirm($id: ID!) {
33+
deleteOperationConfirm(id: $id) {
34+
}
35+
"""
36+
self.api.query(
37+
query,
38+
{
39+
"id": id,
40+
},
41+
)

pycti/api/opencti_api_work.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ def delete_work(self, work_id: str):
128128
)
129129
return work["data"]
130130

131+
def delete(self, **kwargs):
132+
id = kwargs.get("id", None)
133+
query = """
134+
mutation ConnectorWorksMutation($workId: ID!) {
135+
workEdit(id: $workId) {
136+
delete
137+
}
138+
}"""
139+
work = self.api.query(
140+
query,
141+
{"workId": id},
142+
)
143+
return work["data"]
144+
131145
def wait_for_work_to_finish(self, work_id: str):
132146
status = ""
133147
cnt = 0

pycti/api/opencti_api_workspace.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class OpenCTIApiWorkspace:
2+
"""OpenCTIApiWorkspace"""
3+
4+
def __init__(self, api):
5+
self.api = api
6+
7+
def delete(self, **kwargs):
8+
id = kwargs.get("id", None)
9+
query = """
10+
mutation WorkspaceDelete($id: ID!) {
11+
workspaceDelete(id: $id)
12+
}
13+
"""
14+
self.api.query(
15+
query,
16+
{
17+
"id": id,
18+
},
19+
)

pycti/entities/opencti_group.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,16 @@ def create(self, **kwargs) -> Optional[Dict]:
315315
)
316316
return self.opencti.process_multiple_fields(result["data"]["groupAdd"])
317317

318-
def delete(self, id: str):
318+
def delete(self, **kwargs):
319319
"""Delete a given group from OpenCTI
320320
321321
:param id: ID of the group to delete.
322322
:type id: str
323323
"""
324+
id = kwargs.get("id", None)
325+
if id is None:
326+
self.opencti.admin_logger.error("[opencti_user] Missing parameter: id")
327+
return None
324328
self.opencti.admin_logger.info("Deleting group", {"id": id})
325329
query = """
326330
mutation GroupDelete($id: ID!) {

pycti/entities/opencti_stix_core_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1910,4 +1910,4 @@ def remove_from_draft(self, **kwargs):
19101910
self.opencti.query(query, {"id": id})
19111911
else:
19121912
self.opencti.app_logger.error("[stix_core_object] Missing parameters: id")
1913-
return None
1913+
return None

pycti/utils/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class StixCyberObservableTypes(Enum):
4848
PERSONA = "Persona"
4949

5050
@classmethod
51-
def has_value(cls, value):
51+
def has_value(cls, value: str) -> bool:
5252
lower_attr = list(map(lambda x: x.lower(), cls._value2member_map_))
5353
return value.lower() in lower_attr
5454

0 commit comments

Comments
 (0)