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

Commit a228ab2

Browse files
committed
[client] Add toStix options for indicators
1 parent 0adc357 commit a228ab2

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

pycti/api/opencti_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def query(self, query, variables=None):
280280
if is_multiple_files:
281281
# [(var_name + "." + i)] if is_multiple_files else
282282
for _ in file_var_item["file"]:
283-
file_vars[str(map_index)] = [(var_name + "." + str(map_index))]
283+
file_vars[str(map_index)] = [var_name + "." + str(map_index)]
284284
map_index += 1
285285
else:
286286
file_vars[str(map_index)] = [var_name]

pycti/entities/opencti_indicator.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import uuid
55

6+
from requests_toolbelt.multipart.encoder import to_list
67
from stix2.canonicalization.Canonicalize import canonicalize
78

89
from .indicator.opencti_indicator_properties import (
@@ -48,6 +49,7 @@ def list(self, **kwargs):
4849
:param list customAttributes: (optional) list of attributes keys to return
4950
:param bool getAll: (optional) switch to return all entries (be careful to use this without any other filters)
5051
:param bool withPagination: (optional) switch to use pagination
52+
:param bool toStix: (optional) get in STIX
5153
5254
:return: List of Indicators
5355
:rtype: list
@@ -63,21 +65,26 @@ def list(self, **kwargs):
6365
get_all = kwargs.get("getAll", False)
6466
with_pagination = kwargs.get("withPagination", False)
6567
with_files = kwargs.get("withFiles", False)
68+
to_stix = kwargs.get("toStix", False)
6669

6770
self.opencti.app_logger.info(
6871
"Listing Indicators with filters", {"filters": json.dumps(filters)}
6972
)
7073
query = (
7174
"""
72-
query Indicators($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: IndicatorsOrdering, $orderMode: OrderingMode) {
73-
indicators(filters: $filters, search: $search, first: $first, after: $after, orderBy: $orderBy, orderMode: $orderMode) {
75+
query Indicators($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: IndicatorsOrdering, $orderMode: OrderingMode, $toStix: Boolean) {
76+
indicators(filters: $filters, search: $search, first: $first, after: $after, orderBy: $orderBy, orderMode: $orderMode, toStix: $toStix) {
7477
edges {
7578
node {
7679
"""
7780
+ (
78-
custom_attributes
79-
if custom_attributes is not None
80-
else (self.properties_with_files if with_files else self.properties)
81+
"toStix"
82+
if to_stix
83+
else (
84+
custom_attributes
85+
if custom_attributes is not None
86+
else (self.properties_with_files if with_files else self.properties)
87+
)
8188
)
8289
+ """
8390
}
@@ -102,6 +109,7 @@ def list(self, **kwargs):
102109
"after": after,
103110
"orderBy": order_by,
104111
"orderMode": order_mode,
112+
"toStix": to_stix,
105113
},
106114
)
107115
if get_all:

pycti/utils/constants.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""These are the custom STIX properties and observation types used internally by OpenCTI.
2-
3-
"""
1+
"""These are the custom STIX properties and observation types used internally by OpenCTI."""
42

53
from enum import Enum
64

0 commit comments

Comments
 (0)