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

Commit b190117

Browse files
authored
[client] Internal files deletion for background tasks (#11463)
1 parent 3461538 commit b190117

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

pycti/api/opencti_api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pycti import __version__
1212
from pycti.api.opencti_api_connector import OpenCTIApiConnector
1313
from pycti.api.opencti_api_draft import OpenCTIApiDraft
14+
from pycti.api.opencti_api_internal_file import OpenCTIApiInternalFile
1415
from pycti.api.opencti_api_notification import OpenCTIApiNotification
1516
from pycti.api.opencti_api_pir import OpenCTIApiPir
1617
from pycti.api.opencti_api_playbook import OpenCTIApiPlaybook
@@ -182,6 +183,7 @@ def __init__(
182183
self.connector = OpenCTIApiConnector(self)
183184
self.stix2 = OpenCTIStix2(self)
184185
self.pir = OpenCTIApiPir(self)
186+
self.internal_file = OpenCTIApiInternalFile(self)
185187

186188
# Define the entities
187189
self.vocabulary = Vocabulary(self)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class OpenCTIApiInternalFile:
2+
"""OpenCTIApiInternalFile"""
3+
4+
def __init__(self, api):
5+
self.api = api
6+
7+
def delete(self, **kwargs):
8+
item = kwargs.get("item", None)
9+
file_name = self.api.get_attribute_in_extension("id", item)
10+
if file_name is not None:
11+
query = """
12+
mutation InternalFileDelete($fileName: String) {
13+
deleteImport(fileName: $fileName)
14+
}
15+
"""
16+
self.api.query(
17+
query,
18+
{
19+
"fileName": file_name,
20+
},
21+
)
22+
else:
23+
self.api.app_logger.error(
24+
"[stix_internal_file] Cant delete internal file, missing parameters: fileName"
25+
)
26+
return None

pycti/api/opencti_api_playbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def delete(self, **kwargs):
4848
},
4949
)
5050
else:
51-
self.opencti.app_logger.error(
51+
self.api.app_logger.error(
5252
"[stix_playbook] Cant delete playbook, missing parameters: id"
5353
)
5454
return None

pycti/utils/opencti_stix2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ def get_internal_helper(self):
941941
"workspace": self.opencti.workspace,
942942
"publicdashboard": self.opencti.public_dashboard,
943943
"notification": self.opencti.notification,
944+
"internalfile": self.opencti.internal_file,
944945
}
945946

946947
def generate_standard_id_from_stix(self, data):
@@ -2599,7 +2600,7 @@ def element_operation_delete(self, item, operation):
25992600
# Element is not knowledge we need to use the right api
26002601
stix_helper = self.get_internal_helper().get(item["type"])
26012602
if stix_helper and hasattr(stix_helper, "delete"):
2602-
stix_helper.delete(id=item["id"])
2603+
stix_helper.delete(id=item["id"], item=item)
26032604
else:
26042605
raise ValueError(
26052606
"Delete operation or not found stix helper", {"type": item["type"]}

0 commit comments

Comments
 (0)